177 #include <libplayercore/playercore.h> 182 #define LASER_MAX_SAMPLES 1024 189 mbicp( ConfigFile* cf,
int section);
242 void ProcessOdom(player_msghdr_t* hdr, player_position2d_data_t &data);
248 void ProcessCommand(player_msghdr_t* hdr, player_position2d_cmd_pos_t &);
268 return((Driver*)(
new mbicp(cf, section)));
292 puts(
"Setup Scanmatching");
335 : Driver(cf, section,
true, PLAYER_MSGQUEUE_DEFAULT_MAXLEN,
336 PLAYER_POSITION2D_CODE){
339 this->
max_laser_range = cf->ReadFloat(section,
"max_laser_range", 7.9);
340 this->
Bw = cf->ReadFloat(section,
"angular_window", 1.57/3.0);
341 this->
Br = cf->ReadFloat(section,
"radial_window", 0.3);
342 this->
L = cf->ReadFloat(section,
"L", 3.00);
343 this->
laserStep = cf->ReadInt(section,
"laserStep", 1);
344 this->
MaxDistInter = cf->ReadFloat(section,
"MaxDistInter", 0.5);
345 this->
filter = cf->ReadFloat(section,
"filter", 0.85);
347 this->
AsocError = cf->ReadFloat(section,
"AsocError", 0.1);
348 this->
MaxIter = cf->ReadInt(section,
"MaxIter", 50);
349 this->
errorRatio = cf->ReadFloat(section,
"errorRatio", 0.0001);
350 this->
errx_out = cf->ReadFloat(section,
"errx_out", 0.0001);
351 this->
erry_out = cf->ReadFloat(section,
"erry_out", 0.0001);
352 this->
errt_out = cf->ReadFloat(section,
"errt_out", 0.0001);
354 this->
laserPoseTsc.
x = cf->ReadFloat(section,
"laserPose_x", 0.16);
355 this->
laserPoseTsc.
y = cf->ReadFloat(section,
"laserPose_y", 0);
360 PLAYER_POSITION2D_CODE, -1, NULL) != 0){
366 if(cf->ReadDeviceAddr(&
odom_addr, section,
"requires",
367 PLAYER_POSITION2D_CODE, -1, NULL) != 0){
373 if(cf->ReadDeviceAddr(&
laser_addr, section,
"requires",
374 PLAYER_LASER_CODE, -1, NULL) != 0){
392 PLAYER_ERROR(
"Unable to locate suitable position device");
395 if(
odom->Subscribe(InQueue) != 0){
396 PLAYER_ERROR(
"Unable to subscribe to position device");
401 PLAYER_ERROR(
"Unable to locate suitable laser device");
404 if(
laser->Subscribe(InQueue) != 0){
405 PLAYER_ERROR(
"Unable to subscribe to laser device");
415 player_position2d_cmd_vel_t cmd;
417 memset(&cmd, 0,
sizeof(cmd));
424 odom->PutMsg(InQueue, PLAYER_MSGTYPE_CMD, PLAYER_POSITION2D_CMD_VEL,
425 (
void*)&cmd,
sizeof(cmd),NULL);
427 odom->Unsubscribe(InQueue);
428 laser->Unsubscribe(InQueue);
429 puts(
"Shutdown mbicp");
441 pthread_testcancel();
453 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_DATA,PLAYER_LASER_DATA_SCANPOSE,
laser_addr))
455 assert(hdr->size ==
sizeof(player_laser_data_scanpose_t));
460 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_DATA,PLAYER_POSITION2D_DATA_STATE,
odom_addr))
462 assert(hdr->size ==
sizeof(player_position2d_data_t));
463 ProcessOdom(hdr, *reinterpret_cast<player_position2d_data_t *> (data));
466 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_DATA,PLAYER_POSITION2D_DATA_GEOM,
odom_addr))
468 assert(hdr->size ==
sizeof(player_position2d_data_t));
469 player_msghdr_t newhdr = *hdr;
470 newhdr.addr = device_addr;
471 Publish(&newhdr, (
void*)&data);
474 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD, -1, device_addr))
476 assert(hdr->size ==
sizeof(player_position2d_cmd_vel_t));
478 player_msghdr_t newhdr = *hdr;
480 odom->PutMsg(InQueue, &newhdr, (
void*)data);
483 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, -1, device_addr)){
488 if(!(msg =
odom->Request(InQueue, hdr->type, hdr->subtype, (
void*)data,hdr->size, &hdr->timestamp)))
490 PLAYER_WARN1(
"failed to forward config request with subtype: %d\n",hdr->subtype);
493 player_msghdr_t* rephdr = msg->GetHeader();
494 void* repdata = msg->GetPayload();
496 rephdr->addr = device_addr;
497 Publish(resp_queue, rephdr, repdata);
530 composicion_sis(&scanmatchingPoseTsc, &outComposicion1, &outComposicion2);
533 data.pos.px = outComposicion2.
x;
534 data.pos.py = outComposicion2.
y;
535 data.pos.pa = outComposicion2.
tita;
540 player_msghdr_t newhdr = *hdr;
541 newhdr.addr = device_addr;
542 Publish(&newhdr, (
void*)&data);
560 currentScan.intensity_count = data.scan.intensity_count;
563 for (
unsigned int i=0; i <
currentScan.ranges_count; i++){
621 salidaMbicp =
MbICPmatcher(previousScanTpfp,currentScanTpfp,&outComposicion3, &solutionTsc);
623 if (salidaMbicp == 1){
628 composicion_sis(&scanmatchingPoseTsc, &outComposicion10, &outComposicion11);
630 scanmatchingPoseTsc.
x = outComposicion11.
x;
631 scanmatchingPoseTsc.
y = outComposicion11.
y;
632 scanmatchingPoseTsc.
tita = outComposicion11.
tita;
637 if (salidaMbicp == 2)
638 fprintf(stderr,
"2 : Everything OK but reached the Maximum number of iterations\n");
640 if (salidaMbicp == -1)
641 fprintf(stderr,
"Failure in the association step\n");
642 if (salidaMbicp == -2)
643 fprintf(stderr,
"Failure in the minimization step\n");
648 composicion_sis(&scanmatchingPoseTsc, &outComposicion10, &outComposicion11);
650 scanmatchingPoseTsc.
x = outComposicion11.
x;
651 scanmatchingPoseTsc.
y = outComposicion11.
y;
652 scanmatchingPoseTsc.
tita = outComposicion11.
tita;
667 posicionTsc.
x = posicion.px;
668 posicionTsc.
y = posicion.py;
669 posicionTsc.
tita = posicion.pa;
677 player_pose2d_t posicionPlayer;
679 posicionPlayer.px = posicion.
x;
680 posicionPlayer.py = posicion.
y;
681 posicionPlayer.pa = posicion.
tita;
682 return(posicionPlayer);
689 for(
unsigned int i=0; i< laserData.ranges_count; i++){
690 laserDataTpfp[i].
r = laserData.ranges[i];
691 laserDataTpfp[i].
t = laserData.min_angle + (i*laserData.resolution);
player_laser_data_t previousScan
int MbICPmatcher(Tpfp *laserK, Tpfp *laserK1, Tsc *sensorMotion, Tsc *solution)
void ProcessCommand(player_msghdr_t *hdr, player_position2d_cmd_pos_t &)
player_pose2d_t Tsc2playerPose(Tsc posicion)
player_pose2d_t currentPose
player_devaddr_t odom_addr
player_devaddr_t laser_addr
void Init_MbICP_ScanMatching(float max_laser_range, float Bw, float Br, float L, int laserStep, float MaxDistInter, float filter, int ProjectionFilter, float AsocError, int MaxIter, float error_ratio, float error_x, float error_y, float error_t, int IterSmoothConv)
void ProcessOdom(player_msghdr_t *hdr, player_position2d_data_t &data)
player_pose2d_t previousPose
player_pose2d_t scanmatchingPose
player_laser_data_t currentScan
#define LASER_MAX_SAMPLES
void ProcessSubtypeLaser(player_msghdr_t *hdr, player_laser_data_scanpose_t &data)
player_devaddr_t posicion_addr
void mbicp_Register(DriverTable *table)
player_pose2d_t lastPoseOdom
void playerLaser2Tpfp(player_laser_data_t laserData, Tpfp *laserDataTpfp)
void composicion_sis(Tsc *sis1, Tsc *sis2, Tsc *sisOut)
Tsc playerPose2Tsc(player_pose2d_t posicion)
Driver * mbicp_Init(ConfigFile *cf, int section)
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
mbicp(ConfigFile *cf, int section)
void inversion_sis(Tsc *sisIn, Tsc *sisOut)