MRPT  1.9.9
carmen_log_tools.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "obs-precomp.h" // Precompiled headers
11 
15 
17 
19 
20 using namespace mrpt;
21 using namespace mrpt::obs;
22 using namespace mrpt::poses;
23 using namespace mrpt::system;
24 using namespace std;
25 
26 // Read the declaration in the .h file for documentation.
28  std::istream& in_stream,
29  std::vector<mrpt::obs::CObservation::Ptr>& out_observations,
30  const mrpt::system::TTimeStamp& time_start_log)
31 {
32  static TParametersString
33  global_log_params; // global parameters loaded in previous calls.
34 
35  out_observations.clear(); // empty output container
36 
37  // Try to get line:
38  string line;
39  while (line.empty())
40  {
41  if (!in_stream) return false; // End of file
42  std::getline(in_stream, line);
43  line = trim(line);
44  };
45 
46  // Now we have a line: analyze it:
47  if (strStartsI(line, "ROBOTLASER"))
48  {
49  // ROBOTLASER message
50  // ---------------------------
51  std::istringstream S; // Read from the string as if it was a stream
52  S.str(line);
53 
54  CObservation2DRangeScan::Ptr obsLaser_ptr =
55  mrpt::make_aligned_shared<CObservation2DRangeScan>();
56  CObservation2DRangeScan* obsLaser =
57  obsLaser_ptr.get(); // Faster access
58 
59  // Parse:
60  int laser_type; // SICK_LMS = 0, SICK_PLS = 1, HOKUYO_URG = 2,
61  // SIMULATED_LASER = 3,
62  double start_angle, angular_resolution, accuracy;
63  int remission_mode; // OFF = 0, DIRECT = 1, NORMALIZED = 2
64 
65  if (!(S >> obsLaser->sensorLabel >> laser_type >> start_angle >>
66  obsLaser->aperture >> angular_resolution >> obsLaser->maxRange >>
67  accuracy >> remission_mode))
69  "Error parsing line from CARMEN log (params):\n'%s'\n",
70  line.c_str())
71 
72  size_t nRanges;
73  S >> nRanges;
74 
75  obsLaser->resizeScan(nRanges);
76 
77  for (size_t i = 0; i < nRanges; i++)
78  {
79  float range;
80  if (!(S >> range))
82  "Error parsing line from CARMEN log (ranges):\n'%s'\n",
83  line.c_str());
84  obsLaser->setScanRange(i, range);
85  // Valid value?
86  obsLaser->setScanRangeValidity(
87  i, (obsLaser->scan[i] >= obsLaser->maxRange ||
88  obsLaser->scan[i] <= 0));
89  }
90 
91  size_t remmision_count;
92  if (!(S >> remmision_count))
94  "Error parsing line from CARMEN log (remmision_count):\n'%s'\n",
95  line.c_str())
96 
97  vector<double> remission;
98  remission.resize(remmision_count);
99 
100  for (size_t i = 0; i < remmision_count; i++)
101  {
102  if (!(S >> remission[i]))
104  "Error parsing line from CARMEN log (remmision "
105  "vals):\n'%s'\n",
106  line.c_str())
107  }
108 
109  mrpt::math::TPose2D globalLaserPose;
110  mrpt::math::TPose2D globalRobotPose;
111 
112  if (!(S >> globalLaserPose.x >> globalLaserPose.y >>
113  globalLaserPose.phi >> globalRobotPose.x >> globalRobotPose.y >>
114  globalRobotPose.phi))
116  "Error parsing line from CARMEN log (poses):\n'%s'\n",
117  line.c_str())
118 
119  // Compute pose of laser on the robot:
120  obsLaser->sensorPose =
121  CPose3D(CPose2D(globalLaserPose) - CPose2D(globalRobotPose));
122 
123  double tv, rv, fw_dist, side_dist, turn_axis;
124  S >> tv >> rv >> fw_dist >> side_dist >> turn_axis;
125 
126  double timestamp;
127  string robotName;
128  S >> timestamp >> robotName;
129 
130  const mrpt::system::TTimeStamp obs_time =
131  time_start_log + std::chrono::microseconds(static_cast<uint64_t>(1e-6 * timestamp));
132 
133  obsLaser->timestamp = obs_time;
134 
135  // Create odometry observation:
136  {
137  CObservationOdometry::Ptr obsOdo_ptr =
138  mrpt::make_aligned_shared<CObservationOdometry>();
139 
140  obsOdo_ptr->timestamp = obs_time;
141  obsOdo_ptr->odometry = CPose2D(globalRobotPose);
142  obsOdo_ptr->sensorLabel = "ODOMETRY";
143 
144  out_observations.push_back(obsOdo_ptr);
145  }
146 
147  // Send out laser observation:
148  out_observations.push_back(obsLaser_ptr);
149 
150  } // end ROBOTLASER
151  else if (strStartsI(line, "FLASER") || strStartsI(line, "RLASER"))
152  {
153  // [F,R]LASER message
154  // FLASER num_readings [range_readings] x y theta odom_x odom_y
155  // odom_theta
156  // ---------------------------
157  std::istringstream S; // Read from the string as if it was a stream
158  S.str(line);
159 
160  CObservation2DRangeScan::Ptr obsLaser_ptr =
161  mrpt::make_aligned_shared<CObservation2DRangeScan>();
162  CObservation2DRangeScan* obsLaser =
163  obsLaser_ptr.get(); // Faster access
164 
165  // Parse:
166  size_t nRanges;
167 
168  if (!(S >> obsLaser->sensorLabel >> nRanges))
170  "Error parsing line from CARMEN log (params):\n'%s'\n",
171  line.c_str())
172 
173  // Params:
174  {
175  double maxRange = 81.0;
176  double resolutionDeg = 0.5;
177 
178  if (line[0] == 'F')
179  { // front:
180  maxRange = atof(
181  global_log_params
182  .getWithDefaultVal("robot_front_laser_max", "81.0")
183  .c_str());
184  resolutionDeg =
185  atof(global_log_params
186  .getWithDefaultVal(
187  "laser_front_laser_resolution", "0.5")
188  .c_str());
189  }
190  else if (line[0] == 'R')
191  { // rear:
192  maxRange = atof(
193  global_log_params
194  .getWithDefaultVal("robot_rear_laser_max", "81.0")
195  .c_str());
196  resolutionDeg =
197  atof(global_log_params
198  .getWithDefaultVal(
199  "laser_rear_laser_resolution", "0.5")
200  .c_str());
201  }
202  obsLaser->maxRange = maxRange;
203  obsLaser->aperture = DEG2RAD(resolutionDeg) * nRanges;
204  }
205 
206  obsLaser->resizeScan(nRanges);
207 
208  for (size_t i = 0; i < nRanges; i++)
209  {
210  float range;
211  if (!(S >> range))
213  "Error parsing line from CARMEN log (ranges):\n'%s'\n",
214  line.c_str());
215  obsLaser->setScanRange(i, range);
216  // Valid value?
217  obsLaser->setScanRangeValidity(
218  i, (obsLaser->scan[i] >= obsLaser->maxRange ||
219  obsLaser->scan[i] <= 0));
220  }
221 
222  mrpt::math::TPose2D globalLaserPose;
223  mrpt::math::TPose2D globalRobotPose;
224  if (!(S >> globalLaserPose.x >> globalLaserPose.y >>
225  globalLaserPose.phi >> globalRobotPose.x >> globalRobotPose.y >>
226  globalRobotPose.phi))
228  "Error parsing line from CARMEN log (poses):\n'%s'\n",
229  line.c_str())
230 
231  // Compute pose of laser on the robot:
232  obsLaser->sensorPose =
233  CPose3D(CPose2D(globalLaserPose) - CPose2D(globalRobotPose));
234 
235  double timestamp;
236  string robotName;
237  S >> timestamp >> robotName;
238 
239  const mrpt::system::TTimeStamp obs_time =
240  time_start_log + std::chrono::microseconds(static_cast<uint64_t>(1e-6 * timestamp));
241 
242  obsLaser->timestamp = obs_time;
243 
244  // Create odometry observation:
245  {
246  CObservationOdometry::Ptr obsOdo_ptr =
247  mrpt::make_aligned_shared<CObservationOdometry>();
248 
249  obsOdo_ptr->timestamp = obs_time;
250  obsOdo_ptr->odometry = CPose2D(globalRobotPose);
251  obsOdo_ptr->sensorLabel = "ODOMETRY";
252 
253  out_observations.push_back(obsOdo_ptr);
254  }
255 
256  // Send out laser observation:
257  out_observations.push_back(obsLaser_ptr);
258 
259  } // end RAWLASER
260  else if (strStartsI(line, "PARAM "))
261  {
262  // PARAM message
263  // ---------------------------
264  std::istringstream S; // Read from the string as if it was a stream
265  S.str(line);
266 
267  string key, val;
268  S >> key; // This is "PARAM"
269 
270  if (!(S >> key >> val))
272  "Error parsing line from CARMEN log (PARAM):\n'%s'\n",
273  line.c_str())
274 
275  if (!key.empty() && !val.empty())
276 
277  global_log_params[lowerCase(key)] = val;
278 
279  } // end RAWLASER
280 
281  return true; // OK
282 }
static std::string & trim(std::string &s)
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
float maxRange
The maximum range allowed by the device, in meters (e.g.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
std::shared_ptr< CObservation2DRangeScan > Ptr
void resizeScan(const size_t len)
Resizes all data vectors to allocate a given number of scan rays.
void setScanRangeValidity(const size_t i, const bool val)
mrpt::containers::ContainerReadOnlyProxyAccessor< mrpt::aligned_std_vector< float > > scan
The range values of the scan, in meters.
void setScanRange(const size_t i, const float val)
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
Definition: CObservation.h:62
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
Definition: CObservation.h:60
std::shared_ptr< CObservationOdometry > Ptr
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:87
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43
GLsizei range
Definition: glext.h:5907
bool carmen_log_parse_line(std::istream &in_stream, std::vector< mrpt::obs::CObservation::Ptr > &out_imported_observations, const mrpt::system::TTimeStamp &time_start_log)
Parse one line from an text input stream and interpret it as a CARMEN log entry, returning its MRPT o...
bool strStartsI(const std::string &str, const std::string &subStr)
Return true if "str" starts with "subStr" (case insensitive)
std::string lowerCase(const std::string &str)
Returns an lower-case version of a string.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:40
int val
Definition: mrpt_jpeglib.h:955
This namespace contains representation of robot actions and observations.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double DEG2RAD(const double x)
Degrees to radians.
unsigned __int64 uint64_t
Definition: rptypes.h:50
Lightweight 2D pose.
double phi
Orientation (rads)
double x
X,Y coordinates.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
Definition: TParameters.h:55



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST