rawlog_play_node.cpp
Go to the documentation of this file.
1 /***********************************************************************************
2  * Revised BSD License *
3  * Copyright (c) 2014, Markus Bader <markus.bader@tuwien.ac.at> *
4  * All rights reserved. *
5  * *
6  * Redistribution and use in source and binary forms, with or without *
7  * modification, are permitted provided that the following conditions are met: *
8  * * Redistributions of source code must retain the above copyright *
9  * notice, this list of conditions and the following disclaimer. *
10  * * Redistributions in binary form must reproduce the above copyright *
11  * notice, this list of conditions and the following disclaimer in the *
12  * documentation and/or other materials provided with the distribution. *
13  * * Neither the name of the Vienna University of Technology nor the *
14  * names of its contributors may be used to endorse or promote products *
15  * derived from this software without specific prior written permission. *
16  * *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  *AND *
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  **
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
22  * DISCLAIMED. IN NO EVENT SHALL Markus Bader BE LIABLE FOR ANY *
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  **
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  **
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  ** *
32  ***********************************************************************************/
33 
34 #include "rawlog_play_node.h"
35 #include <boost/interprocess/sync/scoped_lock.hpp>
36 #include <mrpt_bridge/pose.h>
37 #include <mrpt_bridge/laser_scan.h>
38 #include <mrpt_bridge/time.h>
39 #include <mrpt_bridge/beacon.h>
40 #include <mrpt_bridge/landmark.h>
41 #include <mrpt/system/filesystem.h>
42 
43 #include <mrpt/version.h>
44 #include <mrpt/obs/CSensoryFrame.h>
45 #include <mrpt/obs/CRawlog.h>
46 #include <mrpt/obs/CObservation2DRangeScan.h>
47 #include <mrpt/obs/CObservationBeaconRanges.h>
48 #include <mrpt/obs/CObservationBearingRange.h>
49 using namespace mrpt::obs;
50 
51 #if MRPT_VERSION >= 0x199
52 #include <mrpt/serialization/CArchive.h>
53 #endif
54 
55 int main(int argc, char** argv)
56 {
57  ros::init(argc, argv, "rawlog_play");
59  RawlogPlayNode my_node(n);
60  my_node.init();
61  my_node.loop();
62  return 0;
63 }
64 
67  : RawlogPlay(new RawlogPlayNode::ParametersNode()), n_(n), loop_count_(0)
68 {
69 }
70 
72 {
74 }
75 
77 {
79  {
80  ROS_ERROR("raw_file: %s does not exit", param_->rawlog_file.c_str());
81  ros::shutdown();
82  return;
83  }
89  odom_frame_ = tf::resolve(param()->tf_prefix, param()->odom_frame);
90  base_frame_ = tf::resolve(param()->tf_prefix, param()->base_frame);
92 }
93 
95  const mrpt::obs::CObservation::Ptr& o)
96 {
97  mrpt::poses::CPose3D pose_sensor;
98  o->getSensorPose(pose_sensor);
99 
100  geometry_msgs::Pose msg_pose_sensor;
102 
103 #if MRPT_VERSION >= 0x199
104  // IS_CLASS accepts a reference in MRPT2
105  auto& oo = *o;
106 #else
107  // IS_CLASS accepts a pointer in MRPT1
108  auto* oo = o.get();
109 #endif
110 
112  { // laser observation detected
114  mrpt_bridge::convert(*laser, msg_laser_, msg_pose_sensor);
115  if (msg_laser_.header.frame_id.empty())
116  msg_laser_.header.frame_id = "laser_link";
117  std::string childframe =
118  tf::resolve(param()->tf_prefix, msg_laser_.header.frame_id);
119  msg_laser_.header.stamp = ros::Time::now();
120  mrpt_bridge::convert(pose_sensor, transform);
122  transform, msg_laser_.header.stamp + ros::Duration(0.05),
123  base_frame_, childframe));
125  }
126  else if (IS_CLASS(oo, CObservation2DRangeScan))
127  {
129  mrpt_bridge::convert(*beacon, msg_beacon_, msg_pose_sensor);
130  if (msg_beacon_.header.frame_id.empty())
131  msg_beacon_.header.frame_id = "beacon_link";
132  std::string childframe =
133  tf::resolve(param()->tf_prefix, msg_beacon_.header.frame_id);
134  msg_beacon_.header.stamp = ros::Time::now();
135  mrpt_bridge::convert(pose_sensor, transform);
137  transform, msg_beacon_.header.stamp + ros::Duration(0.05),
138  base_frame_, childframe));
140  }
141  else if (IS_CLASS(oo, CObservationBearingRange))
142  {
144  mrpt_bridge::convert(*landmark, msg_landmark_, msg_pose_sensor);
145  if (msg_landmark_.header.frame_id.empty())
146  msg_landmark_.header.frame_id = "landmark_link";
147  std::string childframe =
148  tf::resolve(param()->tf_prefix, msg_landmark_.header.frame_id);
149  msg_landmark_.header.stamp = ros::Time::now();
150  mrpt_bridge::convert(pose_sensor, transform);
152  transform, msg_landmark_.header.stamp + ros::Duration(0.05),
153  base_frame_, childframe));
155  }
156  else
157  {
158  ROS_WARN(
159  "Observation mapping to ROS not implemented: %s",
160  o->GetRuntimeClass()->className);
161  }
162 } // end publishSingleObservation()
163 
165 {
166  CActionCollection::Ptr action;
167  CSensoryFrame::Ptr observations;
168  CObservation::Ptr obs;
169 
170 #if MRPT_VERSION >= 0x199
171  auto rs = mrpt::serialization::archiveFrom(rawlog_stream_);
172 #else
173  auto& rs = rawlog_stream_;
174 #endif
175 
176  if (!CRawlog::getActionObservationPairOrObservation(
177  rs, action, observations, obs, entry_))
178  {
179  ROS_INFO("end of stream!");
180  return true;
181  }
183 
184  // Process single obs, if present:
185  if (obs) publishSingleObservation(obs);
186  // and process all obs into a CSensoryFrame, if present:
187  for (const auto& o : *observations) publishSingleObservation(o);
188 
189  mrpt::poses::CPose3DPDFGaussian out_pose_increment;
190  action->getFirstMovementEstimation(out_pose_increment);
191  robotPose -= out_pose_increment;
192 
193  msg_odom_.header.frame_id = "odom";
194  msg_odom_.child_frame_id = base_frame_;
195  if (!msg_laser_.header.frame_id.empty())
196  {
197  msg_odom_.header.stamp = msg_laser_.header.stamp;
198  msg_odom_.header.seq = msg_laser_.header.seq;
199  }
200  else if (!msg_beacon_.header.frame_id.empty())
201  {
202  msg_odom_.header.stamp = msg_beacon_.header.stamp;
203  msg_odom_.header.seq = msg_beacon_.header.seq;
204  }
205  else if (!msg_landmark_.header.frame_id.empty())
206  {
207  msg_odom_.header.stamp = msg_landmark_.header.stamp;
208  msg_odom_.header.seq = msg_landmark_.header.seq;
209  }
211  mrpt_bridge::convert(robotPose, transform);
212 
213  msg_odom_.header.stamp = ros::Time::now();
214 
216  transform.inverse(), msg_odom_.header.stamp + ros::Duration(0.05),
218  return false;
219 }
220 
222 {
223  bool end = false;
224  for (ros::Rate rate(param()->rate); ros::ok() && !end; loop_count_++)
225  {
227  end = nextEntry();
228  ros::spinOnce();
229  rate.sleep();
230  }
231 }
int main(int argc, char **argv)
ros::Publisher pub_landmark_
void publish(const boost::shared_ptr< M > &message) const
std::string rawlog_file
Definition: rawlog_play.h:63
Parameters * param_
Definition: rawlog_play.h:70
bool BASE_IMPEXP fileExists(const std::string &fileName)
ros::NodeHandle n_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool open(const std::string &fileName)
ParametersNode * param()
size_t entry_
Definition: rawlog_play.h:73
RawlogPlayNode(ros::NodeHandle &n)
#define ROS_WARN(...)
sensor_msgs::LaserScan msg_laser_
GLuint GLenum GLenum transform
void update(const unsigned long &loop_count)
GLuint GLuint end
std::string resolve(const std::string &prefix, const std::string &frame_name)
GLsizei n
mrpt::poses::CPose3DPDFGaussian robotPose
Definition: rawlog_play.h:72
nav_msgs::Odometry msg_odom_
obs
void publishSingleObservation(const mrpt::obs::CObservation::Ptr &o)
mrpt_msgs::ObservationRangeBearing msg_landmark_
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
void sendTransform(const StampedTransform &transform)
std::string base_frame_
Transform inverse() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
tf::TransformBroadcaster tf_broadcaster_
action
std::string odom_frame_
void convert(const ros::Time &src, mrpt::system::TTimeStamp &des)
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
static Time now()
ROSCPP_DECL void shutdown()
GLfloat param
ros::Publisher pub_beacon_
#define IS_CLASS(ptrObj, class_name)
ROSCPP_DECL void spinOnce()
unsigned long loop_count_
mrpt_msgs::ObservationRangeBeacon msg_beacon_
#define ROS_ERROR(...)
ros::Publisher pub_laser_
CFileGZInputStream rawlog_stream_
Definition: rawlog_play.h:71


mrpt_rawlog
Author(s):
autogenerated on Thu Mar 12 2020 03:22:04