g2o
Loading...
Searching...
No Matches
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#include "g2o/stuff/logger.h"
32
33using namespace std;
34
35namespace g2o {
36
38 : RobotData(),
39 _laserParams(0, 180, -const_pi() / 2, const_pi() / 180, 50, cst(0.1), 0) {
40}
41
43
44bool RawLaser::write(std::ostream& /*os*/) const {
45 // TODO(Rainer): implement writing of raw laser
46 G2O_ERROR("RawLaser::write() not implemented yet.");
47 return false;
48}
49
50bool RawLaser::read(std::istream& is) {
51 int type;
52 double angle, fov, res, maxrange, acc;
53 int remission_mode;
54 is >> type >> angle >> fov >> res >> maxrange >> acc >> remission_mode;
55
56 int beams;
57 is >> beams;
59 LaserParameters(type, beams, angle, res, maxrange, acc, remission_mode);
60 _ranges.resize(beams);
61 for (int i = 0; i < beams; i++) is >> _ranges[i];
62
63 is >> beams;
64 _remissions.resize(beams);
65 for (int i = 0; i < beams; i++) is >> _remissions[i];
66
67 // timestamp + host
68 is >> _timestamp;
69 is >> _hostname;
70 is >> _loggerTimestamp;
71 return true;
72}
73
74void RawLaser::setRanges(const vector<double>& ranges) { _ranges = ranges; }
75
76void RawLaser::setRemissions(const std::vector<double>& remissions) {
78}
79
83
85 Point2DVector points;
86 for (size_t i = 0; i < _ranges.size(); ++i) {
87 const double& r = _ranges[i];
88 if (r < _laserParams.maxRange && r > _laserParams.minRange) {
90 points.push_back(Vector2(std::cos(alpha) * r, std::sin(alpha) * r));
91 }
92 }
93 return points;
94}
95
96} // namespace g2o
const std::vector< double > & ranges() const
the range measurements by the laser
Definition raw_laser.h:63
std::vector< double > _remissions
Definition raw_laser.h:76
std::vector< double > _ranges
Definition raw_laser.h:75
void setLaserParams(const LaserParameters &laserParams)
Definition raw_laser.cpp:80
const LaserParameters & laserParams() const
the parameters of the laser
Definition raw_laser.h:71
Point2DVector cartesian() const
Definition raw_laser.cpp:84
void setRanges(const std::vector< double > &ranges)
Definition raw_laser.cpp:74
void setRemissions(const std::vector< double > &remissions)
Definition raw_laser.cpp:76
virtual bool read(std::istream &is)
read the data from a stream
Definition raw_laser.cpp:50
LaserParameters _laserParams
Definition raw_laser.h:77
std::vector< Vector2 > Point2DVector
Definition raw_laser.h:47
virtual bool write(std::ostream &os) const
write the data to a stream
Definition raw_laser.cpp:44
const std::vector< double > & remissions() const
the remission measurements by the laser
Definition raw_laser.h:67
data recorded by the robot
Definition robot_data.h:41
double _loggerTimestamp
timestamp when the measurement was recorded
Definition robot_data.h:60
std::string _hostname
name of the computer/robot generating the data
Definition robot_data.h:63
double _timestamp
timestamp when the measurement was generated
Definition robot_data.h:59
#define G2O_ERROR(...)
Definition logger.h:89
constexpr double cst(long double v)
Definition misc.h:60
VectorN< 2 > Vector2
Definition eigen_types.h:50
constexpr double const_pi()
Definition misc.h:62
Definition jet.h:876
parameters for a 2D range finder