Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "rawlog_play_node.h"
00030 #include <boost/interprocess/sync/scoped_lock.hpp>
00031 #include <mrpt_bridge/pose.h>
00032 #include <mrpt_bridge/laser_scan.h>
00033 #include <mrpt_bridge/time.h>
00034
00035 #include <mrpt/system/filesystem.h>
00036 #include <mrpt/slam/CSensoryFrame.h>
00037 #include <mrpt/slam/CSensoryFrame.h>
00038 #include <mrpt/slam/CRawlog.h>
00039 #include <mrpt/slam/CObservation2DRangeScan.h>
00040
00041
00042 int main(int argc, char **argv) {
00043
00044 ros::init(argc, argv, "DataLogger");
00045 ros::NodeHandle n;
00046 RawlogPlayNode my_node(n);
00047 my_node.init();
00048 my_node.loop();
00049 return 0;
00050 }
00051
00052 RawlogPlayNode::~RawlogPlayNode() {
00053 }
00054
00055 RawlogPlayNode::RawlogPlayNode(ros::NodeHandle &n) :
00056 RawlogPlay(new RawlogPlayNode::ParametersNode()), n_(n), loop_count_(0) {
00057
00058 }
00059
00060 RawlogPlayNode::ParametersNode *RawlogPlayNode::param() {
00061 return (RawlogPlayNode::ParametersNode*) param_;
00062 }
00063
00064 void RawlogPlayNode::init() {
00065
00066 if(!mrpt::system::fileExists(param_->rawlog_file)) {
00067 ROS_ERROR("raw_file: %s does not exit", param_->rawlog_file.c_str());
00068 }
00069 rawlog_stream_.open(param_->rawlog_file);
00070 pub_laser_ = n_.advertise<sensor_msgs::LaserScan>("scan", 10);
00071 odom_frame_ = tf::resolve(param()->tf_prefix, param()->odom_frame);
00072 base_frame_ = tf::resolve(param()->tf_prefix, param()->base_frame);
00073 robotPose = mrpt::poses::CPose3DPDFGaussian();
00074 }
00075
00076 bool RawlogPlayNode::nextEntry() {
00077 mrpt::slam::CActionCollectionPtr action;
00078 mrpt::slam::CSensoryFramePtr observations;
00079 mrpt::slam::CObservationPtr obs;
00080
00081 if(!mrpt::slam::CRawlog::getActionObservationPairOrObservation( rawlog_stream_, action, observations, obs, entry_)) {
00082 ROS_INFO("end of stream!");
00083 return true;
00084 }
00085 mrpt::poses::CPose3D pose_laser;
00086 geometry_msgs::Pose msg_pose_laser;
00087 tf::Transform transform;
00088
00089
00090 for(size_t i = 0;i < observations->size() ;i++){
00091 mrpt::slam::CObservation2DRangeScanPtr laser = observations->getObservationByClass<mrpt::slam::CObservation2DRangeScan>(i);
00092 if(laser.pointer() == NULL) break;
00093 mrpt_bridge::convert(*laser, msg_laser_, msg_pose_laser);
00094 laser->getSensorPose(pose_laser);
00095 mrpt_bridge::convert(pose_laser, transform);
00096 std::string childframe = tf::resolve(param()->tf_prefix, msg_laser_.header.frame_id);
00097 tf_broadcaster_.sendTransform(tf::StampedTransform(transform, msg_laser_.header.stamp, base_frame_, childframe));
00098 pub_laser_.publish(msg_laser_);
00099 laser = observations->getObservationByClass<mrpt::slam::CObservation2DRangeScan>();
00100 }
00101 mrpt::poses::CPose3DPDFGaussian out_pose_increment;
00102 action->getFirstMovementEstimation (out_pose_increment);
00103 robotPose -= out_pose_increment;
00104
00105 msg_odom_.header.frame_id = "odom";
00106 msg_odom_.child_frame_id = base_frame_;
00107 msg_odom_.header.stamp = msg_laser_.header.stamp;
00108 msg_odom_.header.seq = msg_laser_.header.seq;
00109 mrpt_bridge::convert(robotPose, msg_odom_.pose);
00110 mrpt_bridge::convert(robotPose, transform);
00111 tf_broadcaster_.sendTransform(tf::StampedTransform(transform, msg_odom_.header.stamp, base_frame_, odom_frame_));
00112 return false;
00113
00114 }
00115
00116 void RawlogPlayNode::loop() {
00117 bool end = false;
00118 for (ros::Rate rate(param()->rate); ros::ok() && !end; loop_count_++) {
00119 param()->update(loop_count_);
00120 end = nextEntry();
00121 ros::spinOnce();
00122 rate.sleep();
00123 }
00124 }