3 * @brief FSM for uOLED display
10 #include <robot_eb2008.h>
19 * A thread for serial line communication.
21 * This thread is waititng for a character to be intercepted
22 * on the serial line, then the character is evaluated
23 * and appropriate EVENT is issued to inform the automaton.
29 struct sercom_data *sercom;
41 void serial_comm(int status)
47 nr = read(sercom->fd, buff, 10);
49 if(buff[0]==MSG_START) {
56 printf("received serial msg: \n");
58 printf("%02x ",buff[i]);
63 int set_actuators(uint8_t actuator)
67 if(robot.orte.servos.brush_left==BRUSH_LEFT_OPEN) {
75 if(robot.orte.servos.brush_right==BRUSH_RIGHT_OPEN) {
83 if(robot.orte.servos.door_bottom==BOTTOM_DOOR_OPEN) {
91 if(robot.orte.servos.door_back==BACK_DOOR_OPEN) {
99 if(robot.orte.drives.brush_left==LEFT_BRUSH_DRIVE_ON) {
107 if(robot.orte.drives.brush_right==RIGHT_BRUSH_DRIVE_ON) {
115 if(robot.orte.drives.bagr==BAGR_DRIVE_ON) {
128 int set_game_color(uint8_t col)
133 int move_carousel(uint8_t dir)
135 uint8_t act_car_pos, new_car_pos;
137 act_car_pos = robot.orte.drives.carousel_pos;
138 ROBOT_UNLOCK(drives);
144 new_car_pos = --act_car_pos;
150 new_car_pos = ++act_car_pos;
153 new_car_pos = act_car_pos;
157 robot.orte.drives.carousel_pos = new_car_pos;
158 ROBOT_UNLOCK(drives);
162 int process_msg(uint8_t *buff) {
164 case SWITCH_TO_STATUS:
165 uoled_switch_mode_rep(MODE_STATUS, CHANGE_MODE_STATUS);
169 case SWITCH_TO_CONTROL:
170 uoled_switch_mode_rep(MODE_STATUS, CHANGE_MODE_CONTROL);
174 case SWITCH_TO_STATUS_DONE:
176 mode_to_go = MODE_STATUS;
179 case SWITCH_TO_CONTROL_DONE:
181 mode_to_go = MODE_CONTROL;
185 set_actuators(buff[2]);
188 set_game_color(buff[2]); //TODO
194 move_carousel(RIGHT);
197 //TODO robot get ready function
200 //TODO robot start function
209 FSM_STATE_DECL(init);
210 FSM_STATE_DECL(control);
211 FSM_STATE_DECL(status);
212 FSM_STATE_DECL(status_send_voltage);
213 FSM_STATE_DECL(status_send_state);
214 FSM_STATE_DECL(status_send_balls);
215 FSM_STATE_DECL(status_send_hw);
216 FSM_STATE_DECL(status_send_position);
217 FSM_STATE_DECL(set_init_mode);
218 FSM_STATE_DECL(wait_for_mode_switch);
223 if (FSM_EVENT == EV_ENTRY) {
225 sercom = robot.sercom;
226 FSM_TRANSITION(set_init_mode);
230 FSM_STATE(set_init_mode)
234 uoled_switch_mode_rep(MODE_STATUS, CHANGE_MODE_STATUS);
238 FSM_TRANSITION(status);
252 uoled_set_color(robot.team_color);
256 uoled_send_voltage(&robot.gorte.pwr_voltage);
257 uoled_send_state(robot.act_fsm_state_name, strlen(robot.act_fsm_state_name));
258 uoled_set_balls((uint8_t*)&robot.carousel);
259 uoled_send_position(&robot.gorte.est_pos);
260 uoled_send_hw_status(robot.hw_status);
263 memcpy(buff, msg, 10);
266 ret = process_msg(buff);
269 FSM_TRANSITION(wait_for_mode_switch);
277 //FSM_TRANSITION(status_send_voltage);
285 FSM_STATE(status_send_voltage)
292 uoled_send_voltage(&robot.gorte.pwr_voltage);
298 memcpy(buff, msg, 10);
301 ret = process_msg(buff);
304 FSM_TRANSITION(wait_for_mode_switch);
312 FSM_TRANSITION(status_send_state);
319 FSM_STATE(status_send_state)
326 uoled_send_state(fsm->state_name, strlen(fsm->state_name));
332 memcpy(buff, msg, 10);
335 ret = process_msg(buff);
338 FSM_TRANSITION(wait_for_mode_switch);
346 FSM_TRANSITION(status_send_balls);
354 FSM_STATE(status_send_balls)
361 uoled_set_balls((uint8_t*)&robot.carousel);
367 memcpy(buff, msg, 10);
370 ret = process_msg(buff);
373 FSM_TRANSITION(wait_for_mode_switch);
381 FSM_TRANSITION(status_send_hw);
389 FSM_STATE(status_send_hw)
396 //TODO: send HW status here
402 memcpy(buff, msg, 10);
405 ret = process_msg(buff);
408 FSM_TRANSITION(wait_for_mode_switch);
416 FSM_TRANSITION(status_send_position);
424 FSM_STATE(status_send_position)
431 uoled_send_position(&robot.gorte.est_pos);
437 memcpy(buff, msg, 10);
440 ret = process_msg(buff);
443 FSM_TRANSITION(wait_for_mode_switch);
451 FSM_TRANSITION(status);
469 memcpy(buff, msg, 10);
472 switch(process_msg(buff)) {
474 FSM_TRANSITION(wait_for_mode_switch);
490 FSM_STATE(wait_for_mode_switch)
501 memcpy(buff, msg, 10);
511 if(mode_to_go==MODE_STATUS)
512 FSM_TRANSITION(status);
513 else if(mode_to_go==MODE_CONTROL)
514 FSM_TRANSITION(control);