wiki:examples:light_controller
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
wiki:examples:light_controller [2012/10/20 17:37] – created pmueller | wiki: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. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ==== Functional Requirements ==== | ||
+ | |||
+ | The device has three modes which can be changed using a simple switch. It has the positions '' | ||
+ | |||
+ | In '' | ||
+ | |||
+ | 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 {{: | ||
+ | |||
+ | Available commands: | ||
+ | |||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | The files '' | ||
+ | |||
+ | To test the machine type in e.g.: '' | ||
+ | |||
+ | |||
+ | ==== 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). | ||
+ | |||
+ | <code bash> | ||
+ | $ java -jar codegen.jar -p ssc -S -o automatic_light.xml automatic_light.xml | ||
+ | </ | ||
+ | |||
+ | 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> | ||
wiki/examples/light_controller.1350747453.txt.gz · Last modified: 2012/10/20 17:37 by pmueller