#include "robot_config.h"
#include <robomath.h>
#include <ul_log.h>
+#include "guard.hpp"
+#include "events.h"
UL_LOG_CUST(ulogd_motion_control); /* Log domain name = ulogd + name of the file */
old = actual_trajectory;
actual_trajectory = NULL;
pthread_mutex_unlock(&actual_trajectory_lock);
- robot_send_speed(0,0);
+ robot.move_helper.send_speed(0,0);
if (old) delete(old);
}
if (error > MAX_POS_ERROR_M) {
if (!lost_sent) {
lost_sent = true;
- FSM_SIGNAL(MOTION, EV_TRAJECTORY_LOST, NULL);
+ robot.sched.queue_event(robot.MOTION, new evTrajectoryLost());
}
} else {
lost_sent = false;
if (done) {
- if (error < CLOSE_TO_TARGET_M) {
- FSM_SIGNAL(MOTION, EV_TRAJECTORY_DONE_AND_CLOSE, NULL);
- } else if (!done_sent) {
+ if (error < CLOSE_TO_TARGET_M || !done_sent) {
+ robot.sched.queue_event(robot.MOTION, new evTrajectoryDone());
done_sent = true;
- FSM_SIGNAL(MOTION, EV_TRAJECTORY_DONE, NULL);
}
} else {
done_sent = false;
continue;
if (map->cells[ycell][xcell].detected_obstacle > 0) {
if (sem_trywait(&recalculation_not_running) == 0) {
- FSM_SIGNAL(MOTION, EV_OBSTACLE, NULL);
+ robot.sched.queue_event(robot.MOTION, new evObstacle());
break;
}
}
if (ref_pos.omega > actual_trajectory->constr.maxomega)
DBG("Omega constraint problem %lf, max %lf -------------------- \n", ref_pos.omega, actual_trajectory->constr.maxomega);
- ROBOT_LOCK(ref_pos);
- robot.ref_pos.x = ref_pos.x;
- robot.ref_pos.y = ref_pos.y;
- robot.ref_pos.phi = ref_pos.phi;
- ROBOT_UNLOCK(ref_pos);
+ {
+ Guard g(robot.lock_ref_pos);
+ robot.ref_pos.x = ref_pos.x;
+ robot.ref_pos.y = ref_pos.y;
+ robot.ref_pos.phi = ref_pos.phi;
+ }
- robot_get_est_pos(&est_pos.x, &est_pos.y, &est_pos.phi);
+ robot.get_est_pos(est_pos.x, est_pos.y, est_pos.phi);
#ifdef MOTION_PRINT_REF
static double last_t;
// Apply controller output
- robot_send_speed(speedl, speedr);
+ robot.move_helper.send_speed(speedl, speedr);
pthread_mutex_unlock(&actual_trajectory_lock);
}
// Robot doesn't move, so return current position
pthread_mutex_unlock(&actual_trajectory_lock);
- robot_get_est_pos(&pos.x, &pos.y, &pos.phi);
+ robot.get_est_pos(pos.x, pos.y, pos.phi);
pos.v = 0;
pos.omega = 0;
}