g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
slam2d
edge_se2_offset.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 "
edge_se2_offset.h
"
28
29
#include <cassert>
30
#include <iostream>
31
32
#include "
parameter_se2_offset.h
"
33
34
namespace
g2o
{
35
using namespace
std;
36
37
EdgeSE2Offset::EdgeSE2Offset
()
38
:
BaseBinaryEdge
<3,
SE2
,
VertexSE2
,
VertexSE2
>() {
39
information
().setIdentity();
40
_offsetFrom
= 0;
41
_offsetTo
= 0;
42
_cacheFrom
= 0;
43
_cacheTo
= 0;
44
resizeParameters
(2);
45
installParameter
(
_offsetFrom
, 0);
46
installParameter
(
_offsetTo
, 1);
47
}
48
49
bool
EdgeSE2Offset::resolveCaches
() {
50
assert(
_offsetFrom
&&
_offsetTo
);
51
52
ParameterVector
pv(1);
53
pv[0] =
_offsetFrom
;
54
resolveCache
(
_cacheFrom
, (
OptimizableGraph::Vertex
*)
_vertices
[0],
55
"CACHE_SE2_OFFSET"
, pv);
56
pv[0] =
_offsetTo
;
57
resolveCache
(
_cacheTo
, (
OptimizableGraph::Vertex
*)
_vertices
[1],
58
"CACHE_SE2_OFFSET"
, pv);
59
return
(
_cacheFrom
&&
_cacheTo
);
60
}
61
62
bool
EdgeSE2Offset::read
(std::istream& is) {
63
int
pidFrom, pidTo;
64
is >> pidFrom >> pidTo;
65
if
(!
setParameterId
(0, pidFrom))
return
false
;
66
if
(!
setParameterId
(1, pidTo))
return
false
;
67
68
Vector3
meas;
69
internal::readVector
(is, meas);
70
setMeasurement
(
SE2
(meas));
71
if
(is.bad())
return
false
;
72
readInformationMatrix
(is);
73
if
(is.bad()) {
74
// we overwrite the information matrix with the Identity
75
information
().setIdentity();
76
}
77
return
true
;
78
}
79
80
bool
EdgeSE2Offset::write
(std::ostream& os)
const
{
81
os <<
_offsetFrom
->id() <<
" "
<<
_offsetTo
->id() <<
" "
;
82
internal::writeVector
(os,
measurement
().toVector());
83
return
writeInformationMatrix
(os);
84
}
85
86
void
EdgeSE2Offset::computeError
() {
87
SE2
delta =
_inverseMeasurement
*
_cacheFrom
->w2n() *
_cacheTo
->n2w();
88
_error
.head<2>() = delta.
translation
();
89
_error
(2) = delta.
rotation
().angle();
90
}
91
92
bool
EdgeSE2Offset::setMeasurementFromState
() {
93
SE2
delta =
_cacheFrom
->w2n() *
_cacheTo
->n2w();
94
setMeasurement
(delta);
95
return
true
;
96
}
97
98
void
EdgeSE2Offset::initialEstimate
(
const
OptimizableGraph::VertexSet
& from_,
99
OptimizableGraph::Vertex
*
/*to_*/
) {
100
VertexSE2
* from =
static_cast<
VertexSE2
*
>
(
_vertices
[0]);
101
VertexSE2
* to =
static_cast<
VertexSE2
*
>
(
_vertices
[1]);
102
103
SE2
virtualMeasurement =
_cacheFrom
->offsetParam()->offset() *
measurement
() *
104
_cacheTo
->offsetParam()->offset().inverse();
105
106
if
(from_.count(from) > 0)
107
to->
setEstimate
(from->
estimate
() * virtualMeasurement);
108
else
109
from->
setEstimate
(to->
estimate
() * virtualMeasurement.
inverse
());
110
}
111
112
}
// namespace g2o
g2o::BaseBinaryEdge< 3, SE2, VertexSE2, VertexSE2 >::BaseBinaryEdge
BaseBinaryEdge()
Definition
base_binary_edge.h:41
g2o::BaseEdge< D, SE2 >::writeInformationMatrix
bool writeInformationMatrix(std::ostream &os) const
Definition
base_edge.h:165
g2o::BaseEdge< D, SE2 >::readInformationMatrix
bool readInformationMatrix(std::istream &is)
Definition
base_edge.h:173
g2o::BaseEdge< D, SE2 >::measurement
EIGEN_STRONG_INLINE const Measurement & measurement() const
Definition
base_edge.h:119
g2o::BaseEdge< D, SE2 >::information
EIGEN_STRONG_INLINE const InformationType & information() const
Definition
base_edge.h:107
g2o::BaseEdge< D, SE2 >::_error
ErrorVector _error
Definition
base_edge.h:149
g2o::BaseVertex::estimate
const EstimateType & estimate() const
return the current estimate of the vertex
Definition
base_vertex.h:127
g2o::BaseVertex::setEstimate
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition
base_vertex.h:129
g2o::EdgeSE2Offset::setMeasurementFromState
virtual bool setMeasurementFromState()
Definition
edge_se2_offset.cpp:92
g2o::EdgeSE2Offset::resolveCaches
virtual bool resolveCaches()
Definition
edge_se2_offset.cpp:49
g2o::EdgeSE2Offset::_cacheTo
CacheSE2Offset * _cacheTo
Definition
edge_se2_offset.h:91
g2o::EdgeSE2Offset::_offsetFrom
ParameterSE2Offset * _offsetFrom
Definition
edge_se2_offset.h:90
g2o::EdgeSE2Offset::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
edge_se2_offset.cpp:62
g2o::EdgeSE2Offset::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
edge_se2_offset.cpp:80
g2o::EdgeSE2Offset::_offsetTo
ParameterSE2Offset * _offsetTo
Definition
edge_se2_offset.h:90
g2o::EdgeSE2Offset::_cacheFrom
CacheSE2Offset * _cacheFrom
Definition
edge_se2_offset.h:91
g2o::EdgeSE2Offset::_inverseMeasurement
SE2 _inverseMeasurement
Definition
edge_se2_offset.h:88
g2o::EdgeSE2Offset::EdgeSE2Offset
EdgeSE2Offset()
Definition
edge_se2_offset.cpp:37
g2o::EdgeSE2Offset::initialEstimate
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
Definition
edge_se2_offset.cpp:98
g2o::EdgeSE2Offset::setMeasurement
virtual void setMeasurement(const SE2 &m)
Definition
edge_se2_offset.h:56
g2o::EdgeSE2Offset::computeError
void computeError()
Definition
edge_se2_offset.cpp:86
g2o::HyperGraph::Edge::_vertices
VertexContainer _vertices
Definition
hyper_graph.h:221
g2o::HyperGraph::VertexSet
std::set< Vertex * > VertexSet
Definition
hyper_graph.h:142
g2o::OptimizableGraph::Edge::installParameter
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
Definition
optimizable_graph.h:554
g2o::OptimizableGraph::Edge::resizeParameters
void resizeParameters(size_t newSize)
Definition
optimizable_graph.h:540
g2o::OptimizableGraph::Edge::resolveCache
void resolveCache(CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector ¶meters)
Definition
cache.h:125
g2o::OptimizableGraph::Edge::setParameterId
bool setParameterId(int argNum, int paramId)
Definition
optimizable_graph.cpp:125
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::SE2
represent SE2
Definition
se2.h:43
g2o::SE2::translation
const Vector2 & translation() const
translational component
Definition
se2.h:57
g2o::SE2::inverse
SE2 inverse() const
invert :-)
Definition
se2.h:83
g2o::SE2::rotation
const Rotation2D & rotation() const
rotational component
Definition
se2.h:61
g2o::VertexSE2
2D pose Vertex, (x,y,theta)
Definition
vertex_se2.h:41
edge_se2_offset.h
g2o::internal::writeVector
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:36
g2o::internal::readVector
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:42
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector3
VectorN< 3 > Vector3
Definition
eigen_types.h:51
g2o::ParameterVector
std::vector< Parameter * > ParameterVector
Definition
parameter.h:54
parameter_se2_offset.h
Generated on
for g2o by
1.17.0