localization3d_alg_node.cpp
Go to the documentation of this file.
00001 #include "localization3d_alg_node.h"
00002 
00003 Localization3dAlgNode::Localization3dAlgNode(void)
00004 {
00005         //sleep(1);//time to allow tf to be ready
00006                 
00007         //init class attributes if necessary
00008         infoGain = 0;
00009 
00010         // [init publishers]
00011         this->tf_publisher_ = this->public_node_handle_.advertise<tf::tfMessage>("odom_to_map", 100);
00012         this->particleSet_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PoseArray>("particleSet", 100);
00013         this->position_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PoseWithCovarianceStamped>("position", 100);
00014         
00015         // [init subscribers]
00016         this->platformData_subscriber_ = this->public_node_handle_.subscribe("platform_data", 100, &Localization3dAlgNode::platformData_callback, this);
00017         this->platformOdometry_subscriber_ = this->public_node_handle_.subscribe("platform_odom", 100, &Localization3dAlgNode::platformOdometry_callback, this);
00018         this->laser0_subscriber_ = this->public_node_handle_.subscribe("laser0/scan", 100, &Localization3dAlgNode::laser0_callback, this);
00019         this->laser1_subscriber_ = this->public_node_handle_.subscribe("laser1/scan", 100, &Localization3dAlgNode::laser1_callback, this);
00020         this->laser2_subscriber_ = this->public_node_handle_.subscribe("laser2/scan", 100, &Localization3dAlgNode::laser2_callback, this);
00021         
00022         // [init services]
00023         
00024         // [init clients]
00025         
00026         // [init action servers]
00027         
00028         // [init action clients]
00029         
00030         //initializes odometry time stamp to now
00031         odometry.setTimeStamp(); 
00032                 
00033         //gets user parameters
00034         //std::cout << "CONFIG = " << alg_.config_.num_particles << std::endl; //doesn't work beacuse config_update is not yet called
00035         double lp_rt; 
00036         this->public_node_handle_.getParam("filter_rate", lp_rt); 
00037         this->loop_rate_ = lp_rt;
00038         transform_tolerance_.fromSec(1.0/lp_rt+0.1);//duration considering loc tf as good: to allow tf extrapolation
00039         this->public_node_handle_.getParam("num_particles", numberOfParticles);
00040         this->public_node_handle_.getParam("resampling_style", resamplingStyle);
00041         this->public_node_handle_.getParam("mapFile", mapFileName);
00042         this->public_node_handle_.getParam("floorGridFile", gridFileName);
00043         this->public_node_handle_.getParam("initX", initX);
00044         this->public_node_handle_.getParam("initY", initY);
00045         this->public_node_handle_.getParam("initH", initH);
00046         
00047         this->public_node_handle_.getParam("odo_error_XY",odometry.error_factor_XY);
00048         this->public_node_handle_.getParam("odo_error_H",odometry.error_factor_H);
00049         this->public_node_handle_.getParam("odo_error_P",odometry.error_factor_P);
00050         this->public_node_handle_.getParam("odo_error_R",odometry.error_factor_R);
00051         
00052         this->public_node_handle_.getParam("sigma_heading",inclinometers.sigmaH);
00053         this->public_node_handle_.getParam("sigma_pitch_roll",inclinometers.sigmaP);
00054         this->public_node_handle_.getParam("sigma_pitch_roll",inclinometers.sigmaR);
00055         
00056         this->public_node_handle_.getParam("l0_frameName",rDevConfig[0].frameName);
00057         this->public_node_handle_.getParam("l0_typeId",rDevConfig[0].deviceType);
00058         if (rDevConfig[0].deviceType == 0)
00059         {
00060                 this->public_node_handle_.getParam("l0_nRays",rDevConfig[0].nRays);
00061                 this->public_node_handle_.getParam("l0_aperture",rDevConfig[0].aperture);
00062                 this->public_node_handle_.getParam("l0_rMin",rDevConfig[0].rangeMin);
00063                 this->public_node_handle_.getParam("l0_rMax",rDevConfig[0].rangeMax);
00064                 this->public_node_handle_.getParam("l0_sigma_range",rDevConfig[0].stdDev);
00065         }
00066         this->public_node_handle_.getParam("l1_frameName",rDevConfig[1].frameName);
00067         this->public_node_handle_.getParam("l1_typeId",rDevConfig[1].deviceType);
00068         if (rDevConfig[1].deviceType == 0)
00069         {
00070                 this->public_node_handle_.getParam("l1_nRays",rDevConfig[1].nRays);
00071                 this->public_node_handle_.getParam("l1_aperture",rDevConfig[1].aperture);
00072                 this->public_node_handle_.getParam("l1_rMin",rDevConfig[1].rangeMin);
00073                 this->public_node_handle_.getParam("l1_rMax",rDevConfig[1].rangeMax);
00074                 this->public_node_handle_.getParam("l1_sigma_range",rDevConfig[1].stdDev);
00075         }
00076         this->public_node_handle_.getParam("l2_frameName",rDevConfig[2].frameName);
00077         this->public_node_handle_.getParam("l2_typeId",rDevConfig[2].deviceType);
00078         if (rDevConfig[2].deviceType == 0)
00079         {
00080                 this->public_node_handle_.getParam("l2_nRays",rDevConfig[2].nRays);
00081                 this->public_node_handle_.getParam("l2_aperture",rDevConfig[2].aperture);
00082                 this->public_node_handle_.getParam("l2_rMin",rDevConfig[2].rangeMin);
00083                 this->public_node_handle_.getParam("l2_rMax",rDevConfig[2].rangeMax);
00084                 this->public_node_handle_.getParam("l2_sigma_range",rDevConfig[2].stdDev);
00085         }
00086 
00087         //prints user's config
00088         printUserConfiguration();
00089 
00090         //init on-board laser mounting positions
00091         //sleep(1);
00092         initDevicePositions();
00093         
00094         //Allocates memory to run the filter 
00095         int debugMode;
00096         this->public_node_handle_.getParam("debug_mode",debugMode);
00097         //std::cout << "localization3d_alg_node.cpp:" << __LINE__ << ": debug_mode = "<< debugMode << std::endl;                        
00098         pFilter = new CbasicPF(gridFileName, mapFileName, (bool)debugMode);
00099         for (unsigned int ii=0; ii<MAX_RANGE_DEVICES; ii++)
00100         {
00101                 if(rDevConfig[ii].frameName != "" )//device has been configured
00102                 {
00103                         if(rDevConfig[ii].deviceType == 0 ) //device type not specified -> use paremetric description
00104                         {
00105                                 pFilter->addRangeModel(2, rDevConfig[ii].nRays, rDevConfig[ii].aperture, rDevConfig[ii].aperture/(double)rDevConfig[ii].nRays,rDevConfig[ii].rangeMin,rDevConfig[ii].rangeMax,ii);
00106                         }
00107                         else //device type has been specified
00108                         {
00109                                 pFilter->addRangeModel(rDevConfig[ii].deviceType,ii);
00110                         }
00111                 }
00112         }
00113 
00114         //initializes the filter with an initial estimate
00115         pFilter->trackingInit(numberOfParticles, initX, initY, initH);
00116         
00117 }
00118 
00119 Localization3dAlgNode::~Localization3dAlgNode(void)
00120 {
00121         // [free dynamic memory]
00122         delete pFilter;
00123 }
00124 
00125 void Localization3dAlgNode::initDevicePositions()
00126 {
00127         tf::TransformListener tfListener;
00128         tf::StampedTransform laserWRTbase;
00129 
00130 //std::cout << "Localization3dAlgNode:" << __LINE__ << std::endl;
00131 //std::string eMsg;
00132 
00133         //get device mounting point with respect to the platform (base link)
00134         for (unsigned int ii=0; ii<MAX_RANGE_DEVICES; ii++)
00135         {
00136                 if(rDevConfig[ii].frameName != "" )
00137                 {
00138                         tfListener.waitForTransform("base_link", rDevConfig[ii].frameName, ros::Time(0), ros::Duration(10.0),ros::Duration(1.0));
00139                         //tfListener.waitForTransform("base_link", rDevConfig[ii].frameName, ros::Time(0), ros::Duration(10.0),ros::Duration(1.0), & eMsg);
00140                         //std::cout << "Localization3dAlgNode:" << __LINE__ << ": " << eMsg << std::endl;
00141                         tfListener.lookupTransform("base_link", rDevConfig[ii].frameName, ros::Time(0), laserWRTbase);
00142                         laserObs[ii].mountingPosition.setXYZ(laserWRTbase.getOrigin().x(),laserWRTbase.getOrigin().y(),laserWRTbase.getOrigin().z());
00143                         laserObs[ii].mountingPosition.setQuaternion(laserWRTbase.getRotation().getW(),laserWRTbase.getRotation().getX(),laserWRTbase.getRotation().getY(),laserWRTbase.getRotation().getZ());
00144                         laserObs[ii].mountingPosition.printPosition();
00145                 }
00146         }
00147 }
00148 
00149 void Localization3dAlgNode::printUserConfiguration()
00150 {
00151         std::cout << "********************** PARTICLE FILTER CONFIGURATION **************************" << std::endl;
00152         std::cout << "Number Of Particles = \t " << numberOfParticles << std::endl;
00153         //std::cout << "Filter Rate (wished) = \t " << this->loop_rate_ << std::endl;
00154         std::cout << "Init (X,Y,H) = \t" << "(" << initX << "," << initY << "," << initH << ")" << std::endl;
00155         std::cout << "Map File = \t" << mapFileName << std::endl;
00156         std::cout << "Grid File = \t" << gridFileName << std::endl;
00157         
00158         for (unsigned int ii=0; ii<MAX_RANGE_DEVICES; ii++)
00159         {
00160                 if(rDevConfig[ii].frameName != "" )
00161                 {
00162                         std::cout << "RANGE DEVICE " << ii << std::endl;
00163                         std::cout << "\t Frame Name = \t" << rDevConfig[ii].frameName << std::endl;
00164                         std::cout << "\t Type = \t" << rDevConfig[ii].deviceType << std::endl;
00165                         std::cout << "\t Num Rays = \t" << rDevConfig[ii].nRays << std::endl;
00166                         std::cout << "\t Aperture = \t" << rDevConfig[ii].aperture << std::endl;
00167                         std::cout << "\t Min Range = \t" << rDevConfig[ii].rangeMin << std::endl;
00168                         std::cout << "\t Max Range = \t" << rDevConfig[ii].rangeMax << std::endl;
00169                 }
00170         }
00171         std::cout << "*******************************************************************************" << std::endl;
00172 }
00173 
00174 void Localization3dAlgNode::mainNodeThread(void)
00175 {
00176         double qReal, qi, qj, qk; //aux variables to fill messages
00177         unsigned int ii;
00178         Cparticle3d *particlePtr;
00179         tf::Quaternion quat;
00180         
00181 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;   
00182         //locks config mutex during an iteration
00183         config_mutex.enter();
00184         
00185         //increments iteration index
00186         pFilter->incrementIterationId();
00187 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;
00188         
00189         //propagation
00190         this->platformOdometry_mutex_.enter();
00191         //odometry.printObservation();
00192 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00193         pFilter->propagatePset(odometry);
00194 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00195         //priorTime = ros::Time::now();
00196         priorTime = odoTime;
00197         this->platformOdometry_mutex_.exit(); 
00198 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00199         
00200         //sets estimate time stamp just after propagation
00201         locEstimate.setTimeStamp();
00202         //this->PoseWithCovarianceStamped_msg_.header.stamp = ros::Time::now();
00203 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00204 
00205         //3-axis compass (compass + inclinometer) correction
00206 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00207         this->platformData_mutex_.enter();
00208         pFilter->correctPset(inclinometers);
00209         this->platformData_mutex_.exit(); 
00210 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00211 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00212         
00213         //laser correction
00214         for (ii=0; ii<MAX_RANGE_DEVICES; ii++)
00215         {       
00216                 if(rDevConfig[ii].frameName != "" )//device model has been allocated
00217                 {
00218                         this->laser_mutex[ii].enter();
00219                         pFilter->correctPset(laserObs[ii], ii);
00220                         this->laser_mutex[ii].exit(); 
00221                 }
00222         }
00223 
00224         //normalize particle set
00225         pFilter->normalizePset();
00226 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00227 
00228         //computes Info gain for this iteration
00229         infoGain += pFilter->computeKLDivergence();
00230 // std::cout << "IG = " << infoGain << std::endl;
00231 
00232         //set estimate
00233         pFilter->setEstimate(locEstimate);
00234         //locEstimate.position.printPosition();
00235 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;                   
00236 
00237         //resampling
00238         pFilter->resamplingPset((unsigned int)resamplingStyle);
00239 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;           
00240         
00241         //unlocks config mutex at the end of the filter iteration
00242         config_mutex.exit();
00243 
00244         
00245         // [fill msg structures]
00246         
00247         //fill particle cloud
00248         this->PoseArray_msg_.header.seq = pFilter->getIterationId();
00249         //this->PoseArray_msg_.header.stamp.sec = locEstimate.getTimeStampSeconds();
00250         //this->PoseArray_msg_.header.stamp.nsec = locEstimate.getTimeStampNanoSeconds();
00251         this->PoseArray_msg_.header.stamp = priorTime;
00252         this->PoseArray_msg_.header.frame_id = mapFrame;
00253         for(ii=0; ii<pFilter->getNumParticles(); ii++)
00254         {
00255                 particlePtr = pFilter->getParticle(ii);
00256                 PoseArray_msg_.poses.resize(ii+1);
00257                 PoseArray_msg_.poses.at(ii).position.x = particlePtr->getX();
00258                 PoseArray_msg_.poses.at(ii).position.y = particlePtr->getY();
00259                 PoseArray_msg_.poses.at(ii).position.z = particlePtr->getZ()+0.1;//to avoid occlusion with model ground surface
00260 //              particlePtr->getQuaternion(qReal, qi, qj, qk);
00261 //              PoseArray_msg_.poses.at(ii).orientation.x = qi;
00262 //              PoseArray_msg_.poses.at(ii).orientation.y = qj;
00263 //              PoseArray_msg_.poses.at(ii).orientation.z = qk;
00264 //              PoseArray_msg_.poses.at(ii).orientation.w = qReal;
00265                 quat = tf::createQuaternionFromRPY( locEstimate.position.getR(),locEstimate.position.getP(),locEstimate.position.getH() );
00266                 PoseArray_msg_.poses.at(ii).orientation.x = quat.getX();
00267                 PoseArray_msg_.poses.at(ii).orientation.y = quat.getY();
00268                 PoseArray_msg_.poses.at(ii).orientation.z = quat.getZ();
00269                 PoseArray_msg_.poses.at(ii).orientation.w = quat.getW();        
00270         }
00271 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;
00272 
00273         //fill localization pose estimate
00274         this->PoseWithCovarianceStamped_msg_.header.seq = pFilter->getIterationId();
00275         //this->PoseWithCovarianceStamped_msg_.header.stamp.sec = locEstimate.getTimeStampSeconds();
00276         //this->PoseWithCovarianceStamped_msg_.header.stamp.nsec = locEstimate.getTimeStampNanoSeconds();
00277         this->PoseWithCovarianceStamped_msg_.header.stamp = priorTime;
00278         this->PoseWithCovarianceStamped_msg_.header.frame_id = mapFrame;
00279         this->PoseWithCovarianceStamped_msg_.pose.pose.position.x = locEstimate.position.getX();
00280         this->PoseWithCovarianceStamped_msg_.pose.pose.position.y = locEstimate.position.getY();
00281         this->PoseWithCovarianceStamped_msg_.pose.pose.position.z = locEstimate.position.getZ();
00282         
00283         locEstimate.position.getQuaternion(qReal, qi, qj, qk);
00284         this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.x = qi;
00285         this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.y = qj;
00286         this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.z = qk;
00287         this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.w = qReal;
00288 
00289 //      quat = tf::createQuaternionFromRPY( locEstimate.position.getR(),locEstimate.position.getP(),locEstimate.position.getH() );
00290 //      this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.x = quat.getX();
00291 //      this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.y = quat.getY();
00292 //      this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.z = quat.getZ();
00293 //      this->PoseWithCovarianceStamped_msg_.pose.pose.orientation.w = quat.getW();
00294         
00295         this->PoseWithCovarianceStamped_msg_.pose.covariance[0] = locEstimate.cxx;
00296         this->PoseWithCovarianceStamped_msg_.pose.covariance[1] = locEstimate.cxy;
00297         this->PoseWithCovarianceStamped_msg_.pose.covariance[6] = locEstimate.cxy;
00298         this->PoseWithCovarianceStamped_msg_.pose.covariance[7] = locEstimate.cyy;
00299         this->PoseWithCovarianceStamped_msg_.pose.covariance[14] = locEstimate.czz;
00300         this->PoseWithCovarianceStamped_msg_.pose.covariance[21] = locEstimate.chh;
00301         this->PoseWithCovarianceStamped_msg_.pose.covariance[28] = locEstimate.cpp;
00302         this->PoseWithCovarianceStamped_msg_.pose.covariance[35] = locEstimate.crr;
00303         this->PoseWithCovarianceStamped_msg_.pose.covariance[33] = locEstimate.position.getP();
00304         this->PoseWithCovarianceStamped_msg_.pose.covariance[34] = locEstimate.position.getR();
00305 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;   
00306         
00307         // [fill srv structure and make request to the server]
00308         
00309         // [fill action structure and make request to the action server]
00310 
00311         // [publish messages]
00312         this->particleSet_publisher_.publish(this->PoseArray_msg_);
00313         this->position_publisher_.publish(this->PoseWithCovarianceStamped_msg_);
00314 // std::cout << "mainNodeThread():" << __LINE__ << std::endl;   
00315         
00316         //Publish provided tf Transforms: odom wrt map
00317         tf::Pose mapToBase;
00318         tf::poseMsgToTF(this->PoseWithCovarianceStamped_msg_.pose.pose, mapToBase);
00319         tf::Stamped<tf::Pose> baseToMap(mapToBase.inverse(),ros::Time(0),baseFrame);
00320         tf::Stamped<tf::Pose> odomToMap;
00321         this->tfListener.transformPose(odomFrame, baseToMap, odomToMap);
00322         this->tfBroadcaster.sendTransform(tf::StampedTransform(odomToMap.inverse(),priorTime+transform_tolerance_,mapFrame,odomFrame));
00323 
00324 // std::cout << "mainNodeThread(): END OF ITERATION" << std::endl << std::endl; 
00325 
00326 }
00327 
00328 /*  [subscriber callbacks] */
00329 void Localization3dAlgNode::platformData_callback(const iri_segway_rmp_msgs::SegwayRMP200Status::ConstPtr& msg) 
00330 { 
00331 //      ROS_INFO("Localization3dAlgNode::platformData_callback: New Message Received"); 
00332         
00333         //use appropiate mutex to shared variables if necessary 
00334         //this->driver_.lock(); 
00335         this->platformData_mutex_.enter(); 
00336         
00337 
00338         //std::cout << msg->data << std::endl; 
00339         inclinometers.markAsNew();
00340         inclinometers.setTimeStamp();//to do: it would be better to get ts from the message
00341         //inclinometers.setTimeStamp(msg->header.stamp.sec,msg->header.stamp.nsec);
00342         inclinometers.pitch = msg->pitch_angle;
00343         inclinometers.roll = msg->roll_angle;
00344         inclinometers.setMagneticDistortion(); //absolute heading is not provided by segway, so we indicate it by alarming 
00345         inclinometers.markAsCorrect(); //to do: we should ckeck for correctness before mark the observation as correct
00346                 
00347         //the 4 lines below should be at odometry callback, but they are here just for debugging because old bags did not provide rotation rates in the odometry message
00348 //      this->platformOdometry_mutex_.enter(); 
00349 //      odometry.accumDeltaP(dT*msg->pitch_rate); //accumulates pitch rotation
00350 //      odometry.accumDeltaR(dT*msg->roll_rate); //accumulates roll rotation
00351 //      this->platformOdometry_mutex_.exit(); 
00352         
00353         //unlock previously blocked shared variables 
00354         //this->driver_.unlock(); 
00355         this->platformData_mutex_.exit(); 
00356         
00357         //ROS_INFO("Localization3dAlgNode::platformData_callback: New Message Received 2"); 
00358 }
00359 void Localization3dAlgNode::platformOdometry_callback(const nav_msgs::Odometry::ConstPtr& msg) 
00360 { 
00361         double vx,vy,vz,vTrans;
00362         double tLast; //dT;
00363                 
00364         //ROS_INFO("Localization3dAlgNode::platformOdometry_callback: New Message Received"); 
00365 
00366         //use appropiate mutex to shared variables if necessary 
00367         //this->driver_.lock(); 
00368         this->platformOdometry_mutex_.enter(); 
00369 
00370         //std::cout << msg->data << std::endl; 
00371         odometry.markAsNew();
00372         tLast = odometry.getTimeStamp();
00373         odometry.setTimeStamp(msg->header.stamp.sec,msg->header.stamp.nsec); //get ts from the message
00374         //tLast = odometry.getTimeStamp(); //gets last time stamp
00375         //odometry.setTimeStamp(); //
00376         dT = odometry.getTimeStamp() - tLast; //computes elapsed time between consecutive readings
00377 //std::cout << "dT = " << dT << std::endl;
00378         if (fabs(dT)>1)
00379         {
00380                 std::cout << "WARNING! Odometry Integration time >1s !" << std::endl;
00381                 dT = 0;
00382         }
00383         vx = msg->twist.twist.linear.x; 
00384         vy = msg->twist.twist.linear.y;
00385         vz = msg->twist.twist.linear.z;
00386         vTrans = sqrt(vx*vx+vy*vy+vz*vz);  //odometry observation considers only forward velocity
00387         odometry.accumDeltaTrans(dT*vTrans); //accumulates translational displacement
00388         odometry.accumDeltaH(dT*msg->twist.twist.angular.z); //accumulates heading rotation
00389         odometry.accumDeltaP(dT*msg->twist.twist.angular.y); //accumulates pitch rotation
00390         odometry.accumDeltaR(dT*msg->twist.twist.angular.x); //accumulates roll rotation
00391         odometry.markAsCorrect();//to do: we should ckeck for correctness before mark the observation as correct
00392         //tf::poseMsgToTF(msg->pose.pose, odoPose);//keeps odoPose for tf broadcaster
00393         odoTime = msg->header.stamp;
00394         //odoTime = ros::Time::now();
00395 
00396         //unlock previously blocked shared variables 
00397         //this->driver_.unlock(); 
00398         this->platformOdometry_mutex_.exit(); 
00399         
00400         //ROS_INFO("Localization3dAlgNode::platformOdometry_callback: New Message Received 2"); 
00401 }
00402 void Localization3dAlgNode::laser0_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00403 { 
00404         unsigned int ii;
00405 
00406         //ROS_INFO("Localization3dAlgNode::laser0_callback: New Message Received"); 
00407 
00408         //use appropiate mutex to shared variables if necessary 
00409         //this->driver_.lock(); 
00410         this->laser_mutex[0].enter(); 
00411 
00412         //std::cout << msg->data << std::endl; 
00413         laserObs[0].markAsNew();
00414         laserObs[0].setTimeStamp(msg->header.stamp.sec,msg->header.stamp.nsec);//laserObs[1].setTimeStamp();
00415         laserObs[0].numPoints = msg->ranges.size();
00416         laserObs[0].aperture = fabs(msg->angle_max - msg->angle_min);
00417         laserObs[0].rmin = msg->range_min;
00418         laserObs[0].rmax = msg->range_max;
00419         laserObs[0].sigmaRange = rDevConfig[0].stdDev; //fixed as an user param, not in the message
00420         laserObs[0].ranges.clear(); //erase previous range data 
00421         laserObs[0].ranges.resize(laserObs[0].numPoints);
00422         if (msg->angle_min > msg->angle_max) //angles are provided clockwise from an overhead point of view
00423         {
00424 //              ROS_INFO("Localization3dAlgNode::laser0_callback: Clockwise"); 
00425                 for(ii=0; ii<laserObs[0].numPoints; ii++) laserObs[0].ranges.at(ii) = msg->ranges.at(ii);
00426         }
00427         else //angles are provided counterclockwise from an overhead point of view
00428         {
00429 //              ROS_INFO("Localization3dAlgNode::laser0_callback: CounterClockwise"); 
00430                 for(ii=0; ii<laserObs[0].numPoints; ii++) laserObs[0].ranges.at(ii) = msg->ranges.at(laserObs[0].numPoints-1-ii);
00431         }
00432         laserObs[0].markAsCorrect();//to do: we should ckeck for correctness before mark the observation as correct
00433         //laserObs[1].printObservation();//debug: check received data
00434         
00435         //unlock previously blocked shared variables 
00436         //this->driver_.unlock(); 
00437         this->laser_mutex[0].exit(); 
00438         
00439         //ROS_INFO("Localization3dAlgNode::laser0_callback: New Message Received 2"); 
00440 }
00441 void Localization3dAlgNode::laser1_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00442 { 
00443         unsigned int ii;
00444 
00445         //ROS_INFO("Localization3dAlgNode::laser1_callback: New Message Received"); 
00446 
00447         //use appropiate mutex to shared variables if necessary 
00448         //this->driver_.lock(); 
00449         this->laser_mutex[1].enter(); 
00450 
00451         //std::cout << msg->data << std::endl; 
00452         laserObs[1].markAsNew();
00453         laserObs[1].setTimeStamp(msg->header.stamp.sec,msg->header.stamp.nsec);//laserObs[1].setTimeStamp();
00454         laserObs[1].numPoints = msg->ranges.size();
00455         laserObs[1].aperture = fabs(msg->angle_max - msg->angle_min);
00456         laserObs[1].rmin = msg->range_min;
00457         laserObs[1].rmax = msg->range_max;
00458         laserObs[1].sigmaRange = rDevConfig[1].stdDev; //fixed as an user param, not in the message
00459         laserObs[1].ranges.clear(); //erase previous range data 
00460         laserObs[1].ranges.resize(laserObs[1].numPoints);
00461         if (msg->angle_min > msg->angle_max) //angles are provided clockwise from an overhead point of view
00462         {
00463 //              ROS_INFO("Localization3dAlgNode::laser1_callback: Clockwise"); 
00464                 for(ii=0; ii<laserObs[1].numPoints; ii++) laserObs[1].ranges.at(ii) = msg->ranges.at(ii);
00465         }
00466         else //angles are provided counterclockwise from an overhead point of view
00467         {
00468 //              ROS_INFO("Localization3dAlgNode::laser1_callback: CounterClockwise"); 
00469                 for(ii=0; ii<laserObs[1].numPoints; ii++) laserObs[1].ranges.at(ii) = msg->ranges.at(laserObs[1].numPoints-1-ii);
00470         }
00471         laserObs[1].markAsCorrect();//to do: we should ckeck for correctness before mark the observation as correct
00472         //laserObs[1].printObservation();//debug: check received data
00473         
00474         //unlock previously blocked shared variables 
00475         //this->driver_.unlock(); 
00476         this->laser_mutex[1].exit(); 
00477         
00478         //ROS_INFO("Localization3dAlgNode::laser1_callback: New Message Received 2");   
00479 }
00480 void Localization3dAlgNode::laser2_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00481 { 
00482         unsigned int ii;
00483         
00484         //ROS_INFO("Localization3dAlgNode::laser2_callback: New Message Received"); 
00485 
00486         //use appropiate mutex to shared variables if necessary 
00487         //this->driver_.lock(); 
00488         this->laser_mutex[2].enter(); 
00489 
00490         //std::cout << msg->data << std::endl; 
00491         laserObs[2].markAsNew();
00492         laserObs[2].setTimeStamp(msg->header.stamp.sec,msg->header.stamp.nsec);//laserObs[1].setTimeStamp();
00493         laserObs[2].numPoints = msg->ranges.size();
00494         laserObs[2].aperture = fabs(msg->angle_max - msg->angle_min);
00495         laserObs[2].rmin = msg->range_min;
00496         laserObs[2].rmax = msg->range_max;
00497         laserObs[2].sigmaRange = rDevConfig[2].stdDev; //fixed as an user param, not in the message
00498         laserObs[2].ranges.clear(); //erase previous range data 
00499         laserObs[2].ranges.resize(laserObs[2].numPoints);
00500         if (msg->angle_min > msg->angle_max) //angles are provided clockwise from an overhead point of view
00501         {
00502 //              ROS_INFO("Localization3dAlgNode::laser2_callback: Clockwise"); 
00503                 for(ii=0; ii<laserObs[2].numPoints; ii++) laserObs[2].ranges.at(ii) = msg->ranges.at(ii);
00504         }
00505         else //angles are provided counterclockwise from an overhead point of view
00506         {
00507 //              ROS_INFO("Localization3dAlgNode::laser2_callback: CounterClockwise"); 
00508                 for(ii=0; ii<laserObs[2].numPoints; ii++) laserObs[2].ranges.at(ii) = msg->ranges.at(laserObs[2].numPoints-1-ii);
00509         }
00510         laserObs[2].markAsCorrect();//to do: we should ckeck for correctness before mark the observation as correct
00511         //laserObs[2].printObservation();//debug: check received data
00512         
00513         //unlock previously blocked shared variables 
00514         //this->driver_.unlock(); 
00515         this->laser_mutex[2].exit(); 
00516 
00517         //ROS_INFO("Localization3dAlgNode::laser2_callback: New Message Received 2"); 
00518 }
00519 
00520 /*  [service callbacks] */
00521 
00522 /*  [action callbacks] */
00523 
00524 /*  [action requests] */
00525 
00526 
00527 void Localization3dAlgNode::node_config_update(Config &config, uint32_t level)
00528 {
00529         config_mutex.enter();
00530         this->public_node_handle_.getParam("num_particles", numberOfParticles);
00531         pFilter->setNumParticles( (unsigned int)numberOfParticles );
00532         config_mutex.exit();
00533 }
00534 
00535 void Localization3dAlgNode::addNodeDiagnostics(void)
00536 {
00537 }
00538 
00539 // void Localization3dAlgNode::setLaserObservation(const sensor_msgs::LaserScan::ConstPtr& msg, ClaserObservation & laserData)
00540 // {
00541 //      laserData.
00542 // }
00543 
00544 /* main function */
00545 int main(int argc,char *argv[])
00546 {
00547         //initialize the filter (to do)
00548         
00549         //initialize glut (faramotics objects)
00550         glutInit(&argc, argv);
00551 
00552         //run the thread
00553         return algorithm_base::main<Localization3dAlgNode>(argc, argv, "localization3d_alg_node");
00554 }


iri_localization3d
Author(s): Andreu Corominas Murtra
autogenerated on Fri Dec 6 2013 23:23:13