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 
19 #pragma once
20 
21 #include <gtsam/geometry/Pose3.h>
22 #include <gtsam/base/Vector.h>
23 #include <gtsam/base/Manifold.h>
24 
25 namespace gtsam {
26 
29 
38 class GTSAM_EXPORT NavState : public LieGroup<NavState, 9> {
39  private:
40 
41  // TODO(frank):
42  // - should we rename t_ to p_? if not, we should rename dP do dT
43  Rot3 R_;
46 
47 public:
48 
49  inline constexpr static auto dimension = 9;
50 
51 
54 
57  t_(0, 0, 0), v_(Vector3::Zero()) {
58  }
59 
61  NavState(const Rot3& R, const Point3& t, const Velocity3& v) :
62  R_(R), t_(t), v_(v) {
63  }
64 
66  NavState(const Pose3& pose, const Velocity3& v) :
67  R_(pose.rotation()), t_(pose.translation()), v_(v) {
68  }
69 
71  NavState(const Matrix3& R, const Vector6& tv) :
72  R_(R), t_(tv.head<3>()), v_(tv.tail<3>()) {
73  }
74 
76  NavState(const Matrix5& T) :
77  R_(T.block<3, 3>(0, 0)), t_(T.block<3, 1>(0, 3)), v_(T.block<3, 1>(0, 4)) {
78  }
79 
81  static NavState Create(const Rot3& R, const Point3& t, const Velocity3& v,
82  OptionalJacobian<9, 3> H1 = {},
83  OptionalJacobian<9, 3> H2 = {},
84  OptionalJacobian<9, 3> H3 = {});
85 
87  static NavState FromPoseVelocity(const Pose3& pose, const Vector3& vel,
88  OptionalJacobian<9, 6> H1 = {},
89  OptionalJacobian<9, 3> H2 = {});
90 
94 
95  const Rot3& attitude(OptionalJacobian<3, 9> H = {}) const;
96  const Point3& position(OptionalJacobian<3, 9> H = {}) const;
97  const Velocity3& velocity(OptionalJacobian<3, 9> H = {}) const;
98 
99  const Pose3 pose() const {
100  return Pose3(attitude(), position());
101  }
102 
106 
108  Matrix3 R() const {
109  return R_.matrix();
110  }
113  return R_.toQuaternion();
114  }
116  Vector3 t() const {
117  return t_;
118  }
120  const Vector3& v() const {
121  return v_;
122  }
123  // Return velocity in body frame
125 
128  Matrix5 matrix() const;
129 
133 
135  GTSAM_EXPORT
136  friend std::ostream &operator<<(std::ostream &os, const NavState& state);
137 
139  void print(const std::string& s = "") const;
140 
142  bool equals(const NavState& other, double tol = 1e-8) const;
143 
147 
149  static NavState Identity() {
150  return NavState();
151  }
152 
154  NavState inverse() const;
155 
156  using LieGroup<NavState, 9>::inverse; // version with derivative
157 
159  NavState operator*(const NavState& T) const {
160  return NavState(R_ * T.R_, t_ + R_ * T.t_, v_ + R_ * T.v_);
161  }
162 
164  const Rot3& rotation() const { return attitude(); };
165 
166  // Tangent space sugar.
167  // TODO(frank): move to private navstate namespace in cpp
168  static Eigen::Block<Vector9, 3, 1> dR(Vector9& v) {
169  return v.segment<3>(0);
170  }
171  static Eigen::Block<Vector9, 3, 1> dP(Vector9& v) {
172  return v.segment<3>(3);
173  }
174  static Eigen::Block<Vector9, 3, 1> dV(Vector9& v) {
175  return v.segment<3>(6);
176  }
177  static Eigen::Block<const Vector9, 3, 1> dR(const Vector9& v) {
178  return v.segment<3>(0);
179  }
180  static Eigen::Block<const Vector9, 3, 1> dP(const Vector9& v) {
181  return v.segment<3>(3);
182  }
183  static Eigen::Block<const Vector9, 3, 1> dV(const Vector9& v) {
184  return v.segment<3>(6);
185  }
186 
188  NavState retract(const Vector9& v, //
189  OptionalJacobian<9, 9> H1 = {}, OptionalJacobian<9, 9> H2 =
190  {}) const;
191 
193  Vector9 localCoordinates(const NavState& g, //
194  OptionalJacobian<9, 9> H1 = {}, OptionalJacobian<9, 9> H2 =
195  {}) const;
196 
200 
201  using LieAlgebra = Matrix5;
202 
207  static NavState Expmap(const Vector9& xi, OptionalJacobian<9, 9> Hxi = {});
208 
213  static Vector9 Logmap(const NavState& pose, OptionalJacobian<9, 9> Hpose = {});
214 
219  Matrix9 AdjointMap() const;
220 
227  Vector9 Adjoint(const Vector9& xi_b,
228  OptionalJacobian<9, 9> H_this = {},
229  OptionalJacobian<9, 9> H_xib = {}) const;
230 
235  static Matrix9 adjointMap(const Vector9& xi);
236 
240  static Vector9 adjoint(const Vector9& xi, const Vector9& y,
241  OptionalJacobian<9, 9> Hxi = {},
242  OptionalJacobian<9, 9> H_y = {});
243 
245  static Matrix9 ExpmapDerivative(const Vector9& xi);
246 
248  static Matrix9 LogmapDerivative(const NavState& xi);
249 
250  // Chart at origin, depends on compile-time flag GTSAM_POSE3_EXPMAP
251  struct GTSAM_EXPORT ChartAtOrigin {
252  static NavState Retract(const Vector9& xi, ChartJacobian Hxi = {});
253  static Vector9 Local(const NavState& state, ChartJacobian Hstate = {});
254  };
255 
257  static Matrix5 Hat(const Vector9& xi);
258 
260  static Vector9 Vee(const Matrix5& X);
261 
265 
268  NavState update(const Vector3& b_acceleration, const Vector3& b_omega,
269  const double dt, OptionalJacobian<9, 9> F = {},
270  OptionalJacobian<9, 3> G1 = {},
271  OptionalJacobian<9, 3> G2 = {}) const;
272 
274  Vector9 coriolis(double dt, const Vector3& omega, bool secondOrder = false,
275  OptionalJacobian<9, 9> H = {}) const;
276 
279  Vector9 correctPIM(const Vector9& pim, double dt, const Vector3& n_gravity,
280  const std::optional<Vector3>& omegaCoriolis, bool use2ndOrderCoriolis =
281  false, OptionalJacobian<9, 9> H1 = {},
282  OptionalJacobian<9, 9> H2 = {}) const;
283 
285 
286 private:
289 #if GTSAM_ENABLE_BOOST_SERIALIZATION
290  friend class boost::serialization::access;
291  template<class ARCHIVE>
292  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
293  ar & BOOST_SERIALIZATION_NVP(R_);
294  ar & BOOST_SERIALIZATION_NVP(t_);
295  ar & BOOST_SERIALIZATION_NVP(v_);
296  }
297 #endif
298 };
300 
301 // Specialize NavState traits to use a Retract/Local that agrees with IMUFactors
302 template <>
303 struct traits<NavState> : public internal::MatrixLieGroup<NavState> {};
304 
305 template <>
306 struct traits<const NavState> : public internal::MatrixLieGroup<NavState> {};
307 
308 } // namespace gtsam
H
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Definition: gnuplot_common_settings.hh:74
gtsam::NavState::dR
static Eigen::Block< Vector9, 3, 1 > dR(Vector9 &v)
Definition: NavState.h:168
relicense.update
def update(text)
Definition: relicense.py:46
tail
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type tail(NType n)
Definition: BlockMethods.h:1257
gtsam::NavState::dV
static Eigen::Block< const Vector9, 3, 1 > dV(const Vector9 &v)
Definition: NavState.h:183
gtsam::translation
Point3_ translation(const Pose3_ &pose)
Definition: slam/expressions.h:97
pose
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
inverse
const EIGEN_DEVICE_FUNC InverseReturnType inverse() const
Definition: ArrayCwiseUnaryOps.h:411
Vector.h
typedef and functions to augment Eigen's VectorXd
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
gtsam::NavState::t_
Point3 t_
position n_t, in nav frame
Definition: NavState.h:44
screwPose2::xi
Vector xi
Definition: testPose2.cpp:169
gtsam::Velocity3
Vector3 Velocity3
Velocity is currently typedef'd to Vector3.
Definition: NavState.h:28
gtsam::NavState::NavState
NavState()
Default constructor.
Definition: NavState.h:56
gtsam::NavState::dP
static Eigen::Block< Vector9, 3, 1 > dP(Vector9 &v)
Definition: NavState.h:171
gtsam::position
Point3_ position(const NavState_ &X)
Definition: navigation/expressions.h:37
gtsam::NavState::NavState
NavState(const Rot3 &R, const Point3 &t, const Velocity3 &v)
Construct from attitude, position, velocity.
Definition: NavState.h:61
dt
const double dt
Definition: testVelocityConstraint.cpp:15
gtsam::NavState::LieAlgebra
Matrix5 LieAlgebra
Definition: NavState.h:201
vel
static const Velocity3 vel(0.4, 0.5, 0.6)
gtsam::NavState
Definition: NavState.h:38
gtsam::utils.numerical_derivative.retract
def retract(a, np.ndarray xi)
Definition: numerical_derivative.py:44
X
#define X
Definition: icosphere.cpp:20
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:44
gtsam::NavState::v
const Vector3 & v() const
Return velocity as Vector3. Computation-free.
Definition: NavState.h:120
os
ofstream os("timeSchurFactors.csv")
gtsam::NavState::NavState
NavState(const Matrix3 &R, const Vector6 &tv)
Construct from SO(3) and R^6.
Definition: NavState.h:71
gtsam::NavState::rotation
const Rot3 & rotation() const
Syntactic sugar.
Definition: NavState.h:164
block
m m block(1, 0, 2, 2)<< 4
biased_x_rotation::omega
const double omega
Definition: testPreintegratedRotation.cpp:32
gtsam::attitude
Rot3_ attitude(const NavState_ &X)
Definition: navigation/expressions.h:34
Expmap
Pose2_ Expmap(const Vector3_ &xi)
Definition: InverseKinematicsExampleExpressions.cpp:47
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:145
gtsam::internal::MatrixLieGroup
Both LieGroupTraits and Testable.
Definition: Lie.h:247
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::Pose3
Definition: Pose3.h:37
gtsam::NavState::R_
Rot3 R_
Rotation nRb, rotates points/velocities in body to points/velocities in nav.
Definition: NavState.h:43
gtsam::NavState::dP
static Eigen::Block< const Vector9, 3, 1 > dP(const Vector9 &v)
Definition: NavState.h:180
gtsam::Rot3::toQuaternion
gtsam::Quaternion toQuaternion() const
Definition: Rot3M.cpp:232
gtsam::NavState::v_
Velocity3 v_
velocity n_v in nav frame
Definition: NavState.h:45
gtsam::NavState::t
Vector3 t() const
Return position as Vector3.
Definition: NavState.h:116
bodyVelocity
Vector3 bodyVelocity(const Pose3 &w_t_b, const Vector3 &vec_w, OptionalJacobian< 3, 6 > Hpose={}, OptionalJacobian< 3, 3 > Hvel={})
Definition: testFactorTesting.cpp:29
gtsam::NavState::R
Matrix3 R() const
Return rotation matrix. Induces computation in quaternion mode.
Definition: NavState.h:108
Manifold.h
Base class and basic functions for Manifold types.
Eigen::Triplet< double >
head
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type head(NType n)
Definition: BlockMethods.h:1208
gtsam::symbol_shorthand::F
Key F(std::uint64_t j)
Definition: inference/Symbol.h:153
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
gtsam::NavState::dV
static Eigen::Block< Vector9, 3, 1 > dV(Vector9 &v)
Definition: NavState.h:174
y
Scalar * y
Definition: level1_cplx_impl.h:124
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
gtsam::NavState::Identity
static NavState Identity()
identity for group operation
Definition: NavState.h:149
Eigen::Quaternion
The quaternion class used to represent 3D orientations and rotations.
Definition: ForwardDeclarations.h:293
gtsam
traits
Definition: SFMdata.h:40
gtsam::rotation
Rot3_ rotation(const Pose3_ &pose)
Definition: slam/expressions.h:93
gtsam::traits
Definition: Group.h:36
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
coriolis
std::function< Vector9(const NavState &, const bool &)> coriolis
Definition: testNavState.cpp:334
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::Rot3::matrix
Matrix3 matrix() const
Definition: Rot3M.cpp:218
gtsam::LieGroup
Definition: Lie.h:37
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
Eigen::Matrix< double, 9, 9 >
gtsam.examples.ImuFactorISAM2Example.n_gravity
def n_gravity
Definition: ImuFactorISAM2Example.py:31
gtsam::NavState::operator*
NavState operator*(const NavState &T) const
compose syntactic sugar
Definition: NavState.h:159
gtsam::NavState::pose
const Pose3 pose() const
Definition: NavState.h:99
align_3::t
Point2 t(10, 10)
gtsam::NavState::quaternion
Quaternion quaternion() const
Return quaternion. Induces computation in matrix mode.
Definition: NavState.h:112
Pose3
Definition: testDependencies.h:3
gtsam::NavState::dR
static Eigen::Block< const Vector9, 3, 1 > dR(const Vector9 &v)
Definition: NavState.h:177
gtsam::NavState::NavState
NavState(const Matrix5 &T)
Construct from Matrix5.
Definition: NavState.h:76
adjoint
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:67
gtsam::NavState::NavState
NavState(const Pose3 &pose, const Velocity3 &v)
Construct from pose and velocity.
Definition: NavState.h:66
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::NavState::ChartAtOrigin
Definition: NavState.h:251
R
Rot2 R(Rot2::fromAngle(0.1))
Pose3.h
3D Pose manifold SO(3) x R^3 and group SE(3)
make_changelog.state
state
Definition: make_changelog.py:29
gtsam::velocity
Velocity3_ velocity(const NavState_ &X)
Definition: navigation/expressions.h:40


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:02:32