7 * @brief Robot's main control program
14 * Robot's main control program (Eurobot 2010).
16 * Copyright: (c) 2009-2010 CTU Dragons
17 * CTU FEE - Department of Control Engineering
18 * License: GNU GPL v.2
25 // FIXME: remove unused includes:
32 #include <movehelper.h>
40 #include <actuators.h>
43 #define WAIT_FOR_START
44 #define COMPETITION_TIME_DEFAULT 90
45 #define TIME_TO_DEPOSITE_DEFAULT 60
48 #define COMPETITION_TIME_DEFAULT 900
49 #define TIME_TO_DEPOSITE_DEFAULT 60
52 /* competition time in seconds */
53 #define COMPETITION_TIME COMPETITION_TIME_DEFAULT
54 #define TIME_TO_DEPOSITE TIME_TO_DEPOSITE_DEFAULT
55 /* competition time in seconds */
57 /************************************************************************
58 * SUBFSM's return values ...
59 ************************************************************************/
66 #define FSM_EVENT_RET_VAL ((subfsm_ret_val)FSM_EVENT_INT)
68 /************************************************************************
69 * Trajectory constraints used, are initialized in the init state
70 ************************************************************************/
72 struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
74 /************************************************************************
76 ************************************************************************/
78 /** is set to true in separate thread when there is short time left */
79 bool short_time_to_end;
81 /************************************************************************
82 * Definition of particular movement sequences (FIXME)
83 ************************************************************************/
85 /** *********************************************************************
86 * Competition timer. Stop robot when the timer exceeds.
87 ********************************************************************** */
88 void *timing_thread(void *arg)
90 struct timespec start;
92 sem_wait(&robot.start);
94 clock_gettime(CLOCK_MONOTONIC, &start);
98 t.tv_sec = start.tv_sec+sec; \
99 t.tv_nsec = start.tv_nsec; \
100 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); \
104 // // microswitch (backside opponent detector), ignore it while at starting point
105 // robot.use_back_switch = true;
106 // printf("Back switch not ignored\n");
108 WAIT(TIME_TO_DEPOSITE);
109 short_time_to_end = true;
111 WAIT(COMPETITION_TIME);
112 printf("%d seconds timer exceeded! exiting!\n", COMPETITION_TIME);
118 /************************************************************************
119 * FSM STATES DECLARATION
120 ************************************************************************/
122 /* initial and starting states */
123 FSM_STATE_DECL(init);
124 FSM_STATE_DECL(wait_for_start);
125 /* strategies related states */
126 FSM_STATE_DECL(decide_what_next);
127 /* movement states */
129 /************************************************************************
130 * INITIAL AND STARTING STATES
131 ************************************************************************/
137 short_time_to_end = false;
139 tcFast = trajectoryConstraintsDefault;
140 tcSlow = trajectoryConstraintsDefault;
144 tcSlow.maxangacc = 1;
145 tcVerySlow = trajectoryConstraintsDefault;
146 tcVerySlow.maxv = 0.1;
147 tcVerySlow.maxacc = 0.05;
148 tcVerySlow.maxomega = 0.7;
149 tcVerySlow.maxangacc = 1;
150 FSM_TRANSITION(wait_for_start);
157 void set_initial_position()
159 robot_set_est_pos_trans(0.16,
160 PLAYGROUND_HEIGHT_M - 0.16,
164 FSM_STATE(wait_for_start)
168 printf("COMPETITION mode set\n");
172 pthread_create(&thid, NULL, timing_thread, NULL);
173 #ifdef WAIT_FOR_START
179 /* start competition timer */
180 sem_post(&robot.start);
182 set_initial_position();
183 FSM_TRANSITION(decide_what_next);
186 // We set initial position periodically in
187 // order for it to be updated on the display
188 // if the team color is changed during waiting
190 set_initial_position();
193 case EV_GOAL_NOT_REACHABLE: // currently not used
195 case EV_ACTION_ERROR:
197 DBG_PRINT_EVENT("unhandled event");
204 /************************************************************************
205 * STRATEGIES RELATED STATES
206 ************************************************************************/
208 FSM_STATE(decide_what_next)
212 if(short_time_to_end) {
220 case EV_GOAL_NOT_REACHABLE: // currently not used
221 case EV_ACTION_ERROR:
223 DBG_PRINT_EVENT("unhandled event");
236 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
238 robot.fsm.main.debug_states = 1;
239 robot.fsm.motion.debug_states = 1;
240 robot.fsm.act.debug_states = 1;
242 robot.fsm.main.state = &fsm_state_main_init;
245 if (rv) error(1, errno, "robot_start() returned %d\n", rv);