break;
case EV_TIMER:
/* button1 - turn off all drives */
- if (robot.gorte.joy_data.button1 == 1) {
+ if (robot.joy_data.button1 == 1) {
if(buttons_prev[0]!=1) {
buttons[0] = ~buttons[0];
buttons_prev[0] = 1;
buttons_prev[0] = 0;
/* button2 - open/close brush left/right */
- if (robot.gorte.joy_data.button2 == 1) {
+ if (robot.joy_data.button2 == 1) {
if(buttons_prev[1]!=1) {
buttons[1] = ~buttons[1];
buttons_prev[1] = 1;
buttons_prev[1] = 0;
/* button3 - open close back door */
- if (robot.gorte.joy_data.button3 == 1) {
+ if (robot.joy_data.button3 == 1) {
if(buttons_prev[2]!=1) {
buttons[2] = ~buttons[2];
buttons_prev[2] = 1;
buttons_prev[2] = 0;
/* button4 - */
- if (robot.gorte.joy_data.button4 == 1) {
+ if (robot.joy_data.button4 == 1) {
if(buttons_prev[3]!=1) {
buttons[3] = ~buttons[3];
buttons_prev[3] = 1;
buttons_prev[3] = 0;
/* button5 - */
- if (robot.gorte.joy_data.button5 == 1) {
+ if (robot.joy_data.button5 == 1) {
if(buttons_prev[4]!=1) {
buttons[4] = ~buttons[4];
buttons_prev[4] = 1;
buttons_prev[4] = 0;
/* button6 - turn brush drives off */
- if (robot.gorte.joy_data.button6 == 1) {
+ if (robot.joy_data.button6 == 1) {
if(buttons_prev[5]!=1) {
buttons[5] = ~buttons[5];
buttons_prev[5] = 1;
buttons_prev[5] = 0;
/* button7 */
- if (robot.gorte.joy_data.button7 == 1) {
+ if (robot.joy_data.button7 == 1) {
if(buttons_prev[6]!=1) {
buttons[6] = ~buttons[6];
buttons_prev[6] = 1;
buttons_prev[6] = 0;
/* button8 */
- if (robot.gorte.joy_data.button8 == 1) {
+ if (robot.joy_data.button8 == 1) {
if(buttons_prev[7]!=1) {
buttons[7] = ~buttons[7];
buttons_prev[7] = 1;
buttons_prev[7] = 0;
/* button9 */
- if (robot.gorte.joy_data.button9 == 1) {
+ if (robot.joy_data.button9 == 1) {
if(buttons_prev[8]!=1) {
buttons[8] = ~buttons[8];
buttons_prev[8] = 1;
buttons_prev[8] = 0;
/* button10 */
- if (robot.gorte.joy_data.button10 == 1) {
+ if (robot.joy_data.button10 == 1) {
if(buttons_prev[9]!=1) {
buttons[9] = ~buttons[9];
buttons_prev[9] = 1;
buttons_prev[9] = 0;
/* button11 */
- if (robot.gorte.joy_data.button11 == 1) {
+ if (robot.joy_data.button11 == 1) {
if(buttons_prev[10]!=1) {
buttons[10] = ~buttons[10];
buttons_prev[10] = 1;
buttons_prev[10] = 0;
/* button12 */
- if (robot.gorte.joy_data.button12 == 1) {
+ if (robot.joy_data.button12 == 1) {
if(buttons_prev[11]!=1) {
buttons[11] = ~buttons[11];
buttons_prev[11] = 1;
buttons_prev[11] = 0;
/* axis - carousel left/right */
- if (robot.gorte.joy_data.axisS1 == -32767) {
+ if (robot.joy_data.axisS1 == -32767) {
if(axis_prev[3] != 1) {
axis[3] = ~axis[3];
axis_prev[3] = 1;
} else
axis_prev[3] = 0;
- if (robot.gorte.joy_data.axisS1 == 32767) {
+ if (robot.joy_data.axisS1 == 32767) {
if(axis_prev[4] != 1) {
axis[4] = ~axis[4];
axis_prev[4] = 1;
axis_prev[4] = 0;
/* axis - brush in/out */
- if (robot.gorte.joy_data.axisS2 == -32767) {
+ if (robot.joy_data.axisS2 == -32767) {
brushes_in();
}
- if (robot.gorte.joy_data.axisS2 == 32767) {
+ if (robot.joy_data.axisS2 == 32767) {
brushes_out();
}
- if (prev_axisR != robot.gorte.joy_data.axisR) {
- set_bagr(150 + (-robot.gorte.joy_data.axisR * 50 / 32767));
- prev_axisR = robot.gorte.joy_data.axisR;
+ if (prev_axisR != robot.joy_data.axisR) {
+ set_bagr(150 + (-robot.joy_data.axisR * 50 / 32767));
+ prev_axisR = robot.joy_data.axisR;
}
*/
FSM_STATE(loc_update)
{
- static unsigned int times[LAS_CNT];
- static int cnt;
static struct mcl_particle est_pos;
- int i;
DBG_PRINT_EVENT("loc_update:");
- ROBOT_LOCK(laser_meas);
- cnt = robot.orte.laser_meas.cnt + 1;
- times[0] = robot.orte.laser_meas.period;
- times[1] = robot.orte.laser_meas.measures0;
- times[2] = robot.orte.laser_meas.measures1;
- times[3] = robot.orte.laser_meas.measures2;
- times[4] = robot.orte.laser_meas.measures3;
- times[5] = robot.orte.laser_meas.measures4;
- times[6] = robot.orte.laser_meas.measures5;
- times[7] = robot.orte.laser_meas.measures6;
- times[8] = robot.orte.laser_meas.measures7;
- times[9] = robot.orte.laser_meas.measures8;
- times[10] = robot.orte.laser_meas.measures9;
- ROBOT_UNLOCK(laser_meas);
-
- meas_angles.count = cnt;
- for (i=0; i<cnt; i++) {
- meas_angles.val[i] = (double)TIME2ANGLE(times[0],times[i+1]);
- }
-
mcl.update(&mcl, mcl.data);
mcl.normalize(&mcl);
mcl.sort(&mcl);
est_pos = mcl_get_pos(&mcl);
ROBOT_LOCK(est_pos);
- robot.gorte.est_pos.x = est_pos.x;
- robot.gorte.est_pos.y = est_pos.y;
- robot.gorte.est_pos.phi = est_pos.angle;
+ robot.est_pos.x = est_pos.x;
+ robot.est_pos.y = est_pos.y;
+ robot.est_pos.phi = est_pos.angle;
ROBOT_UNLOCK(est_pos);
FSM_SIGNAL(MOTION, EV_LOC_UPDATED, NULL);
// static void odometry(double l, r) {
// static double last_l, last_r;
-// robot.act_pos->x = (double)ROBOT_AXIS_TO_BACK_MM/1000;
-// robot.act_pos->y = ((double)PLAYGROUND_HEIGHT_MM - ROBOT_WIDTH_MM/2)/1000;
-// robot.act_pos->phi = 0;
+// robot.act_pos.x = (double)ROBOT_AXIS_TO_BACK_MM/1000;
+// robot.act_pos.y = ((double)PLAYGROUND_HEIGHT_MM - ROBOT_WIDTH_MM/2)/1000;
+// robot.act_pos.phi = 0;
// ROBOT_LOCK(act_pos);
// ROBOT_UNLOCK(act_pos);
robot_set_act_pos_notrans(ref_pos.x, ref_pos.y, ref_pos.phi);
#endif
ROBOT_LOCK(act_pos);
- ap = *robot.act_pos;
+ ap = robot.act_pos;
ROBOT_UNLOCK(act_pos);
double aktPos[] = { ap.x, ap.y, ap.phi };
* #OBS_CSPACE. */
ROBOT_LOCK(act_pos);
- act_pos = *robot.act_pos;
+ act_pos = robot.act_pos;
ROBOT_UNLOCK(act_pos);
for (i=(xcell-OBS_AREA); i <= xcell+OBS_AREA; i++) {
/** Updates Map. */
//ShmapUpdateTmpObstacles(OBS_UPDATE_MAP_SPEED);
/* FIXME: here should be data from opponent sharp sensors */
- ROBOT_LOCK(sharpsOpponent);
+ ROBOT_LOCK(sharp_opponent);
val[0] = 2.0;
val[1] = 2.0;
val[2] = 2.0;
- ROBOT_UNLOCK(sharpsOpponent);
+ ROBOT_UNLOCK(sharp_opponent);
const float ang[NUM_SHARPS] = {DEG2RAD(22), DEG2RAD(0), DEG2RAD(-22)};
for (i=0; i<NUM_SHARPS; i++) {
if(val[i] < OBS_OFFSET) {
/** Get actual position. */
ROBOT_LOCK(act_pos);
- p = *robot.act_pos;
+ p = robot.act_pos;
ROBOT_UNLOCK(act_pos);
/**
* The obstacle cell its calulated as (val*cos(p.phi)) + p.x) and ((val*sin(p.phi)) + p.y)
/// Get actual position.
ROBOT_LOCK(act_pos);
- startx = robot.act_pos->x;
- starty = robot.act_pos->y;
+ startx = robot.act_pos.x;
+ starty = robot.act_pos.y;
start.x = startx;
start.y = starty;
- start.phi = robot.act_pos->phi;
+ start.phi = robot.act_pos.phi;
tc = robot.goal_trajectory_constraints;
ROBOT_UNLOCK(act_pos);
/// Get goal position.
ROBOT_LOCK(act_pos);
- pos.x = robot.act_pos->x;
- pos.y = robot.act_pos->y;
- pos.phi = robot.act_pos->phi;
+ pos.x = robot.act_pos.x;
+ pos.y = robot.act_pos.y;
+ pos.phi = robot.act_pos.phi;
ROBOT_UNLOCK(act_pos);
if (t->prepare(pos)) {
if (y<0) y=0;
if (y>PLAYGROUND_HEIGHT_M) y=PLAYGROUND_HEIGHT_M;
ROBOT_LOCK(act_pos);
- robot.act_pos->x = x;
- robot.act_pos->y = y;
- robot.act_pos->phi = phi;
+ robot.act_pos.x = x;
+ robot.act_pos.y = y;
+ robot.act_pos.phi = phi;
ROBOT_UNLOCK(act_pos);
}
pthread_mutex_init(&robot.lock, NULL);
pthread_mutex_init(&robot.lock_act_pos, NULL);
+ pthread_mutex_init(&robot.lock_mcl, NULL);
+ pthread_mutex_init(&robot.lock_meas_angles, NULL);
+ pthread_mutex_init(&robot.lock_joy_data, NULL);
/* FSM initialization */
for (i=0; i<FSM_CNT; i++)
/* init ORTE domain, create publishers, subscribers, .. */
robot_init_orte();
- /* just for easier manipulation with this variables */
- robot.act_pos = &robot.gorte.act_pos;
- robot.est_pos = &robot.gorte.est_pos;
-
return 0;
}
/**
#define __robot_lock_act_pos lock_act_pos
#define __robot_lock_est_pos lock
#define __robot_lock_des_pos lock
-#define __robot_lock_mcl lock_mcl
#define __robot_lock_goal lock
-#define __robot_lock_IRsensors lock
-#define __robot_lock_joy_data lock
-#define __robot_lock_laser_meas lock
+#define __robot_lock_mcl lock_mcl
+#define __robot_lock_joy_data lock_joy_data
+#define __robot_lock_meas_angles lock_meas_angles
#define __robot_lock_new_trajectory lock
-#define __robot_lock_sharpsOpponent lock
-#define __robot_lock_sharpsWaste lock
-#define __robot_lock_waste_cnt lock
+#define __robot_lock_sharp_opponent lock
/* robot's main data structure */
struct robot_eb2008 {
pthread_mutex_t lock;
pthread_mutex_t lock_act_pos;
pthread_mutex_t lock_mcl;
+ pthread_mutex_t lock_meas_angles;
+ pthread_mutex_t lock_joy_data;
/* competition parameters */
unsigned char team_color;
struct robo_fsm fsm[FSM_CNT];
/* actual position */
- struct act_pos_type *act_pos;
+ struct act_pos_type act_pos;
/* estimated position */
- struct est_pos_type *est_pos;
+ struct est_pos_type est_pos;
/* goal position */
struct act_pos_type goal;
/* move */
struct act_pos_type move_dpos;
+ struct motion_irc_type odometry;
+ struct joy_data_type joy_data;
+
/* orte */
struct eb2008_orte_data orte;
struct generic_orte_data gorte;
- struct motion_irc_type odometry;
-
/* mcl */
struct mcl_model mcl;
struct mcl_angles meas_angles;;
* PUBLISHER CALLBACKS - GENERIC
* ---------------------------------------------------------------------- */
+void send_act_pos_cb(const ORTESendInfo *info, void *vinstance,
+ void *sendCallBackParam)
+{
+ struct act_pos_type *instance = (struct act_pos_type *)vinstance;
+
+ ROBOT_LOCK(act_pos);
+ *instance = robot.act_pos;
+ ROBOT_UNLOCK(act_pos);
+}
+
+void send_est_pos_cb(const ORTESendInfo *info, void *vinstance,
+ void *sendCallBackParam)
+{
+ struct est_pos_type *instance = (struct est_pos_type *)vinstance;
+
+ ROBOT_LOCK(est_pos);
+ *instance = robot.est_pos;
+ ROBOT_UNLOCK(est_pos);
+}
+
void send_dummy_cb(const ORTESendInfo *info, void *vinstance,
void *sendCallBackParam)
{
deltAlfa = (aktk1 - aktk0) / (2.0*ROBOT_ROTATION_RADIUS_MM/1000);
ROBOT_LOCK(act_pos);
- aktUhel = robot.act_pos->phi;
+ aktUhel = robot.act_pos.phi;
ROBOT_UNLOCK(act_pos);
/* aktualni uhel */
printf("dx=%f dy=%f dphi=%f\n", dx, dy, deltAlfa);*/
ROBOT_LOCK(act_pos);
- x = robot.act_pos->x + dx;
- y = robot.act_pos->y + dy;
- phi = robot.act_pos->phi = aktUhel;
+ x = robot.act_pos.x + dx;
+ y = robot.act_pos.y + dy;
+ phi = robot.act_pos.phi = aktUhel;
ROBOT_UNLOCK(act_pos);
robot_set_act_pos_notrans(x, y, phi);
switch (info->status) {
case NEW_DATA:
- instance = &(robot.gorte.act_pos);
+ ROBOT_LOCK(act_pos);
+ robot.act_pos = *instance;
+ ROBOT_UNLOCK(act_pos);
break;
case DEADLINE:
printf("ORTE deadline occurred - act_pos receive\n");
switch (info->status) {
case NEW_DATA:
ROBOT_LOCK(est_pos);
- instance = &(robot.gorte.est_pos);
+ robot.est_pos = *instance;
ROBOT_UNLOCK(est_pos);
break;
case DEADLINE:
void rcv_joy_data_cb(const ORTERecvInfo *info, void *vinstance,
void *recvCallBackParam)
{
- struct joy_data_type *joy =
- (struct joy_data_type *)vinstance;
-
+ struct joy_data_type *instance = (struct joy_data_type *)vinstance;
+
switch (info->status) {
case NEW_DATA:
ROBOT_LOCK(joy_data);
- robot.gorte.joy_data = *joy;
+ robot.joy_data = *instance;
ROBOT_UNLOCK(joy_data);
break;
case DEADLINE:
void rcv_laser_meas_cb(const ORTERecvInfo *info, void *vinstance,
void *recvCallBackParam)
{
+ struct laser_meas_type *instance = (struct laser_meas_type *)vinstance;
static unsigned int times[LAS_CNT];
static struct mcl_particle est_pos;
static int i;
switch (info->status) {
case NEW_DATA:
- ROBOT_LOCK(laser_meas);
- robot.meas_angles.count = robot.orte.laser_meas.cnt + 1;
- times[0] = robot.orte.laser_meas.period;
- times[1] = robot.orte.laser_meas.measures0;
- times[2] = robot.orte.laser_meas.measures1;
- times[3] = robot.orte.laser_meas.measures2;
- times[4] = robot.orte.laser_meas.measures3;
- times[5] = robot.orte.laser_meas.measures4;
- times[6] = robot.orte.laser_meas.measures5;
- times[7] = robot.orte.laser_meas.measures6;
- times[8] = robot.orte.laser_meas.measures7;
- times[9] = robot.orte.laser_meas.measures8;
- times[10] = robot.orte.laser_meas.measures9;
- ROBOT_UNLOCK(laser_meas);
-
+ times[0] = instance->period;
+ times[1] = instance->measures0;
+ times[2] = instance->measures1;
+ times[3] = instance->measures2;
+ times[4] = instance->measures3;
+ times[5] = instance->measures4;
+ times[6] = instance->measures5;
+ times[7] = instance->measures6;
+ times[8] = instance->measures7;
+ times[9] = instance->measures8;
+ times[10] = instance->measures9;
+
+ ROBOT_LOCK(meas_angles);
+ robot.meas_angles.count = instance->cnt + 1;
for (i=0; i<robot.meas_angles.count; i++)
robot.meas_angles.val[i] =
(double)TIME2ANGLE(times[0],times[i+1]);
+ ROBOT_UNLOCK(meas_angles);
ROBOT_LOCK(mcl);
robot.mcl.update(&robot.mcl, robot.mcl.data);
est_pos = mcl_get_pos(&robot.mcl);
ROBOT_LOCK(est_pos);
- robot.gorte.est_pos.x = est_pos.x;
- robot.gorte.est_pos.y = est_pos.y;
- robot.gorte.est_pos.phi = est_pos.angle;
+ robot.est_pos.x = est_pos.x;
+ robot.est_pos.y = est_pos.y;
+ robot.est_pos.phi = est_pos.angle;
ROBOT_UNLOCK(est_pos);
break;
generic_publisher_motion_irc_create(&robot.gorte, NULL, &robot.gorte);
generic_publisher_motion_speed_create(&robot.gorte, NULL, &robot.gorte);
generic_publisher_motion_status_create(&robot.gorte, NULL, &robot.gorte);
- generic_publisher_act_pos_create(&robot.gorte, send_dummy_cb, &robot.gorte);
- generic_publisher_est_pos_create(&robot.gorte, send_dummy_cb, &robot.gorte);
+ generic_publisher_act_pos_create(&robot.gorte, send_act_pos_cb, &robot.gorte);
+ generic_publisher_est_pos_create(&robot.gorte, send_est_pos_cb, &robot.gorte);
generic_publisher_joy_data_create(&robot.gorte, NULL, &robot.gorte);
generic_publisher_pwr_voltage_create(&robot.gorte, NULL, &robot.gorte);
generic_publisher_pwr_ctrl_create(&robot.gorte, NULL, &robot.gorte);
#include <sys/shm.h>
#include <sys/stat.h>
#include <math.h>
+#include <robomath.h>
#include <map.h>
{
ShmapInit(1);
/* Where we are at the begining? */
- ROBOT_LOCK(act_pos);
- robot.act_pos->x = 0.5;
- robot.act_pos->y = 0.5;
- robot.act_pos->phi = 0;
- ROBOT_UNLOCK(act_pos);
+ robot_set_act_pos_trans(0.5, 0.5, DEG2RAD(0));
FSM_TRANSITION(robot_goto_test);
}
FSM_STATE(main_init) {
/* Where we are at the begining? */
- robot.act_pos->x = 1;
- robot.act_pos->y = 0.5;
- robot.act_pos->phi = 0;
+ robot_set_act_pos_trans(1, 0.5, DEG2RAD(0));
FSM_TRANSITION(line);
}