* Competition timer. Stop robot when the timer exceeds.
*
*/
-void *wait_for_end(void *arg)
+void *timing_thread(void *arg)
{
- sleep(COMPETITION_TIME);
+ struct timespec start;
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+#define WAIT(sec) \
+ do { \
+ struct timespec t; \
+ t.tv_sec = start.tv_sec+sec; \
+ t.tv_nsec = start.tv_nsec; \
+ clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); \
+ } while(0)
+
+ WAIT(5);
+ robot.use_back_switch = true;
+ printf("Back switch not ignored\n");
+
+ WAIT(TIME_TO_DEPOSITE);
+ FSM_SIGNAL(MAIN, EV_SHORT_TIME_TO_END, NULL);
+
+ WAIT(COMPETITION_TIME);
printf("%d seconds timer exceeded! exiting!\n", COMPETITION_TIME);
robot_exit();
- return NULL;
-}
-/**
- * Timer to go to tray.
- *
- * FIXME: rename this function? (F.J.)
- */
-void *wait_to_deposition(void *arg)
-{
- sleep(TIME_TO_DEPOSITE);
- FSM_SIGNAL(MAIN, EV_SHORT_TIME_TO_END, NULL);
return NULL;
}
case EV_START:
#endif
/* start competition timer */
- pthread_create(&thid, NULL, wait_for_end, NULL);
- pthread_create(&thid, NULL, wait_to_deposition, NULL);
+ pthread_create(&thid, NULL, timing_thread, NULL);
robot_set_est_pos_trans(0.16,
PLAYGROUND_HEIGHT_M - 0.16,
DEG2RAD(-45));
r = (int)(right * mul);
robot.orte.motion_speed.left = l;//(l&0xff) << 8 | (l&0xff00) >> 8;
robot.orte.motion_speed.right = r;//(r&0xff) << 8 | (r&0xff00) >> 8;
+
+ robot.moves_backward = (left < -0.01 || right < -0.01);
// DBG("speed l=%8.3g (%6d) r=%8.3g (%6d)",
// left, l, // robot.orte.motion_speed.left,
// right, r //robot.orte.motion_speed.right
robot.fsm.display.state = &fsm_state_disp_init;
robot.obstacle_avoidance_enabled = true;
+ robot.use_back_switch = false; /* Switched on sime time after start */
robot.state = POWER_ON;
/* init ORTE domain, create publishers, subscribers, .. */
/** True if localization data arrives correctly and therfore
* localization runs */
bool localization_works;
+
+ bool use_back_switch;
+
+ /** True iff at least one wheel rotates backward */
+ bool moves_backward;
+
/*
* sometimes H8S does not send queried odometry
* following flag has been added for EKF estimator,
static bool previous_switch_status;
switch (info->status) {
case NEW_DATA: {
- if (robot.orte.puck_inside.status == 1) {
- //FSM_SIGNAL(ACT, EV_PUCK_INSIDE, NULL);
- FSM_SIGNAL(MOTION, EV_OBSTACLE_BEHIND, NULL);
+ if (robot.use_back_switch) {
+ if (robot.orte.puck_inside.status & 0x01) {
+ //FSM_SIGNAL(ACT, EV_PUCK_INSIDE, NULL);
+
+ /* React on the first switch or when moving backward. */
+ if ((previous_switch_status & 0x01) == 0 ||
+ robot.moves_backward) {
+ FSM_SIGNAL(MOTION, EV_OBSTACLE_BEHIND, NULL);
+ }
+ previous_switch_status = robot.orte.puck_inside.status;
+ }
}
- previous_switch_status = robot.orte.puck_inside.status;
robot.hw_status[STATUS_CHE]=HW_STATUS_OK;
}
break;