sensorstream.cpp
Go to the documentation of this file.
1 #include <assert.h>
2 #include <sstream>
4 //#define LINEBUFFER_SIZE 1000000 //for not Cyrill to unbless me, it is better to exagerate :-))
5 // Can't declare a buffer that big on the stack. So we'll risk Cyrill's
6 // unblessing, and make it smaller.
7 #define LINEBUFFER_SIZE 8192
8 
9 namespace GMapping {
10 
11 using namespace std;
12 
13 //SensorStream
14 SensorStream::SensorStream(const SensorMap& sensorMap) :m_sensorMap(sensorMap){}
15 
17 
19  SensorReading* reading=0;
20  if (is){
21  char buf[LINEBUFFER_SIZE];
22  is.getline(buf, LINEBUFFER_SIZE);
23  istringstream lis(buf);
24 
25  string sensorname;
26 
27  if (lis){
28  lis >>sensorname;
29  } else
30  return 0;
31 
32  SensorMap::const_iterator it=smap.find(sensorname);
33  if (it==smap.end()){
34  return 0;
35  }
36 
37  Sensor* sensor=it->second;
38 
39  OdometrySensor* odometry=dynamic_cast<OdometrySensor*>(sensor);
40  if (odometry)
41  reading=parseOdometry(lis, odometry);
42 
43  RangeSensor* range=dynamic_cast<RangeSensor*>(sensor);
44  if (range)
45  reading=parseRange(lis, range);
46  }
47  return reading;
48 }
49 
51  OdometryReading* reading=new OdometryReading(osen);
52  OrientedPoint pose;
53  OrientedPoint speed;
54  OrientedPoint accel;
55  is >> pose.x >> pose.y >> pose.theta;
56  is >> speed.x >>speed.theta;
57  speed.y=0;
58  is >> accel.x;
59  accel.y=accel.theta=0;
60  reading->setPose(pose); reading->setSpeed(speed); reading->setAcceleration(accel);
61  double timestamp, reltimestamp;
62  string s;
63  is >> timestamp >>s >> reltimestamp;
64  reading->setTime(timestamp);
65  return reading;
66 }
67 
69  //cerr << __func__ << endl;
70  if(rs->newFormat){
71  string laser_type, start_angle, field_of_view, angular_resolution, maximum_range, accuracy, remission_mode;
72  is >> laser_type>> start_angle>> field_of_view>> angular_resolution>> maximum_range>> accuracy>> remission_mode;
73  //cerr << " New format laser msg" << endl;
74  }
75  unsigned int size;
76  is >> size;
77  assert(size==rs->beams().size());
78  RangeReading* reading=new RangeReading(rs);
79  reading->resize(size);
80  for (unsigned int i=0; i<size; i++){
81  is >> (*reading)[i];
82  }
83  if (rs->newFormat){
84  int reflectionBeams;
85  is >> reflectionBeams;
86  double reflection;
87  for (int i=0; i<reflectionBeams; i++)
88  is >> reflection;
89  }
90  OrientedPoint laserPose;
91  is >> laserPose.x >> laserPose.y >> laserPose.theta;
92  OrientedPoint pose;
93  is >> pose.x >> pose.y >> pose.theta;
94  reading->setPose(pose);
95 
96  if (rs->newFormat){
97  string laser_tv, laser_rv, forward_safety_dist, side_safty_dist, turn_axis;
98  is >> laser_tv >> laser_rv >> forward_safety_dist >> side_safty_dist >> turn_axis;
99  }
100 // else {
101 // double a,b,c;
102 // is >> a >> b >> c;
103 // }
104  double timestamp, reltimestamp;
105  string s;
106  is >> timestamp >>s >> reltimestamp;
107  reading->setTime(timestamp);
108  return reading;
109 
110 }
111 
112 //LogSensorStream
114  SensorStream(sensorMap){
115  m_log=log;
116  assert(m_log);
117  m_cursor=log->begin();
118 }
119 
120 LogSensorStream::operator bool() const{
121  return m_cursor==m_log->end();
122 }
123 
125  m_cursor=m_log->begin();
126  return true;
127 }
128 
130  rd=*m_cursor;
131  m_cursor++;
132  return *this;
133 }
134 
135 //InputSensorStream
136 InputSensorStream::InputSensorStream(const SensorMap& sensorMap, std::istream& is):
137  SensorStream(sensorMap), m_inputStream(is){
138 }
139 
140 InputSensorStream::operator bool() const{
141  return (bool) m_inputStream;
142 }
143 
145  //m_inputStream.rewind();
146  return false;
147 }
148 
151  return *this;
152 }
153 
154 };
155 
GMapping::RangeReading::setPose
void setPose(const OrientedPoint &pose)
Definition: rangereading.h:23
GMapping::SensorMap
std::map< std::string, Sensor * > SensorMap
Definition: sensor.h:20
GMapping::OdometryReading::setPose
void setPose(const OrientedPoint &pose)
Definition: odometryreading.h:18
GMapping::LogSensorStream::LogSensorStream
LogSensorStream(const SensorMap &sensorMap, const SensorLog *log)
Definition: sensorstream.cpp:113
sensorstream.h
is
ifstream is(argv[c])
GMapping
Definition: configfile.cpp:34
GMapping::LogSensorStream::m_log
const SensorLog * m_log
Definition: sensorstream.h:43
GMapping::RangeSensor::beams
const std::vector< Beam > & beams() const
Definition: rangesensor.h:24
GMapping::SensorStream::m_sensorMap
const SensorMap & m_sensorMap
Definition: sensorstream.h:18
GMapping::SensorReading::setTime
void setTime(double t)
Definition: sensorreading.h:14
GMapping::RangeSensor
Definition: rangesensor.h:11
GMapping::OdometryReading
Definition: odometryreading.h:12
GMapping::InputSensorStream::operator>>
virtual SensorStream & operator>>(const SensorReading *&)
Definition: sensorstream.cpp:149
LINEBUFFER_SIZE
#define LINEBUFFER_SIZE
Definition: sensorstream.cpp:7
GMapping::point::y
T y
Definition: point.h:16
GMapping::SensorStream::parseRange
static RangeReading * parseRange(std::istream &is, const RangeSensor *)
Definition: sensorstream.cpp:68
GMapping::Sensor
Definition: sensor.h:10
GMapping::orientedpoint::theta
A theta
Definition: point.h:60
GMapping::SensorStream::~SensorStream
virtual ~SensorStream()
Definition: sensorstream.cpp:16
GMapping::OdometryReading::setAcceleration
void setAcceleration(const OrientedPoint &acceleration)
Definition: odometryreading.h:20
GMapping::SensorReading
Definition: sensoreading.h:9
GMapping::LogSensorStream::rewind
virtual bool rewind()
Definition: sensorstream.cpp:124
GMapping::RangeReading
Definition: rangereading.h:17
GMapping::InputSensorStream::m_inputStream
std::istream & m_inputStream
Definition: sensorstream.h:33
GMapping::InputSensorStream::InputSensorStream
InputSensorStream(const SensorMap &sensorMap, std::istream &is)
Definition: sensorstream.cpp:136
GMapping::SensorStream::parseOdometry
static OdometryReading * parseOdometry(std::istream &is, const OdometrySensor *)
Definition: sensorstream.cpp:50
GMapping::LogSensorStream::m_cursor
SensorLog::const_iterator m_cursor
Definition: sensorstream.h:44
GMapping::SensorStream::parseReading
static SensorReading * parseReading(std::istream &is, const SensorMap &smap)
Definition: sensorstream.cpp:18
GMapping::SensorStream::SensorStream
SensorStream(const SensorMap &sensorMap)
Definition: sensorstream.cpp:14
GMapping::SensorStream
Definition: sensorstream.h:9
GMapping::orientedpoint< double, double >
GMapping::SensorLog
Definition: sensorlog.h:16
GMapping::RangeSensor::newFormat
bool newFormat
Definition: rangesensor.h:28
GMapping::InputSensorStream::rewind
virtual bool rewind()
Definition: sensorstream.cpp:144
GMapping::OdometrySensor
Definition: odometrysensor.h:10
GMapping::point::x
T x
Definition: point.h:16
GMapping::LogSensorStream::operator>>
virtual SensorStream & operator>>(const SensorReading *&)
Definition: sensorstream.cpp:129
GMapping::OdometryReading::setSpeed
void setSpeed(const OrientedPoint &speed)
Definition: odometryreading.h:19


openslam_gmapping
Author(s): Cyrill Stachniss, Udo Frese, Giorgio Grisetti, Wolfram Burgard
autogenerated on Thu Oct 19 2023 02:25:51