Smart Trains 1

ST 4 Taking a Ride on Hierarki Fully Driven by Statecharts

Let’s take a ride on this G-scale hobby train named Hierarki shuttling between the Upper Garden and Lower Garden stations. It is battery-powered and controlled by an onboard STM32L4S5 discovery board. Apart from the motor blocks, wheel bearings, electrical components and the standard couplers, most other parts are 3D-printed with custom design, including the non-driving wheels which work surprisingly well!

Now for the software-minded, consider this user story: The model train shall automatically shuttle between stations A and B. Once arrived at a station, it shall wait for 10-15s before departing in the opposite direction. Its headlights and taillights shall be lit in white and red respectively according to the direction of travel.

Surely the story sounds pretty straight-forward and we might be tempted to architect its embedded software in an equally straight-forward manner, with step-by-step sequential logic (if-else, loops, sleep(), etc.) that could be well described by a flowchart.

While this could get us quickly started, however, as more requirements are added down the track (which always happens, and some of which would be for out of the ordinary cases), this kind of sequential or synchronous design model could rapidly get out of hand. We will explore the opposite design philosophy of asynchronous model in the next post.