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
00030
00031
00032
00033
00034 #include "rawlog_play_node.h"
00035 #include <boost/interprocess/sync/scoped_lock.hpp>
00036 #include <mrpt_bridge/pose.h>
00037 #include <mrpt_bridge/laser_scan.h>
00038 #include <mrpt_bridge/time.h>
00039 #include <mrpt_bridge/beacon.h>
00040 #include <mrpt_bridge/landmark.h>
00041 #include <mrpt/system/filesystem.h>
00042
00043 #include <mrpt/version.h>
00044 #include <mrpt/obs/CSensoryFrame.h>
00045 #include <mrpt/obs/CRawlog.h>
00046 #include <mrpt/obs/CObservation2DRangeScan.h>
00047 #include <mrpt/obs/CObservationBeaconRanges.h>
00048 #include <mrpt/obs/CObservationBearingRange.h>
00049 using namespace mrpt::obs;
00050
00051 int main(int argc, char** argv)
00052 {
00053 ros::init(argc, argv, "rawlog_play");
00054 ros::NodeHandle n;
00055 RawlogPlayNode my_node(n);
00056 my_node.init();
00057 my_node.loop();
00058 return 0;
00059 }
00060
00061 RawlogPlayNode::~RawlogPlayNode() {}
00062 RawlogPlayNode::RawlogPlayNode(ros::NodeHandle& n)
00063 : RawlogPlay(new RawlogPlayNode::ParametersNode()), n_(n), loop_count_(0)
00064 {
00065 }
00066
00067 RawlogPlayNode::ParametersNode* RawlogPlayNode::param()
00068 {
00069 return (RawlogPlayNode::ParametersNode*)param_;
00070 }
00071
00072 void RawlogPlayNode::init()
00073 {
00074 if (!mrpt::system::fileExists(param_->rawlog_file))
00075 {
00076 ROS_ERROR("raw_file: %s does not exit", param_->rawlog_file.c_str());
00077 }
00078 rawlog_stream_.open(param_->rawlog_file);
00079 pub_laser_ = n_.advertise<sensor_msgs::LaserScan>("scan", 10);
00080 pub_beacon_ = n_.advertise<mrpt_msgs::ObservationRangeBeacon>("beacon", 10);
00081 pub_landmark_ =
00082 n_.advertise<mrpt_msgs::ObservationRangeBearing>("landmark", 10);
00083 odom_frame_ = tf::resolve(param()->tf_prefix, param()->odom_frame);
00084 base_frame_ = tf::resolve(param()->tf_prefix, param()->base_frame);
00085 robotPose = mrpt::poses::CPose3DPDFGaussian();
00086 }
00087
00088 bool RawlogPlayNode::nextEntry()
00089 {
00090 CActionCollection::Ptr action;
00091 CSensoryFrame::Ptr observations;
00092 CObservation::Ptr obs;
00093
00094 if (!CRawlog::getActionObservationPairOrObservation(
00095 rawlog_stream_, action, observations, obs, entry_))
00096 {
00097 ROS_INFO("end of stream!");
00098 return true;
00099 }
00100 mrpt::poses::CPose3D pose_sensor;
00101 geometry_msgs::Pose msg_pose_sensor;
00102 tf::Transform transform;
00103
00104
00105 for (size_t i = 0; i < observations->size(); i++)
00106 {
00107 CObservation2DRangeScan::Ptr laser =
00108 observations->getObservationByClass<CObservation2DRangeScan>(i);
00109 CObservationBeaconRanges::Ptr beacon =
00110 observations->getObservationByClass<CObservationBeaconRanges>(i);
00111 CObservationBearingRange::Ptr landmark =
00112 observations->getObservationByClass<CObservationBearingRange>(i);
00113 if (laser)
00114 {
00115 mrpt_bridge::convert(*laser, msg_laser_, msg_pose_sensor);
00116 laser->getSensorPose(pose_sensor);
00117 if (msg_laser_.header.frame_id.empty())
00118 msg_laser_.header.frame_id = "laser_link";
00119 std::string childframe =
00120 tf::resolve(param()->tf_prefix, msg_laser_.header.frame_id);
00121 msg_laser_.header.stamp = ros::Time::now();
00122 mrpt_bridge::convert(pose_sensor, transform);
00123 tf_broadcaster_.sendTransform(
00124 tf::StampedTransform(
00125 transform, msg_laser_.header.stamp + ros::Duration(0.05),
00126 base_frame_, childframe));
00127 pub_laser_.publish(msg_laser_);
00128 laser =
00129 observations->getObservationByClass<CObservation2DRangeScan>();
00130 }
00131 else if (beacon)
00132 {
00133 mrpt_bridge::convert(*beacon, msg_beacon_, msg_pose_sensor);
00134 beacon->getSensorPose(pose_sensor);
00135 if (msg_beacon_.header.frame_id.empty())
00136 msg_beacon_.header.frame_id = "beacon_link";
00137 std::string childframe =
00138 tf::resolve(param()->tf_prefix, msg_beacon_.header.frame_id);
00139 msg_beacon_.header.stamp = ros::Time::now();
00140 mrpt_bridge::convert(pose_sensor, transform);
00141 tf_broadcaster_.sendTransform(
00142 tf::StampedTransform(
00143 transform, msg_beacon_.header.stamp + ros::Duration(0.05),
00144 base_frame_, childframe));
00145 pub_beacon_.publish(msg_beacon_);
00146 beacon =
00147 observations->getObservationByClass<CObservationBeaconRanges>();
00148 }
00149 else if (landmark)
00150 {
00151 mrpt_bridge::convert(*landmark, msg_landmark_, msg_pose_sensor);
00152 landmark->getSensorPose(pose_sensor);
00153 if (msg_landmark_.header.frame_id.empty())
00154 msg_landmark_.header.frame_id = "landmark_link";
00155 std::string childframe =
00156 tf::resolve(param()->tf_prefix, msg_landmark_.header.frame_id);
00157 msg_landmark_.header.stamp = ros::Time::now();
00158 mrpt_bridge::convert(pose_sensor, transform);
00159 tf_broadcaster_.sendTransform(
00160 tf::StampedTransform(
00161 transform, msg_landmark_.header.stamp + ros::Duration(0.05),
00162 base_frame_, childframe));
00163 pub_landmark_.publish(msg_landmark_);
00164 landmark =
00165 observations->getObservationByClass<CObservationBearingRange>();
00166 }
00167 else
00168 {
00169 break;
00170 }
00171 }
00172 mrpt::poses::CPose3DPDFGaussian out_pose_increment;
00173 action->getFirstMovementEstimation(out_pose_increment);
00174 robotPose -= out_pose_increment;
00175
00176 msg_odom_.header.frame_id = "odom";
00177 msg_odom_.child_frame_id = base_frame_;
00178 if (!msg_laser_.header.frame_id.empty())
00179 {
00180 msg_odom_.header.stamp = msg_laser_.header.stamp;
00181 msg_odom_.header.seq = msg_laser_.header.seq;
00182 }
00183 else if (!msg_beacon_.header.frame_id.empty())
00184 {
00185 msg_odom_.header.stamp = msg_beacon_.header.stamp;
00186 msg_odom_.header.seq = msg_beacon_.header.seq;
00187 }
00188 else if (!msg_landmark_.header.frame_id.empty())
00189 {
00190 msg_odom_.header.stamp = msg_landmark_.header.stamp;
00191 msg_odom_.header.seq = msg_landmark_.header.seq;
00192 }
00193 mrpt_bridge::convert(robotPose, msg_odom_.pose);
00194 mrpt_bridge::convert(robotPose, transform);
00195
00196 msg_odom_.header.stamp = ros::Time::now();
00197
00198 tf_broadcaster_.sendTransform(
00199 tf::StampedTransform(
00200 transform.inverse(), msg_odom_.header.stamp + ros::Duration(0.05),
00201 odom_frame_, base_frame_));
00202 return false;
00203 }
00204
00205 void RawlogPlayNode::loop()
00206 {
00207 bool end = false;
00208 for (ros::Rate rate(param()->rate); ros::ok() && !end; loop_count_++)
00209 {
00210 param()->update(loop_count_);
00211 end = nextEntry();
00212 ros::spinOnce();
00213 rate.sleep();
00214 }
00215 }