Smart Trains 2

ST 15 Seeing Statecharts Run

Software development is fun when the system works exactly as designed, including both nominal and off-nominal paths. It would be less so if something didn’t work and we had to reconstruct a mental picture of how it was supposed to behave from loads of interlocking variables and if-else.

The previous post illustrates the fun part with the design of a two-stage stopping operation. This video shows its realization with the actual hardware on a deck railing.

The first run exercised the nominal path when the train was in the AutoMotorCoasting state as the second magnet was detected (ARRIVED event). The train gently slowed down giving a sense of realism.

The second run exercised the off-nominal path when the two magnets were too close together, and the train was still in AutoMotorSlowing as the second one was detected. The train braked sharply just in time to avoid running off the end.

With this reliable auto-shuttling feature, we don’t need a lot of space to have fun with model trains!