}
// FIXME: This is duplicite code with new_goal. Remove this
// function and use always new_goal.
- if (robot.localization_works) {
- ROBOT_LOCK(est_pos_uzv);
- pos.x = robot.est_pos_uzv.x;
- pos.y = robot.est_pos_uzv.y;
- pos.phi = robot.est_pos_uzv.phi;
- ROBOT_UNLOCK(est_pos_uzv);
- } else if (robot.odometry_works) {
- ROBOT_LOCK(est_pos_odo);
- pos.x = robot.est_pos_odo.x;
- pos.y = robot.est_pos_odo.y;
- pos.phi = robot.est_pos_odo.phi;
- ROBOT_UNLOCK(est_pos_odo);
- } else {
- ROBOT_LOCK(ref_pos);
- pos.x = robot.ref_pos.x;
- pos.y = robot.ref_pos.y;
- pos.phi = robot.ref_pos.phi;
- ROBOT_UNLOCK(ref_pos);
- }
+ robot_get_est_pos(&pos.x, &pos.y, &pos.phi);
pos.v = 0;
pos.omega = 0;
switch (FSM_EVENT) {
case EV_ENTRY:
if (robot.localization_works) {
- // TODO lock
- robot_set_est_pos_notrans(robot.est_pos_uzv.x,
- robot.est_pos_uzv.y,
- robot.est_pos_uzv.phi);
+ robot_pos_type p;
+ ROBOT_LOCK(est_pos_uzv);
+ p = robot.est_pos_uzv;
+ ROBOT_UNLOCK(est_pos_uzv);
+
+ robot_set_est_pos_notrans(p.x, p.y, p.phi);
}
break;
case EV_TRAJECTORY_DONE:
* #OBS_CSPACE. */
/* Mark "protected" area around the obstacle */
- ROBOT_LOCK(est_pos_uzv);
- est_pos = robot.est_pos_uzv;
- ROBOT_UNLOCK(est_pos_uzv);
+ robot_get_est_pos(&est_pos.x, &est_pos.y, &est_pos.phi);
+
int obst_size_cell = (int)ceil(OBS_SIZE_M/MAP_CELL_SIZE_M);
for (i=(xcell-obst_size_cell); i <= xcell+obst_size_cell; i++) {
for (j=(ycell- obst_size_cell); j <=ycell + obst_size_cell; j++) {
struct sharp_pos beam;
u_int16_t *data;
- ROBOT_LOCK(est_pos_uzv);
- e = robot.est_pos_uzv;
- ROBOT_UNLOCK(est_pos_uzv);
-
+ robot_get_est_pos(&e.x, &e.y, &e.phi);
+
beam.x = HOKUYO_CENTER_OFFSET_M;
beam.y = 0;
robot.ref_pos.phi = ref_pos.phi;
ROBOT_UNLOCK(ref_pos);
- if (robot.odometry_works) {
- ROBOT_LOCK(est_pos_odo);
- est_pos.x = robot.est_pos_odo.x;
- est_pos.y = robot.est_pos_odo.y;
- est_pos.phi = robot.est_pos_odo.phi;
- ROBOT_UNLOCK(est_pos_odo);
- } else {
- est_pos = ref_pos;
- }
+ robot_get_est_pos(&est_pos.x, &est_pos.y, &est_pos.phi);
#ifdef MOTION_PRINT_REF
static double last_t;
// Robot doesn't move, so return current position
pthread_mutex_unlock(&actual_trajectory_lock);
- if (robot.localization_works) {
- ROBOT_LOCK(est_pos_uzv);
- pos.x = robot.est_pos_uzv.x;
- pos.y = robot.est_pos_uzv.y;
- pos.phi = robot.est_pos_uzv.phi;
- ROBOT_UNLOCK(est_pos_uzv);
- } else if (robot.odometry_works) {
- ROBOT_LOCK(est_pos_odo);
- pos.x = robot.est_pos_odo.x;
- pos.y = robot.est_pos_odo.y;
- pos.phi = robot.est_pos_odo.phi;
- ROBOT_UNLOCK(est_pos_odo);
- } else {
- ROBOT_LOCK(ref_pos);
- pos.x = robot.ref_pos.x;
- pos.y = robot.ref_pos.y;
- pos.phi = robot.ref_pos.phi;
- ROBOT_UNLOCK(ref_pos);
- }
+ robot_get_est_pos(&pos.x, &pos.y, &pos.phi);
pos.v = 0;
pos.omega = 0;
}
void robot_move_by(double distance, struct move_target_heading heading, struct TrajectoryConstraints *tc)
{
double x, y, phi;
-
- ROBOT_LOCK(est_pos_uzv);
- x = robot.est_pos_uzv.x;
- y = robot.est_pos_uzv.y ;
- phi = robot.est_pos_uzv.phi;
- ROBOT_UNLOCK(est_pos_uzv);
+
+ robot_get_est_pos(&x, &y, &phi);
x += distance*cos(phi);
y += distance*sin(phi);
ShmapFree();
DBG("robofsm: stop.\n");
}
+
+void robot_get_est_pos(double *x, double *y, double *phi)
+{
+ if (robot.localization_works) {
+ ROBOT_LOCK(est_pos_uzv);
+ *x = robot.est_pos_uzv.x;
+ *y = robot.est_pos_uzv.y;
+ *phi = robot.est_pos_uzv.phi;
+ ROBOT_UNLOCK(est_pos_uzv);
+ } else if (robot.odometry_works) {
+ ROBOT_LOCK(est_pos_odo);
+ *x = robot.est_pos_odo.x;
+ *y = robot.est_pos_odo.y;
+ *phi = robot.est_pos_odo.phi;
+ ROBOT_UNLOCK(est_pos_odo);
+ } else {
+ ROBOT_LOCK(ref_pos);
+ *x = robot.ref_pos.x;
+ *y = robot.ref_pos.y;
+ *phi = robot.ref_pos.phi;
+ ROBOT_UNLOCK(ref_pos);
+ }
+}
void robot_exit();
void robot_destroy();
+void robot_get_est_pos(double *x, double *y, double *phi);
+
/* Hack to easily disable display if it is not configured */
void serial_comm(int status);
ROBOT_UNLOCK(lift_cmd);
}
-
#endif /* ROBOT_H */