g2o
Loading...
Searching...
No Matches
targetTypes6D.hpp
Go to the documentation of this file.
1#ifndef G2O_TARGET_TYPES_6D_HPP_
2#define G2O_TARGET_TYPES_6D_HPP_
3
7
8#include <Eigen/Core>
9#include <cassert>
10
11using namespace g2o;
12
13typedef Eigen::Matrix<double, 6, 1> Vector6d;
14typedef Eigen::Matrix<double, 6, 6> Matrix6d;
15
16// This header file specifies a set of types for the different
17// tracking examples; note that
18
19class VertexPosition3D : public g2o::BaseVertex<3, Eigen::Vector3d> {
20 public:
21 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23
24 virtual void setToOriginImpl() { _estimate.setZero(); }
25
26 virtual void oplusImpl(const double* update) {
27 _estimate[0] += update[0];
28 _estimate[1] += update[1];
29 _estimate[2] += update[2];
30 }
31
32 virtual bool read(std::istream& /*is*/) { return false; }
33
34 virtual bool write(std::ostream& /*os*/) const { return false; }
35};
36
38
39class VertexPositionVelocity3D : public g2o::BaseVertex<6, Vector6d> {
40 public:
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43
44 virtual void setToOriginImpl() { _estimate.setZero(); }
45
46 virtual void oplusImpl(const double* update) {
47 for (int k = 0; k < 6; k++) _estimate[k] += update[k];
48 }
49
50 virtual bool read(std::istream& /*is*/) { return false; }
51
52 virtual bool write(std::ostream& /*os*/) const { return false; }
53};
54
55// The odometry which links pairs of nodes together
57 : public g2o::BaseBinaryEdge<6, Eigen::Vector3d, VertexPositionVelocity3D,
58 VertexPositionVelocity3D> {
59 public:
60 TargetOdometry3DEdge(double dt, double noiseSigma) {
61 _dt = dt;
62
63 double q = noiseSigma * noiseSigma;
64 double dt2 = dt * dt;
65
66 // Process noise covariance matrix; this assumes an "impulse"
67 // noise model; we add a small stabilising term on the diagonal to make it
68 // invertible
69 Matrix6d Q = Matrix6d::Zero();
70 Q(0, 0) = Q(1, 1) = Q(2, 2) = dt2 * dt2 * q / 4 + 1e-4;
71 Q(0, 3) = Q(1, 4) = Q(2, 5) = dt * dt2 * q / 2;
72 Q(3, 3) = Q(4, 4) = Q(5, 5) = dt2 * q + 1e-4;
73 Q(3, 0) = Q(4, 1) = Q(5, 2) = dt * dt2 * q / 2;
74
75 setInformation(Q.inverse());
76 }
77
82 assert(from.size() == 1);
83 const VertexPositionVelocity3D* vi =
84 static_cast<const VertexPositionVelocity3D*>(*from.begin());
86 Vector6d viEst = vi->estimate();
87 Vector6d vjEst = viEst;
88
89 for (int m = 0; m < 3; m++) {
90 vjEst[m] += _dt * (vjEst[m + 3] + 0.5 * _dt * _measurement[m]);
91 }
92
93 for (int m = 0; m < 3; m++) {
94 vjEst[m + 3] += _dt * _measurement[m];
95 }
96 vj->setEstimate(vjEst);
97 }
98
104 // only works on sequential vertices
105 const VertexPositionVelocity3D* vi =
106 static_cast<const VertexPositionVelocity3D*>(*from.begin());
107 return (to->id() - vi->id() == 1) ? 1.0 : -1.0;
108 }
109
111 const VertexPositionVelocity3D* vi =
112 static_cast<const VertexPositionVelocity3D*>(_vertices[0]);
113 const VertexPositionVelocity3D* vj =
114 static_cast<const VertexPositionVelocity3D*>(_vertices[1]);
115
116 for (int k = 0; k < 3; k++) {
117 _error[k] = vi->estimate()[k] +
118 _dt * (vi->estimate()[k + 3] + 0.5 * _dt * _measurement[k]) -
119 vj->estimate()[k];
120 }
121 for (int k = 3; k < 6; k++) {
122 _error[k] =
123 vi->estimate()[k] + _dt * _measurement[k - 3] - vj->estimate()[k];
124 }
125 }
126
127 virtual bool read(std::istream& /*is*/) { return false; }
128
129 virtual bool write(std::ostream& /*os*/) const { return false; }
130
131 private:
132 double _dt;
133};
134
135// The GPS
137 : public g2o::BaseUnaryEdge<3, Eigen::Vector3d, VertexPositionVelocity3D> {
138 public:
140 double noiseSigma) {
142 setInformation(Eigen::Matrix3d::Identity() / (noiseSigma * noiseSigma));
143 }
144
146 const VertexPositionVelocity3D* v =
147 static_cast<const VertexPositionVelocity3D*>(_vertices[0]);
148 for (int k = 0; k < 3; k++) {
149 _error[k] = v->estimate()[k] - _measurement[k];
150 }
151 }
152
153 virtual bool read(std::istream& /*is*/) { return false; }
154
155 virtual bool write(std::ostream& /*os*/) const { return false; }
156};
157
158#endif // __TARGET_TYPES_6D_HPP__
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool write(std::ostream &) const
write the vertex to a stream
GPSObservationEdgePositionVelocity3D(const Eigen::Vector3d &measurement, double noiseSigma)
TargetOdometry3DEdge(double dt, double noiseSigma)
virtual double initialEstimatePossible(const g2o::OptimizableGraph::VertexSet &from, g2o::OptimizableGraph::Vertex *to)
virtual bool write(std::ostream &) const
write the vertex to a stream
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
virtual void initialEstimate(const g2o::OptimizableGraph::VertexSet &from, g2o::OptimizableGraph::Vertex *to)
virtual void oplusImpl(const double *update)
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
virtual bool write(std::ostream &) const
write the vertex to a stream
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexPosition3D()
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool write(std::ostream &) const
write the vertex to a stream
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexPositionVelocity3D()
virtual void oplusImpl(const double *update)
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition base_edge.h:119
virtual void setMeasurement(const Measurement &m)
Definition base_edge.h:122
void setInformation(const InformationType &information)
Definition base_edge.h:111
Measurement _measurement
the measurement of the edge
Definition base_edge.h:146
ErrorVector _error
Definition base_edge.h:149
Templatized BaseVertex.
Definition base_vertex.h:51
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
VertexContainer _vertices
int id() const
returns the id
std::set< Vertex * > VertexSet
A general case Vertex for optimization.
Eigen::Matrix< double, 6, 1 > Vector6d
Eigen::Matrix< double, 6, 6 > Matrix6d