gtsam
Loading...
Searching...
No Matches
NavState.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
18
19#pragma once
20
21#include <gtsam/base/Manifold.h>
23#include <gtsam/base/Vector.h>
27
28#if GTSAM_ENABLE_BOOST_SERIALIZATION
29#include <boost/serialization/base_object.hpp>
30#endif
31
32namespace gtsam {
33
35using Velocity3 = Vector3;
36
45class GTSAM_EXPORT NavState : public ExtendedPose3<2, NavState> {
46public:
47 using Base = ExtendedPose3<2, NavState>;
48 using LieAlgebra = Matrix5;
49 using Vector25 = Eigen::Matrix<double, 25, 1>;
50 inline constexpr static auto dimension = 9;
51
54
56 NavState() : Base() {}
57
58 NavState(const Base& other) : Base(other) {}
59
61 NavState(const Rot3& R, const Point3& t, const Velocity3& v)
62 : Base(R, Matrix32{{t.x(), v.x()}, {t.y(), v.y()}, {t.z(), v.z()}}) {}
63
65 NavState(const Pose3& pose, const Velocity3& v)
66 : NavState(pose.rotation(), pose.translation(), v) {}
67
69 NavState(const Matrix3& R, const Vector6& tv)
70 : NavState(Rot3(R), tv.head<3>(), tv.tail<3>()) {}
71
73 NavState(const Matrix5& T) : Base(T) {}
74
76 static NavState Create(const Rot3& R, const Point3& t, const Velocity3& v,
78 OptionalJacobian<9, 3> H2 = {},
80
82 static NavState FromPoseVelocity(const Pose3& pose, const Vector3& vel,
85
89
90 const Rot3& attitude(OptionalJacobian<3, 9> H = {}) const;
91 Point3 position(OptionalJacobian<3, 9> H = {}) const;
92 Velocity3 velocity(OptionalJacobian<3, 9> H = {}) const;
93
94 const Pose3 pose() const {
95 return Pose3(attitude(), position());
96 }
97
103 double range(const Point3& point, OptionalJacobian<1, 9> Hself = {},
104 OptionalJacobian<1, 3> Hpoint = {}) const;
105
111 Unit3 bearing(const Point3& point, OptionalJacobian<2, 9> Hself = {},
112 OptionalJacobian<2, 3> Hpoint = {}) const;
113
117
119 Matrix3 R() const {
120 return R_.matrix();
121 }
122
123 Quaternion quaternion() const {
124 return R_.toQuaternion();
125 }
126
127 Vector3 t() const {
128 return t_.col(0);
129 }
130
131 Vector3 v() const {
132 return velocity();
133 }
134 // Return velocity in body frame
135 Velocity3 bodyVelocity(OptionalJacobian<3, 9> H = {}) const;
136
140
142 GTSAM_EXPORT
143 friend std::ostream &operator<<(std::ostream &os, const NavState& state);
144
146 void print(const std::string& s = "") const;
147
149 bool equals(const NavState& other, double tol = 1e-8) const;
150
154
156 const Rot3& rotation(OptionalJacobian<3, 9> H = {}) const {
157 return attitude(H);
158 };
159
160 // Tangent space sugar.
161 // TODO(frank): move to private navstate namespace in cpp
162 static Eigen::Block<Vector9, 3, 1> dR(Vector9& v) {
163 return v.segment<3>(0);
164 }
165 static Eigen::Block<Vector9, 3, 1> dP(Vector9& v) {
166 return v.segment<3>(3);
167 }
168 static Eigen::Block<Vector9, 3, 1> dV(Vector9& v) {
169 return v.segment<3>(6);
170 }
171 static Eigen::Block<const Vector9, 3, 1> dR(const Vector9& v) {
172 return v.segment<3>(0);
173 }
174 static Eigen::Block<const Vector9, 3, 1> dP(const Vector9& v) {
175 return v.segment<3>(3);
176 }
177 static Eigen::Block<const Vector9, 3, 1> dV(const Vector9& v) {
178 return v.segment<3>(6);
179 }
180
186 NavState retract(const Vector9& v, //
188 {}) const;
189
191 Vector9 localCoordinates(const NavState& g, //
193 {}) const;
194
198
202
203 // φ: autonomous flow where velocity acts on position for
204 // dt (R, p, v) -> p += v·dt.
206 double dt;
207
208 // Differential at identity: Φ = I with ∂p/∂v = dt·I.
209 Jacobian dIdentity() const {
210 Jacobian Phi = I_9x9;
211 Phi.template block<3, 3>(3, 6) = I_3x3 * dt;
212 return Phi;
213 }
214
215 // Apply φ(x) by p += v·dt
216 NavState operator()(const NavState& X) const {
217 return {X.attitude(), X.position() + X.velocity() * dt, X.velocity()};
218 }
219 };
220
223 NavState update(const Vector3& b_acceleration, const Vector3& b_omega,
224 const double dt, OptionalJacobian<9, 9> F = {},
226 OptionalJacobian<9, 3> G2 = {}) const;
227
228#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
234 Vector9 coriolis(double dt, const Vector3& omega, bool secondOrder = false,
235 OptionalJacobian<9, 9> H = {}) const;
236
242 Vector9 correctPIM(const Vector9& pim, double dt, const Vector3& n_gravity,
243 const std::optional<Vector3>& omegaCoriolis,
244 bool use2ndOrderCoriolis = false,
247 OptionalJacobian<9, 3> H3 = {}) const;
248#endif
249
251
252private:
253 friend class PreintegrationBase;
254
255 // Return the predicted state directly, avoiding a local/retract round-trip.
256 NavState predictPIM(const Vector9& pim, double dt,
257 const Vector3& n_gravity,
258 const std::optional<Vector3>& omegaCoriolis,
261 OptionalJacobian<9, 3> H3 = {}) const;
262
265#if GTSAM_ENABLE_BOOST_SERIALIZATION
266 friend class boost::serialization::access;
267 template<class ARCHIVE>
268 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
269 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
270 }
271#endif
273};
274
275namespace internal {
276
278GTSAM_EXPORT NavState navStateComponentWiseRetract(
279 const NavState& state, const Vector9& v,
280 OptionalJacobian<9, 9> H1 = {}, OptionalJacobian<9, 9> H2 = {});
281
283GTSAM_EXPORT Vector9 navStateComponentWiseLocalCoordinates(
284 const NavState& state, const NavState& other,
285 OptionalJacobian<9, 9> H1 = {}, OptionalJacobian<9, 9> H2 = {});
286
287} // namespace internal
288
289// Specialize NavState traits to use the configured optimization chart.
290template <>
291struct traits<NavState> : public internal::MatrixLieGroup<NavState, 5> {};
292
293template <>
294struct traits<const NavState> : public internal::MatrixLieGroup<NavState, 5> {};
295
296// bearing and range traits, used in RangeFactor and BearingFactor
297template <>
298struct Bearing<NavState, Point3> : HasBearing<NavState, Point3, Unit3> {};
299
300template <>
301struct Range<NavState, Point3> : HasRange<NavState, Point3, double> {};
302
303} // namespace gtsam
Macros for Matrix constants to avoid excessive template instantiation.
Base class and basic functions for Manifold types.
typedef and functions to augment Eigen's VectorXd
Extended pose Lie group SE_k(3), with static or dynamic k.
3D Pose manifold SO(3) x R^3 and group SE(3)
Bearing-Range product.
GTSAM_EXPORT Vector9 navStateComponentWiseLocalCoordinates(const NavState &state, const NavState &other, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={})
Component-wise NavState local coordinates independent of optimization.
Definition NavState.cpp:181
GTSAM_EXPORT NavState navStateComponentWiseRetract(const NavState &state, const Vector9 &v, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={})
Component-wise NavState retraction independent of the optimization chart.
Definition NavState.cpp:147
Global functions in a separate testing namespace.
Definition chartTesting.h:28
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Both LieGroupTraits and Testable.
Definition MatrixLieGroup.h:350
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
Definition BearingRange.h:36
Definition BearingRange.h:42
Definition BearingRange.h:182
Definition BearingRange.h:196
Rot3 R_
Definition ExtendedPose3.h:80
Matrix3K t_
Definition ExtendedPose3.h:81
ExtendedPose3()
Definition ExtendedPose3.h:99
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65
Represents a 3D point on a unit sphere.
Definition Unit3.h:44
Navigation state: Pose (rotation, translation) + velocity Following Barrau20icra, this class belongs ...
Definition NavState.h:45
NavState()
Default constructor.
Definition NavState.h:56
NavState(const Matrix5 &T)
Construct from Matrix5.
Definition NavState.h:73
NavState(const Matrix3 &R, const Vector6 &tv)
Construct from SO(3) and R^6.
Definition NavState.h:69
NavState(const Rot3 &R, const Point3 &t, const Velocity3 &v)
Construct from attitude, position, velocity.
Definition NavState.h:61
Matrix3 R() const
Return rotation matrix. Induces computation in quaternion mode.
Definition NavState.h:119
NavState(const Pose3 &pose, const Velocity3 &v)
Construct from pose and velocity.
Definition NavState.h:65
Vector3 t() const
Return position as Vector3.
Definition NavState.h:127
Vector3 v() const
Return velocity as Vector3.
Definition NavState.h:131
Quaternion quaternion() const
Return quaternion. Induces computation in matrix mode.
Definition NavState.h:123
const Rot3 & rotation(OptionalJacobian< 3, 9 > H={}) const
Syntactic sugar.
Definition NavState.h:156
NavState update(const Vector3 &b_acceleration, const Vector3 &b_omega, const double dt, OptionalJacobian< 9, 9 > F={}, OptionalJacobian< 9, 3 > G1={}, OptionalJacobian< 9, 3 > G2={}) const
Integrate forward in time given angular velocity and acceleration in body frame.
Definition NavState.cpp:223
Definition NavState.h:205
PreintegrationBase is the base class for PreintegratedMeasurements (in ImuFactor) and CombinedPreinte...
Definition PreintegrationBase.h:45