]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robofsm/test/camera_onoff.cc
Events
[eurobot/public.git] / src / robofsm / test / camera_onoff.cc
1 /*
2  * line.cc                      07/08/01
3  *
4  * Movement test: move on a line.
5  *
6  * Copyright: (c) 2007 CTU Dragons
7  *            CTU FEE - Department of Control Engineering
8  * License: GNU GPL v.2
9  */
10
11 #include <robot.h>
12 #include <movehelper.h>
13 #include <trgen.h>
14 #include <robomath.h>
15 #include <string.h>
16 #include <error.h>
17 #include <actuators.h>
18 #include <boost/statechart/asynchronous_state_machine.hpp>
19 #include <boost/statechart/transition.hpp>
20 #include "../timedFSM.h"
21 #include <events.h>
22
23 struct on;
24 struct off;
25
26 struct FSMMain : boost::statechart::asynchronous_state_machine< FSMMain, on, Scheduler > {
27         FSMMain(my_context ctx) : my_base(ctx) {
28                 printf("%s\n", __FUNCTION__);
29         }
30 };
31
32 struct on : TimedState< on, FSMMain > {
33         Timer onTime;
34         on(my_context ctx) : base_state(ctx) {
35                 act.camera_on();
36                 runTimer(onTime, 10000, new evTimer());
37         }
38         typedef sc::transition< evTimer, off > reactions;
39 };
40
41
42 struct off : TimedState< off, FSMMain > {
43         Timer offTime;
44         off(my_context ctx) : base_state(ctx) {
45                 act.camera_off();
46                 runTimer(offTime, 10000, new evTimer());
47         }
48         typedef sc::transition< evTimer, on > reactions;
49 };
50
51 int main(int argc, char *argv[])
52 {
53         int rv;
54         robot.MAIN = robot.sched.create_processor<FSMMain>();
55         rv = robot.init();
56         if (rv) error(1, errno, "robot_init() returned %d\n", rv);
57
58         rv = robot.start();
59         if (rv) error(1, errno, "robot_start() returned %d\n", rv);
60
61         robot.destroy();
62
63         return 0;
64 }