#include "robot.h"
#include <fsm.h>
+struct mcl_particle cal_pos;
void loc_pln_update();
int loc_mcl_update(struct mcl_model *mcl, double dx, double dy, double dangle);
void dbg_print_parts();
{
// DBG_PRINT_EVENT("loc_run event:");
- FSM_TIMEOUT(1000);
+// FSM_TIMEOUT(1000);
switch (FSM_EVENT) {
case EV_LOC_INIT:
/*DBG_PRINT_EVENT("mcl_init event:");*/
FSM_TRANSITION(loc_mcl_init);
break;
- case EV_TIMEOUT:
-// FIXME: dont forget to uncomment the break expression bellow
-// when the laser works.
+// case EV_TIMEOUT:
// DBG_PRINT_EVENT("timeout event:");
// break;
case EV_LOC_LOCATE:
loc_pln_update();
/* update mcl with measured position */
- rv = loc_mcl_update(&robot.mcl, (double)dx, (double)dy, (double)dangle);
-
- /* send update signal if mcl update has finished successful */
- if (!rv)
- FSM_SIGNAL(MOTION, EV_LOC_UPDATED);
- else {
- printf("MCL_RESET: LOST!\n");
- FSM_SIGNAL(MOTION, EV_LOC_LOST);
- }
+// rv = loc_mcl_update(&robot.mcl, (double)dx, (double)dy, (double)dangle);
+
+// /* send update signal if mcl update has finished successful */
+// if (!rv)
+// FSM_SIGNAL(MOTION, EV_LOC_UPDATED);
+// else {
+// printf("MCL_RESET: LOST!\n");
+// FSM_SIGNAL(MOTION, EV_LOC_LOST);
+// }
SUBFSM_RET();
}
struct pln_pos_state _act_pos;
struct pln_pos_state _cal_pos;
unsigned int times[LAS_CNT], cnt;
+ int i;
/* measured times from laser beacon */
ROBOT_LOCK(laser_recv);
times[10] = robot.laser_recv.measures9;
ROBOT_UNLOCK(laser_recv);
-// printf("cnt=%d period=%d measures: ",
-// robot.laser_recv.cnt, robot.laser_recv.period);
-// printf("times:");
-// for (i=0; i<cnt; i++)
-// printf("%d ", times[i]);
-// printf("\n");
+ printf("\n");
+ printf("cnt=%d period=%d measures: ",
+ robot.laser_recv.cnt, robot.laser_recv.period);
+ printf("times:");
+ for (i=1; i<cnt; i++)
+ printf("%d ", times[i]);
+ printf("\n");
/* actual position */
- /*ROBOT_LOCK(act_pos);
- _act_pos.x = robot.act_pos.x;
- _act_pos.y = robot.act_pos.y;
+ ROBOT_LOCK(act_pos);
+ _act_pos.x = robot.act_pos.x * 1000;
+ _act_pos.y = robot.act_pos.y * 1000;
_act_pos.head = robot.act_pos.phi;
- ROBOT_UNLOCK(act_pos);*/
+ ROBOT_UNLOCK(act_pos);
/* FIXME: this stays here just until the odometry will be done */
- _act_pos.x = 500;
- _act_pos.y = 1600;
- _act_pos.head = 0;
+// _act_pos.x = 2000;
+// _act_pos.y = 1950;
+// _act_pos.head = DEG2RAD(0);
// printf("act: x=%f y=%f h=%f\n", _act_pos.x, _act_pos.y, _act_pos.head);
/* calculated measured position */
pln_cal_position(times, cnt, _act_pos, &_cal_pos);
-// printf("calculated posititon: [x=%f,y=%f]\n", _cal_pos.x, _cal_pos.y);
+ printf("calculated posititon: [x=%f,y=%f]\n", _cal_pos.x, _cal_pos.y);
/* set currently calculated position */
+ /* FIXME: remove this when the mcl is used */
ROBOT_LOCK(est_pos);
- robot.est_pos.x = _cal_pos.x;
- robot.est_pos.y = _cal_pos.y;
+ robot.est_pos.x = _cal_pos.x / 1000;
+ robot.est_pos.y = _cal_pos.y / 1000;
robot.est_pos.phi = _cal_pos.head;
ROBOT_UNLOCK(est_pos);
+
+ cal_pos.x = _cal_pos.x;
+ cal_pos.y = _cal_pos.y;
+ cal_pos.angle = _cal_pos.head;
}
/**
int loc_mcl_update(struct mcl_model *mcl, double dx, double dy, double dangle)
{
struct mcl_particle est_pos;
- struct mcl_particle cal_pos;
-
- /* get calculated position by laser */
- ROBOT_LOCK(est_pos);
- cal_pos.x = robot.est_pos.x;
- cal_pos.y = robot.est_pos.y;
- cal_pos.angle = robot.est_pos.phi;
- ROBOT_UNLOCK(est_pos);
mcl->cycle++;
// printf("loc_mcl_update: cycle = %d\n", mcl->cycle);
#include <QPen>
#include "playgroundscene.h"
-robot::robot(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsItem(parent)
+robot::robot(QGraphicsItem *parent, QGraphicsScene *scene, int color) : QGraphicsItem(parent)
{
actPhi = M_PI/2;
this->robotBody = new QGraphicsRectItem(QRectF(OFFSET_X,OFFSET_Y,ROBOT_SIZE_X,ROBOT_SIZE_Y),parent,scene);
this->robotBody->setPen(QPen(QBrush(Qt::black),1,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
- this->robotBody->setBrush(QBrush(Qt::black));
+ switch (color) {
+ case 0:
+ this->robotBody->setBrush(QBrush(Qt::black));
+ break;
+ case 1:
+ this->robotBody->setBrush(QBrush(Qt::green));
+ break;
+ case 2:
+ this->robotBody->setBrush(QBrush(Qt::yellow));
+ break;
+ case 3:
+ this->robotBody->setBrush(QBrush(Qt::gray));
+ break;
+ default:
+ this->robotBody->setBrush(QBrush(Qt::black));
+ break;
+ }
this->robotBody->setParentItem(this);
this->robotBody->setZValue(10);
;