Tuesday, December 7, 2010

Differential steering challenge problem

I posed a challenge problem in today's guest lecture in the Embedded Systems Programming course.  The challenge is to efficiently control a simple differential steering robot.  The Acumen code below presents both the model of the robot (dsbot), a target object, and a very simple controller.  How well the controller performs is measured in the Main object by the total energy (e) at the end of the simulation.  My score was 161.3.  You are welcome to submit to me the code of an controller that performs better.

The only rule is that you can only send me the code for the controller.  In other words, the code for the robot, target, and the main program has to remain the same.

class dsbot () // Differential steering robot
  private x=0; x'=0; y=0; y'=0;
          a=0; a'=0 ; v=0
  x' [=] v * cos(a);
  y' [=] v * sin(a);

class target () // A simple target moving in a circle
  private t=0; t'=0; x=0; y=0 end
  t' [=] 1;
  x = 2*sin(t/1.5);
  y = 2*cos(t/1.5);

class controller () // A simple controller
  private t =0; t'=0; // local time
  ex = 0; ey = 0; // Error in x and y
  ia = 0; // Input angle
  ov = 0; oap = 0; // Ouput v and a'
  t' [=] 1;
  if t>0.1
  t = 0;
  // Control code goes here
  if (ex*ex + ey*ey) < 1 // Robot is close enough. Slow down 
    ov = 1   
    ov = 4; 
    if   (   (ex>0 && cos(ia)<0) 
          || (ey>0 && sin(ia)<0)) 
       || (  (ex<0 && cos(ia)>0) 
           ||(ey<0 && sin(ia)>0))
      oap = -10
      oap = 0

class Main(simulator)
  private r = create dsbot ();
          t = create target ();
          c = create controller ();
          d = 0; e = 0; e'= 0; // Measures of success
  // Controller see robot
    c.ex [=] t.x - r.x;
    c.ey [=] t.y - r.y;
    c.ia [=] r.a;
  // Robot listens to controller
    r.a' [=] c.oap;
    r.v [=] c.ov;
  // Error over time
    d [=] sqrt(c.ex*c.ex+c.ey*c.ey);
    e' [=] r.v*r.v + 2*d*d

Tuesday, October 26, 2010

Bouncing ball example in your favorite language

This is a request for audience participation!

The code below is a minimalist model defining the behavior of a ball subject to gravity, air resistance, and idealized bouncing.  I'd like to use this example to collect in one place code written in different hybrid modeling languages.  It would be great if you can send me (or add as comment) equivalent code written in your favorite hybrid modeling language, or for that matter any hybrid modeling language that you are familiar with.  As much as possible, please follow the same style and avoid making stylistic changes to the extent possible.  Please free to provide multiple versions if necessary, and to offer explanation of your stylistic choices as needed.

If you happen to know Verilog-AMS, PSPICE, Modelica, Sol, MapleSim, or Impromptu, I would really appreciate if you can express this model in those languages as well.  All other languages are very welcome as well!

Here's the code:

// Minimalist model for ball with airodynamic
//  resistance (2010/10/26, Scottsdale)

class Main (simulator)
  a = create BouncingBall()

class BouncingBall ()
  g = -9.8; cr = 0.95; cd = 0.075;
  x = 10; x' = 2; x'' = 0;

 if x>=0
  if x'<0
   x'' [=] g + cd * (x')^2
   x'' [=] g - cd * (x')^2
  x' = - cr * x';
  x  = 0


From Andre Platzer:

Here's the bouncing ball as a hybrid program:

(if (x=0) then v := -r*v fi;

Here's the bouncing ball as a differential-algebraic program:

(if (x=0) then 
v := -r*v fi;
       |(v'=g-d*v^2&v>=0)), x>=0})*

Monday, September 20, 2010

Globally Parallel, Locally Sequential. Or, “Preserving Natural Parallelism”

We have just finished a draft of a short paper describing some preliminary results on the automatically parallelizing version of Acumen.  The paper itself can be found here:

Please stay tuned for a release of the parallelizing version of Acumen that was used in these experiments!

Tuesday, August 24, 2010

Sneak preview of Acumen 10

Acumen 10 features improvements to the syntax, semantics, expressivity, and user interface.  The picture below is a snapshot using an example illustrating two different models of a bouncing ball.

Here's the code example in plain text:

class BouncingSpringBall1 (x,x',x'')
  x'' [=] - 9.8 + (1/x^2)

class BouncingSpringBall2 (x,x',x'')
  x'' [=] - 9.8;
  if (x < 0) 
    x = -x; x' = -x'

class Main (mode, simulation)
  private state = "Init" end
  switch state
   case "Init"
     create BouncingSpringBall1 (2, 0, 0);
     create BouncingSpringBall2 (2, 0, 0);
     state = "Persist"
   case "Persist"

New features in Acumen 10 include class declarations, dynamic object creation & deletion and an explicit imperative programming language for describing what happens during discrete mode changes.

Wednesday, August 4, 2010

Acumen 3D Trailer

Breaking news!

A preview of what Acumen 3D will look like can be seen in the videos put together by Paul Brauner and is available on YouTube.

Monday, May 31, 2010

What New Acumen Animations Should Look Like :)

A google search for bouncing balls returned this interesting visualization of an audio, which has some nice ideas that we will try to use (at least for basic demos).

Scratch also has a bouncing ball demo.

And there is a video from some town with a bouncing ball invasion, probably somewhere in California.  :)

Tuesday, January 5, 2010

Draft paper

We've just finished a draft of a new paper describing the source language of Acumen and how it is compiled.  The PDF can be downloaded from the links on the right of the page.  Here's the abstract:
"Cyber-physical systems comprise digital components that directly interact with a physical environment.  Specifying the behavior desired of such systems requires analytical modeling of physical phenomena.  Similarly, testing them requires simulation of continuous systems.  While numerous tools support later stages of developing simulation codes, there is still a large gap between analytical modeling and building running simulators.  This gap significantly impedes the ability of scientists and engineers to develop novel cyber-physical systems.
We propose bridging this gap by automating the mapping from analytical models to simulation codes.  Focusing on mechanical systems as an important class of models of physical systems, we study the form of analytical models that arise in this domain, along with the process by which domain experts map them to executable codes.  We show that the key steps needed to automate this mapping are 1) a light-weight analysis to partially direct equations, 2) a binding-time analysis, and 3) an efficient implementation of symbolic differentiation.  As such, our work pinpoints and highlights a number of limitations in the state of the art in tool support of simulation, and shows how some of
these limitations can be overcome."