SinelaboreRT Header Logo

SinelaboreRT

As simple as possible, but not any simpler!

User Tools

Site Tools


wiki:examples:light_controller

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wiki:examples:light_controller [2012/10/20 17:37] – created pmuellerwiki:examples:light_controller [2019/12/09 20:00] (current) pmueller
Line 5: Line 5:
  
 The following figure shows a simplified state machine of such a device. The following figure shows a simplified state machine of such a device.
 +
 +{{ :wiki:examples:simplified_light_controller.png?nolink |}}
 +
 +==== Functional Requirements ====
 +
 +The device has three modes which can be changed using a simple switch. It has the positions ''OFF'', ''Auto'' and ''ON''. The switch is realized in a way that the user can only go from ''OFF'' to ''AUTO'' to ''ON'' and vice versa.
 +
 +In ''ON'' mode the light is permanently switched on. In ''OFF'' mode the light is permanently switched off. In ''Auto'' the light is automatically switched on and off as described in the next section.
 +
 +When its becoming dark and the auto mode is active the device automatically switches on the light if a person is detected. If the person walks away the light is switched off again. The light is on for at least a configurable time (e.g. 60s). If the person is still nearby after that time the light is kept on as long as no person can be detected anymore.
 +
 +The light should not be switched on during daylight. Therefore the device permanently measures the ambient brightness. Only if the measured value is below an adjustable threshold the device switches on the light automatically.
 +
 +==== State Machine Design ====
 +
 +The three modes of the device can be easily transferred into states. The auto state is a hierarchical state which realizes the night/day behavior when a person was detected. The design was created using the  SinelaboreRT state machine editor. The diagram is shown in the figure above.
 +
 +The {{:wiki:examples:automatic_light.zip|automatic light controller}} zip files contains the fully worked out example with a simple text based command interface. Start the executable and type in one of the supported letters to trigger the machine.
 +
 +Available commands:
 +
 +
 +  * ''+'' There is a person
 +  * ''-'' There is no person
 +  * ''t'' Ambient brightness low (twilight, night)
 +  * ''d'' Ambient brightness high (dawn, day)
 +  * ''a'' Auto mode
 +  * ''o'' Permanent on
 +  * ''x'' Permanent off
 +  * ''q'' Quit the program
 +
 +The files ''gui.c/h'' realizes the keyboard handling. In the file  light_trace.c a simple trace function was realized to trace the event flow. Main.c calls the state machine and checks the keyboard for new events. All other files are automatically generated from the state machine as shown above.
 +
 +To test the machine type in e.g.:   ''       +  ... (repeat 20 times) +  -''
 +
 +
 +==== Graphical Trace ====
 +
 +The sinelaboreRT codegen tool is able to display state diagrams based on an automatic layout engine. In simulation mode trace data can be received via a UDP connection. The received evens are then used to trigger the same state changes as in the compiled C program. This makes it possible to follow the state changes of the light.exe program while we stimulate it with the keyboard events.
 +
 +The prepared example already sends the trace data via UDP (see light_trace.c).  To display the state machine start the editor in simulation mode as follows:
 +
 +<code bash>
 +$ java -jar codegen.jar -p ssc -S -o automatic_light.xml automatic_light.xml
 +</code>
 +
 +This command line brings up a window showing the state machine((Make sure graphviz is installed on your system and the correct path to the dot.exe (layout engine) is defined in the codegen.cfg file. Otherwise you will get an error message when starting the codegen in simulation mode.)). Start the light executable again and type in commands. You can now follow the current state of the state machine and the C-code executed as reaction to your keyboard input.
 +
 +The ZIP file contains an executable that was built with Cygwin on Windows (light.exe) and for OS X (light_osx). To change the state machine or to generate the code yourself download the demo version of the Sinelabore code generator.
 +
 +Have fun!
 +
 +
 +~~DISCUSSION|Leave your comments~~
 +
 +
 +{{tag>[Application_Example]}}
  
  
wiki/examples/light_controller.1350747453.txt.gz · Last modified: 2012/10/20 17:37 by pmueller

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki