g2o
targetTypes6D.hpp
Go to the documentation of this file.
1 #ifndef G2O_TARGET_TYPES_6D_HPP_
2 #define G2O_TARGET_TYPES_6D_HPP_
3 
4 #include <g2o/core/base_vertex.h>
7 #include <Eigen/Core>
8 
9 using namespace g2o;
10 
11 typedef Eigen::Matrix<double,6,1> Vector6d;
12 typedef Eigen::Matrix<double,6,6> Matrix6d;
13 
14 // This header file specifies a set of types for the different
15 // tracking examples; note that
16 
17 class VertexPosition3D : public g2o::BaseVertex<3, Eigen::Vector3d>
18 {
19 public:
20  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
22  {
23  }
24 
25  virtual void setToOriginImpl() {
26  _estimate.setZero();
27  }
28 
29  virtual void oplusImpl(const double* update)
30  {
31  _estimate[0] += update[0];
32  _estimate[1] += update[1];
33  _estimate[2] += update[2];
34  }
35 
36  virtual bool read(std::istream& /*is*/)
37  {
38  return false;
39  }
40 
41  virtual bool write(std::ostream& /*os*/) const
42  {
43  return false;
44  }
45 
46 };
47 
49 {
50 };
51 
52 class VertexPositionVelocity3D : public g2o::BaseVertex<6, Vector6d>
53 {
54 public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
57  {
58  }
59 
60  virtual void setToOriginImpl() {
61  _estimate.setZero();
62  }
63 
64  virtual void oplusImpl(const double* update)
65  {
66  for (int k = 0; k < 6; k++)
67  _estimate[k] += update[k];
68  }
69 
70 
71  virtual bool read(std::istream& /*is*/)
72  {
73  return false;
74  }
75 
76  virtual bool write(std::ostream& /*os*/) const
77  {
78  return false;
79  }
80 
81 };
82 
83 // The odometry which links pairs of nodes together
84 class TargetOdometry3DEdge : public g2o::BaseBinaryEdge<6, Eigen::Vector3d, VertexPositionVelocity3D, VertexPositionVelocity3D>
85 {
86 public:
87  TargetOdometry3DEdge(double dt, double noiseSigma)
88  {
89  _dt = dt;
90 
91  double q = noiseSigma * noiseSigma;
92  double dt2 = dt * dt;
93 
94  // Process noise covariance matrix; this assumes an "impulse"
95  // noise model; we add a small stabilising term on the diagonal to make it invertible
96  Matrix6d Q=Matrix6d::Zero();
97  Q(0, 0) = Q(1,1) = Q(2,2) = dt2*dt2*q/4 + 1e-4;
98  Q(0, 3) = Q(1, 4) = Q(2, 5) = dt*dt2*q/2;
99  Q(3, 3) = Q(4,4) = Q(5,5) = dt2 * q + 1e-4;
100  Q(3, 0) = Q(4, 1) = Q(5, 2) = dt*dt2*q/2;
101 
102  setInformation(Q.inverse());
103  }
104 
107  assert(from.size() == 1);
108  const VertexPositionVelocity3D* vi = static_cast<const VertexPositionVelocity3D*>(*from.begin());
109  VertexPositionVelocity3D* vj = static_cast<VertexPositionVelocity3D*>(to);
110  Vector6d viEst=vi->estimate();
111  Vector6d vjEst=viEst;
112 
113  for (int m = 0; m < 3; m++)
114  {
115  vjEst[m] += _dt * (vjEst[m+3] + 0.5 * _dt * _measurement[m]);
116  }
117 
118  for (int m = 0; m < 3; m++)
119  {
120  vjEst[m+3] += _dt * _measurement[m];
121  }
122  vj->setEstimate(vjEst);
123  }
124 
127  //only works on sequential vertices
128  const VertexPositionVelocity3D* vi = static_cast<const VertexPositionVelocity3D*>(*from.begin());
129  return (to->id() - vi->id() == 1) ? 1.0 : -1.0;
130  }
131 
132 
134  {
135  const VertexPositionVelocity3D* vi = static_cast<const VertexPositionVelocity3D*>(_vertices[0]);
136  const VertexPositionVelocity3D* vj = static_cast<const VertexPositionVelocity3D*>(_vertices[1]);
137 
138  for (int k = 0; k < 3; k++)
139  {
140  _error[k] = vi->estimate()[k] + _dt * (vi->estimate()[k+3] + 0.5 * _dt * _measurement[k]) - vj->estimate()[k];
141  }
142  for (int k = 3; k < 6; k++)
143  {
144  _error[k] = vi->estimate()[k] + _dt * _measurement[k-3]- vj->estimate()[k];
145  }
146  }
147 
148  virtual bool read(std::istream& /*is*/)
149  {
150  return false;
151  }
152 
153  virtual bool write(std::ostream& /*os*/) const
154  {
155  return false;
156  }
157 
158 private:
159  double _dt;
160 };
161 
162 // The GPS
163 class GPSObservationEdgePositionVelocity3D : public g2o::BaseUnaryEdge<3, Eigen::Vector3d, VertexPositionVelocity3D>
164 {
165 public:
166  GPSObservationEdgePositionVelocity3D(const Eigen::Vector3d& measurement, double noiseSigma)
167  {
168  setMeasurement(measurement);
169  setInformation(Eigen::Matrix3d::Identity() / (noiseSigma*noiseSigma));
170  }
171 
173  {
174  const VertexPositionVelocity3D* v = static_cast<const VertexPositionVelocity3D*>(_vertices[0]);
175  for (int k = 0; k < 3; k++)
176  {
177  _error[k] = v->estimate()[k] - _measurement[k];
178  }
179  }
180 
181  virtual bool read(std::istream& /*is*/)
182  {
183  return false;
184  }
185 
186  virtual bool write(std::ostream& /*os*/) const
187  {
188  return false;
189  }
190 };
191 
192 
193 #endif // __TARGET_TYPES_6D_HPP__
int id() const
returns the id
Definition: hyper_graph.h:148
virtual void oplusImpl(const double *update)
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
Eigen::Matrix< double, 6, 6, Eigen::ColMajor > Matrix6d
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexPosition3D()
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
virtual void oplusImpl(const double *update)
Templatized BaseVertex.
Definition: base_vertex.h:50
virtual bool write(std::ostream &) const
write the vertex to a stream
TargetOdometry3DEdge(double dt, double noiseSigma)
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)
Eigen::Matrix< double, 6, 6 > Matrix6d
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 bool write(std::ostream &) const
write the vertex to a stream
virtual double initialEstimatePossible(const g2o::OptimizableGraph::VertexSet &from, g2o::OptimizableGraph::Vertex *to)
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
virtual void initialEstimate(const g2o::OptimizableGraph::VertexSet &from, g2o::OptimizableGraph::Vertex *to)
A general case Vertex for optimization.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexPositionVelocity3D()
GPSObservationEdgePositionVelocity3D(const Eigen::Vector3d &measurement, double noiseSigma)
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
Eigen::Matrix< double, 6, 1 > Vector6d
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
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75