| This is
a simulation demo we assembled to test out our new FStEng state
engine in ActionScript 2.0, as well as new AS 2.0 components. While
it only took us a few hours to make the traffic light, we ended
up spending the majority of our time on the car behavior and car-to-car
interaction.
*** THIS EXAMPLE REQUIRES THE FLASH
PLAYER 7 ***
It started from Miro Samek's C/C++
Users Journal column on state machines (June 2003), in which
he describes a traffic light accompanied by a pedestrian crossing
mechanism. We implemented that statechart, and then went a little
overboard (okay, a lot overboard) on the traffic.
We decided to implement the traffic light and pedestrian crossing
using our state engine, but implement the car behavior using Samek's
QHsm (AS 2.0) implementation. We started by designing the traffic
light system using our XML-to-Statechart
code tool. Click
here to see the XML for the traffic light system.
The system looked so lonely without traffic to manage, so we decided
to implement basic traffic. It occurred to us that we could describe
the behavior of a car using state machines. Ultimately, one could
describe different kinds of driving styles by inheriting from a
default car behavior (state machine). Because this is a great example
for inheriting behavior, we used Miro Samek's QHsm framework to
describe the cars. Click here
to see the original XML for the car (we subsequently modified it,
particularly adding more events, but it is essentially the same
as what is running in the movie).
For simplicity, when the light turns red, all cars in front of
the traffic light stop where they are.
Extra: If you'd like to see how the traffic light
is working with respect to states, click
here to view the page with the run-time state visualization
tool.
You can allow pedestrians to cross (though
there are none) by pressing the button on either side of the crosswalk.
Use the sliders on the right to change the light timing. If you
select a car with the mouse, you will see a speedometer appear to
show its current speed. If you press "Display Car States",
the cars will show which state they are in (Stopped, Cruising, Accelerating,
or Decelerating). |