g2o
raw_laser.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #include "raw_laser.h"
28 
29 #include <iostream>
30 
31 using namespace std;
32 
33 namespace g2o {
34 
35  RawLaser::RawLaser() :
36  RobotData(),
37  _laserParams(0, 180, -M_PI/2, M_PI/180., 50.,0.1, 0)
38  {
39  }
40 
42  {
43  }
44 
45  bool RawLaser::write(std::ostream& /*os*/) const
46  {
47  // TODO
48  cerr << "RawLaser::write() not implemented yet." << endl;
49  return false;
50  }
51 
52  bool RawLaser::read(std::istream& is)
53  {
54  int type;
55  double angle, fov, res, maxrange, acc;
56  int remission_mode;
57  is >> type >> angle >> fov >> res >> maxrange >> acc >> remission_mode;
58 
59  int beams;
60  is >> beams;
61  _laserParams = LaserParameters(type, beams, angle, res, maxrange, acc, remission_mode);
62  _ranges.resize(beams);
63  for (int i=0; i<beams; i++)
64  is >> _ranges[i];
65 
66  is >> beams;
67  _remissions.resize(beams);
68  for (int i=0; i < beams; i++)
69  is >> _remissions[i];
70 
71  // timestamp + host
72  is >> _timestamp;
73  is >> _hostname;
74  is >> _loggerTimestamp;
75  return true;
76  }
77 
78  void RawLaser::setRanges(const vector<double>& ranges)
79  {
80  _ranges = ranges;
81  }
82 
83  void RawLaser::setRemissions(const std::vector<double>& remissions)
84  {
86  }
87 
89  {
91  }
92 
94  {
95  Point2DVector points;
96  for (size_t i = 0; i < _ranges.size(); ++i) {
97  const double& r = _ranges[i];
98  if (r < _laserParams.maxRange) {
100  points.push_back(Vector2D(cos(alpha) * r, sin(alpha) * r));
101  }
102  }
103  return points;
104  }
105 
106 } // end namespace
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
std::string _hostname
name of the computer/robot generating the data
Definition: robot_data.h:63
std::vector< Vector2D, Eigen::aligned_allocator< Vector2D > > Point2DVector
Definition: raw_laser.h:48
virtual bool write(std::ostream &os) const
write the data to a stream
Definition: raw_laser.cpp:45
double _timestamp
timestamp when the measurement was generated
Definition: robot_data.h:60
void setLaserParams(const LaserParameters &laserParams)
Definition: raw_laser.cpp:88
double _loggerTimestamp
timestamp when the measurement was recorded
Definition: robot_data.h:61
std::vector< double > _ranges
Definition: raw_laser.h:76
const std::vector< double > & remissions() const
the remission measurements by the laser
Definition: raw_laser.h:68
void setRanges(const std::vector< double > &ranges)
Definition: raw_laser.cpp:78
const std::vector< double > & ranges() const
the range measurements by the laser
Definition: raw_laser.h:64
const LaserParameters & laserParams() const
the parameters of the laser
Definition: raw_laser.h:72
void setRemissions(const std::vector< double > &remissions)
Definition: raw_laser.cpp:83
LaserParameters _laserParams
Definition: raw_laser.h:78
virtual bool read(std::istream &is)
read the data from a stream
Definition: raw_laser.cpp:52
#define M_PI
Definition: misc.h:34
std::vector< double > _remissions
Definition: raw_laser.h:77
Point2DVector cartesian() const
Definition: raw_laser.cpp:93
data recorded by the robot
Definition: robot_data.h:41
parameters for a 2D range finder