#include <can_msg_def.h>
#include <actuators.h>
#include <ul_log.h>
+#include "guard.hpp"
+#include "events.h"
UL_LOG_CUST(ulogd_robot_orte); /* Log domain name = ulogd + name of the file */
{
struct robot_pos_type *instance = (struct robot_pos_type *)vinstance;
- ROBOT_LOCK(ref_pos);
+ Guard g(robot.lock_ref_pos);
*instance = robot.ref_pos;
- ROBOT_UNLOCK(ref_pos);
}
void send_est_pos_odo_cb(const ORTESendInfo *info, void *vinstance,
{
struct robot_pos_type *instance = (struct robot_pos_type *)vinstance;
- ROBOT_LOCK(est_pos_odo);
+ Guard g(robot.lock_est_pos_odo);
*instance = robot.est_pos_odo;
- ROBOT_UNLOCK(est_pos_odo);
}
void send_est_pos_indep_odo_cb(const ORTESendInfo *info, void *vinstance,
{
struct robot_pos_type *instance = (struct robot_pos_type *)vinstance;
- ROBOT_LOCK(est_pos_indep_odo);
+ Guard g(robot.lock_est_pos_indep_odo);
*instance = robot.est_pos_indep_odo;
- ROBOT_UNLOCK(est_pos_indep_odo);
}
static void send_est_pos_best_cb(const ORTESendInfo *info, void *vinstance,
{
struct robot_pos_type *instance = (struct robot_pos_type *)vinstance;
- robot_get_est_pos(&instance->x, &instance->y, &instance->phi);
+ robot.get_est_pos(instance->x, instance->y, instance->phi);
}
static void send_system_status_cb(const ORTESendInfo *info, void *vinstance,
switch (info->status) {
case NEW_DATA:
if (first_run) {
- ROBOT_LOCK(odo_data);
- robot.odo_data = *instance;
- ROBOT_UNLOCK(odo_data);
+ {
+ Guard g(robot.lock);
+ robot.odo_data = *instance;
+ }
first_run = false;
break;
}
dtang = (dleft + dright) / 2.0;
dphi = (dright - dleft) / (2.0*ODOMETRY_ROTATION_RADIUS_M);
-
- ROBOT_LOCK(est_pos_indep_odo);
- double a = robot.est_pos_indep_odo.phi;
- robot.est_pos_indep_odo.x += dtang*cos(a);
- robot.est_pos_indep_odo.y += dtang*sin(a);
- robot.est_pos_indep_odo.phi += dphi;
- ROBOT_UNLOCK(est_pos_indep_odo);
-
- ROBOT_LOCK(odo_data);
- robot.odo_data = *instance;
- ROBOT_UNLOCK(odo_data);
+ {
+ Guard g(robot.lock_est_pos_indep_odo);
+ double a = robot.est_pos_indep_odo.phi;
+ robot.est_pos_indep_odo.x += dtang*cos(a);
+ robot.est_pos_indep_odo.y += dtang*sin(a);
+ robot.est_pos_indep_odo.phi += dphi;
+ }
+ {
+ Guard g(robot.lock);
+ robot.odo_data = *instance;
+ }
robot.indep_odometry_works = true;
switch (info->status) {
case NEW_DATA:
if (first_run) {
- ROBOT_LOCK(motion_irc);
- robot.motion_irc = *instance;
- ROBOT_UNLOCK(motion_irc);
+ {
+ Guard g(robot.lock);
+ robot.motion_irc = *instance;
+ }
first_run = false;
break;
}
dtang = (dleft + dright) / 2.0;
dphi = (dright - dleft) / (2.0*ROBOT_ROTATION_RADIUS_M);
-
- ROBOT_LOCK(est_pos_odo);
- double a = robot.est_pos_odo.phi;
- robot.est_pos_odo.x += dtang*cos(a);
- robot.est_pos_odo.y += dtang*sin(a);
- robot.est_pos_odo.phi += dphi;
- ROBOT_UNLOCK(est_pos_odo);
+
+ {
+ Guard g(robot.lock_est_pos_odo);
+ double a = robot.est_pos_odo.phi;
+ robot.est_pos_odo.x += dtang*cos(a);
+ robot.est_pos_odo.y += dtang*sin(a);
+ robot.est_pos_odo.phi += dphi;
+ }
/* locking should not be needed, but... */
- ROBOT_LOCK(motion_irc);
- robot.motion_irc = *instance;
- robot.motion_irc_received = 1;
- ROBOT_UNLOCK(motion_irc);
+ {
+ Guard g(robot.lock);
+ robot.motion_irc = *instance;
+ robot.motion_irc_received = 1;
+ }
robot.odometry_works = true;
robot.status[COMPONENT_START] = STATUS_OK;
/* Competition starts when plugged out, check component status before start */
if ((instance->start_condition == COMPETITION_STARTED) && !check_prestart_status()) {
- FSM_SIGNAL(MAIN, EV_START, NULL);
+ robot.sched.queue_event(robot.MAIN, new evStart());
robot.start_state = COMPETITION_STARTED;
ul_logmsg("STARTED\n");
}
static int num = 0;
if (instance->start_condition == START_PLUGGED_IN) {
if (++num == 10)
- robot_exit();
+ robot.robot_exit();
}
break;
}
switch (info->status) {
case NEW_DATA: {
- ROBOT_LOCK(hokuyo);
- robot.hokuyo = *instance;
- robot.status[COMPONENT_HOKUYO] = STATUS_OK;
- ROBOT_UNLOCK(hokuyo);
+ {
+ Guard g(robot.lock);
+ robot.hokuyo = *instance;
+ robot.status[COMPONENT_HOKUYO] = STATUS_OK;
+ }
if(!robot.ignore_hokuyo)
{
update_map_hokuyo(instance);
switch (info->status) {
case NEW_DATA: {
if (instance->error) {
- robot.status[COMPONENT_CAMERA] = STATUS_FAILED;
+ robot.status[COMPONENT_CAMERA] = STATUS_FAILED;
} else if (instance->data_valid && instance->data_valid != last_response) {
- ROBOT_LOCK(camera_result);
- robot.target_valid = instance->target_valid;
- ROBOT_UNLOCK(camera_result);
- FSM_SIGNAL(MAIN, EV_CAMERA_DONE, NULL);
- printf("robot_orte: valid: %d\n", instance->target_valid);
+ {
+ Guard g(robot.lock_camera);
+ robot.target_valid = instance->target_valid;
+ }
+ robot.sched.queue_event(robot.MAIN, new evCameraDone());
+ printf("robot_orte: valid: %d\n", instance->target_valid);
- robot.status[COMPONENT_CAMERA] = STATUS_OK;
+ robot.status[COMPONENT_CAMERA] = STATUS_OK;
}
last_response = instance->data_valid;
break;
if (instance->response != last_response &&
instance->response == act_crane_get_last_reqest())
- FSM_SIGNAL(MAIN, EV_CRANE_DONE, NULL);
+ robot.sched.queue_event(robot.MAIN, new evCraneDone);
last_response = instance->response;
break;
case DEADLINE:
switch (info->status) {
case NEW_DATA:
if ((!last_strategy && instance->strategy) && (robot.start_state == POWER_ON)) {
- FSM_SIGNAL(MAIN, EV_SWITCH_STRATEGY, NULL);
+ robot.sched.queue_event(robot.MAIN, new evSwitchStrategy());
}
last_strategy = instance->strategy;
break;
switch (info->status) {
case NEW_DATA:
if (!instance->bumper_rear) {
- FSM_SIGNAL(MOTION, EV_OBSTACLE_BEHIND, NULL);
+ robot.sched.queue_event(robot.MOTION, new evObstacleBehind());
}
if ((!instance->bumper_left) ||
(!instance->bumper_right)) {
- FSM_SIGNAL(MOTION, EV_OBSTACLE_SIDE, NULL);
+ robot.sched.queue_event(robot.MOTION, new evObstacleSide());
}
break;
case DEADLINE: