gtsam
Loading...
Searching...
No Matches
VelocityConstraint.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
17
18#pragma once
19
20#include <gtsam/config.h>
21
22#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
23
28
29#include <cassert>
30
31namespace gtsam {
32
33namespace dynamics {
34
36typedef enum {
37 TRAPEZOIDAL, // Constant acceleration
38 EULER_START, // Constant velocity, using starting velocity
39 EULER_END // Constant velocity, using ending velocity
40} IntegrationMode;
41
42}
43
53class VelocityConstraint
54 : public gtsam::NoiseModelFactorT<gtsam::Vector3, PoseRTV, PoseRTV> {
55public:
56 typedef gtsam::NoiseModelFactorT<gtsam::Vector3, PoseRTV, PoseRTV> Base;
57
58 // Provide access to the Matrix& version of evaluateError:
59 using Base::evaluateError;
60
61protected:
62
63 double dt_;
64 dynamics::IntegrationMode integration_mode_;
65
66public:
67
71 VelocityConstraint(Key key1, Key key2, const dynamics::IntegrationMode& mode,
72 double dt, double mu = 1000)
73 : Base(noiseModel::Constrained::All(3, mu), key1, key2), dt_(dt), integration_mode_(mode) {}
74
79 VelocityConstraint(Key key1, Key key2, double dt, double mu = 1000)
80 : Base(noiseModel::Constrained::All(3, mu), key1, key2),
81 dt_(dt), integration_mode_(dynamics::TRAPEZOIDAL) {}
82
86 VelocityConstraint(Key key1, Key key2, const dynamics::IntegrationMode& mode,
87 double dt, const gtsam::SharedNoiseModel& model)
88 : Base(model, key1, key2), dt_(dt), integration_mode_(mode) {}
89
94 VelocityConstraint(Key key1, Key key2, double dt, const gtsam::SharedNoiseModel& model)
95 : Base(model, key1, key2), dt_(dt), integration_mode_(dynamics::TRAPEZOIDAL) {}
96
97 ~VelocityConstraint() override {}
98
100 gtsam::NonlinearFactor::shared_ptr clone() const override {
101 return std::static_pointer_cast<gtsam::NonlinearFactor>(
102 gtsam::NonlinearFactor::shared_ptr(new VelocityConstraint(*this))); }
103
107 gtsam::Vector3 evaluateError(const PoseRTV& x1, const PoseRTV& x2,
108 OptionalMatrixType H1,
109 OptionalMatrixType H2) const override {
111 std::bind(VelocityConstraint::evaluateError_, std::placeholders::_1,
112 std::placeholders::_2, dt_, integration_mode_), x1, x2, 1e-5);
114 std::bind(VelocityConstraint::evaluateError_, std::placeholders::_1,
115 std::placeholders::_2, dt_, integration_mode_), x1, x2, 1e-5);
116 return evaluateError_(x1, x2, dt_, integration_mode_);
117 }
118
119 void print(const std::string& s = "", const gtsam::KeyFormatter& formatter = gtsam::DefaultKeyFormatter) const override {
120 std::string a = "VelocityConstraint: " + s;
121 Base::print(a, formatter);
122 switch(integration_mode_) {
123 case dynamics::TRAPEZOIDAL: std::cout << "Integration: Trapezoidal\n"; break;
124 case dynamics::EULER_START: std::cout << "Integration: Euler (start)\n"; break;
125 case dynamics::EULER_END: std::cout << "Integration: Euler (end)\n"; break;
126 default: std::cout << "Integration: Unknown\n" << std::endl; break;
127 }
128 std::cout << "dt: " << dt_ << std::endl;
129 }
130
131private:
132 static gtsam::Vector evaluateError_(const PoseRTV& x1, const PoseRTV& x2,
133 double dt, const dynamics::IntegrationMode& mode) {
134
135 const Velocity3& v1 = x1.v(), v2 = x2.v();
136 const Point3& p1 = x1.t(), p2 = x2.t();
137 Point3 hx(0,0,0);
138 switch(mode) {
139 case dynamics::TRAPEZOIDAL: hx = p1 + Point3((v1 + v2) * dt *0.5); break;
140 case dynamics::EULER_START: hx = p1 + Point3(v1 * dt); break;
141 case dynamics::EULER_END : hx = p1 + Point3(v2 * dt); break;
142 default: assert(false); break;
143 }
144 return p2 - hx;
145 }
146};
147
148} // \namespace gtsam
149
150#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
Numerical derivative helpers for manifold-valued functions.
Base class for noise model factors with N variables.
Non-linear factor base classes.
Pose3 with translational velocity.
State< N >::TangentVector dynamics(const Vector3 &omega, const State< N > &xi)
Continuous-time dynamics on the manifold M = SO(3) x R^3 x SO(3)^N, as in Eq.
Definition ABC.h:251
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2 > >::dimension, N >::type numericalDerivative21(F &&h, const X1 &x1, const X2 &x2, double delta=1e-5)
Compute numerical derivative in argument 1 of binary function.
Definition numericalDerivative.h:236
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2 > >::dimension, N >::type numericalDerivative22(F &&h, const X1 &x1, const X2 &x2, double delta=1e-5)
Compute numerical derivative in argument 2 of binary function.
Definition numericalDerivative.h:265
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
Vector3 Velocity3
Velocity is currently typedef'd to Vector3.
Definition Gal3.h:33
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846