g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
apps
g2o_simulator
sensor_segment2d_line.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 G. Grisetti, R. Kuemmerle, 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 "
sensor_segment2d_line.h
"
28
29
#include <cassert>
30
31
#include "
g2o/apps/g2o_simulator/simutils.h
"
32
using namespace
std
;
33
using namespace
Eigen
;
34
35
namespace
g2o
{
36
37
SensorSegment2DLine::SensorSegment2DLine
(
const
std::string& name_)
38
:
BinarySensor
<
Robot2D
,
EdgeSE2Segment2DLine
,
WorldObjectSegment2D
>(name_) {
39
}
40
41
void
SensorSegment2DLine::addNoise
(
EdgeType
* e) {
42
EdgeType::ErrorVector n =
_sampler
.generateSample();
43
e->setMeasurement(e->measurement() + n);
44
e->setInformation(
information
());
45
}
46
47
bool
SensorSegment2DLine::isVisible
(
SensorSegment2DLine::WorldObjectType
* to) {
48
if
(!
_robotPoseObject
)
return
false
;
49
50
assert(to && to->vertex());
51
VertexType
* v = to->vertex();
52
53
Vector2d p1, p2;
54
SE2
iRobot =
_robotPoseObject
->vertex()->estimate().inverse();
55
p1 = iRobot * v->
estimateP1
();
56
p2 = iRobot * v->
estimateP2
();
57
58
Vector3d vp1(p1.x(), p1.y(), 0.);
59
Vector3d vp2(p2.x(), p2.y(), 0.);
60
Vector3d cp = vp1.cross(vp2);
// visibility check
61
if
(cp[2] < 0)
return
false
;
62
63
int
circleClip =
clipSegmentCircle
(p1, p2, sqrt(
_maxRange2
));
64
bool
clip1 =
false
, clip2 =
false
;
65
switch
(circleClip) {
66
case
-1:
67
return
false
;
68
case
0:
69
clip1 =
true
;
70
break
;
71
case
1:
72
clip2 =
true
;
73
break
;
74
case
3:
75
clip1 =
true
;
76
clip2 =
true
;
77
break
;
78
default
:;
79
}
80
81
int
fovClip =
clipSegmentFov
(p1, p2, -
_fov
, +
_fov
);
82
switch
(fovClip) {
83
case
-1:
84
return
false
;
85
case
0:
86
clip1 =
true
;
87
break
;
88
case
1:
89
clip2 =
true
;
90
break
;
91
case
3:
92
clip1 =
true
;
93
clip2 =
true
;
94
break
;
95
default
:;
96
}
97
if
(clip1 && clip2)
// only if both endpoints have been clipped do something
98
return
true
;
99
// if all these checks went well, we set the point
100
return
false
;
101
}
102
103
void
SensorSegment2DLine::sense
() {
104
_robotPoseObject
= 0;
105
RobotType
* r =
dynamic_cast<
RobotType
*
>
(
robot
());
106
std::list<PoseObject*>::reverse_iterator it = r->
trajectory
().rbegin();
107
int
count = 0;
108
while
(it != r->
trajectory
().rend() && count < 1) {
109
if
(!
_robotPoseObject
)
_robotPoseObject
= *it;
110
++it;
111
count++;
112
}
113
for
(std::set<BaseWorldObject*>::iterator it =
world
()->objects().begin();
114
it !=
world
()->
objects
().end(); ++it) {
115
WorldObjectType
* o =
dynamic_cast<
WorldObjectType
*
>
(*it);
116
if
(o &&
isVisible
(o)) {
117
EdgeType
* e =
mkEdge
(o);
118
if
(e &&
graph
()) {
119
e->setMeasurementFromState();
120
addNoise
(e);
121
graph
()->
addEdge
(e);
122
}
123
}
124
}
125
}
126
127
}
// namespace g2o
g2o::BaseSensor::graph
OptimizableGraph * graph() const
Definition
simulator.cpp:76
g2o::BaseSensor::world
World * world() const
Definition
simulator.cpp:71
g2o::BaseSensor::robot
BaseRobot * robot()
Definition
simulator.h:162
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::VertexType
WorldObjectType::VertexType VertexType
Definition
simulator.h:244
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::WorldObjectType
WorldObjectSegment2D WorldObjectType
Definition
simulator.h:243
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::mkEdge
EdgeType * mkEdge(WorldObjectType *object)
Definition
simulator.h:290
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::_robotPoseObject
PoseObject * _robotPoseObject
Definition
simulator.h:287
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::information
const InformationType & information()
Definition
simulator.h:256
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::RobotType
Robot2D RobotType
Definition
simulator.h:238
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::_sampler
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition
simulator.h:298
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::BinarySensor
BinarySensor(const std::string &name)
Definition
simulator.h:247
g2o::BinarySensor< Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D >::EdgeType
EdgeSE2Segment2DLine EdgeType
Definition
simulator.h:242
g2o::EdgeSE2Segment2DLine
Definition
edge_se2_segment2d_line.h:42
g2o::PointSensorParameters::_maxRange2
double _maxRange2
Definition
pointsensorparameters.h:52
g2o::PointSensorParameters::_fov
double _fov
Definition
pointsensorparameters.h:52
g2o::Robot::trajectory
TrajectoryType & trajectory()
Definition
simulator.h:151
g2o::SE2
represent SE2
Definition
se2.h:43
g2o::SensorSegment2DLine::SensorSegment2DLine
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SensorSegment2DLine(const std::string &name_)
Definition
sensor_segment2d_line.cpp:37
g2o::SensorSegment2DLine::sense
virtual void sense()
Definition
sensor_segment2d_line.cpp:103
g2o::SensorSegment2DLine::isVisible
bool isVisible(WorldObjectType *to)
Definition
sensor_segment2d_line.cpp:47
g2o::SensorSegment2DLine::addNoise
virtual void addNoise(EdgeType *e)
Definition
sensor_segment2d_line.cpp:41
g2o::VertexSegment2D::estimateP1
Vector2 estimateP1() const
Definition
vertex_segment2d.h:45
g2o::VertexSegment2D::estimateP2
Vector2 estimateP2() const
Definition
vertex_segment2d.h:48
g2o::World::objects
std::set< BaseWorldObject * > & objects()
Definition
simulator.h:115
Eigen
Definition
jet.h:938
g2o
Definition
dl_wrapper.cpp:55
g2o::clipSegmentCircle
int clipSegmentCircle(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double r)
Definition
simutils.cpp:37
g2o::clipSegmentFov
int clipSegmentFov(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double min, double max)
Definition
simutils.cpp:107
g2o::WorldObjectSegment2D
WorldObject< VertexSegment2D > WorldObjectSegment2D
Definition
simulator2d_base.h:40
g2o::Robot2D
Robot< WorldObjectSE2 > Robot2D
Definition
simulator2d_base.h:42
std
Definition
jet.h:876
sensor_segment2d_line.h
simutils.h
g2o::OptimizableGraph::addEdge
virtual bool addEdge(HyperGraph::Edge *e)
Definition
optimizable_graph.cpp:252
Generated on
for g2o by
1.17.0