Sump Controller#

This example presents the software needed to implement a simplified pump controller that might be used in a mining environment. It is based on a case study from Burns and Wellings, Real-Time Systems and Programming Languages, Addison Wesley, 2001.
The task of the system is to pump water from a sump to the surface. There are two level monitors which start pumping if the sump is full and stop pumping if it is empty again.
Pumping should only start if the methane level is below a certain threshold. If the pump is already running and methane exceeds the threshold, it should stop automatically.
There are some additional requirements:
- After starting the pump, a pressure monitor must signal pressure within a defined time to ensure the pump does not run dry. Otherwise the pump becomes hot and finally breaks.
- When stopped, the run signal (checkback) from the motor must be absent (i.e. the contactor is open).
- When running, the checkback signal must be present.
- After a fault, a manual reset signal is necessary to restart the controller.
The controller behavior can be modeled as a flat state chart. The model below is drawn with the built-in editor and saved as controller.xml. There are two main states, PumpStopped and PumpRunning. Changing from running to stopped is only possible via two intermediate states (PumpStarting, PumpStopping) that check that the pump motor checkback signal is present after a switching command. If the checkback from the motor is missing, the Error state is entered.
In another possible design, all states except the Error state are children of a NoError state.
To open the model in the editor:
java -jar codegen.jar -p ssc -E -o controller controller.xmlTo create the state machine implementation code, call the state machine generator on the model file:
java -jar codegen.jar -p ssc -o controller controller.xmlIn this case, the C implementation is generated.
With the -S command line flag, the graphical simulation starts instead (see below). No code is generated then:
java -jar codegen.jar -S -p ssc -o controller controller.xml The graphical simulation allows you to send events to the machine interactively and observe both the new active state and the executed C code. The diagram below shows the state machine in the PumpRunning state. Events currently accepted by the machine are listed on the left and are shown in blue in the diagram. To trigger a transition, click an event in the list. The output window displays a trace of the executed code provided in the diagram.

It is also possible to observe a real target connected to the graphical simulation. More information on how to connect an embedded target, e.g. via a CAN communication link, is available in the Sinelabore manual. Started with -V instead, the diagram shows the states the target reports over UDP. If you are interested in the model file or generated code, just send a mail to info at sinelabore dot com.