@@ -77,10 +77,13 @@ Vector3 NavState::bodyVelocity(OptionalJacobian<3, 9> H) const {
7777}
7878
7979// ------------------------------------------------------------------------------
80- Matrix7 NavState::matrix () const {
80+ Matrix5 NavState::matrix () const {
8181 Matrix3 R = this ->R ();
82- Matrix7 T;
83- T << R, Z_3x3, t (), Z_3x3, R, v (), Vector6::Zero ().transpose (), 1.0 ;
82+
83+ Matrix5 T = Matrix5::Identity ();
84+ T.block <3 , 3 >(0 , 0 ) = R;
85+ T.block <3 , 1 >(0 , 3 ) = t_;
86+ T.block <3 , 1 >(0 , 4 ) = v_;
8487 return T;
8588}
8689
@@ -103,6 +106,161 @@ bool NavState::equals(const NavState& other, double tol) const {
103106 && equal_with_abs_tol (v_, other.v_ , tol);
104107}
105108
109+ // ------------------------------------------------------------------------------
110+ NavState NavState::inverse () const {
111+ Rot3 Rt = R_.inverse ();
112+ return NavState (Rt, Rt * (-t_), Rt * -(v_));
113+ }
114+
115+ // ------------------------------------------------------------------------------
116+ NavState NavState::Expmap (const Vector9& xi, OptionalJacobian<9 , 9 > Hxi) {
117+ // Get angular velocity w, translational velocity v, and acceleration a
118+ Vector3 w = xi.head <3 >();
119+ Vector3 rho = xi.segment <3 >(3 );
120+ Vector3 nu = xi.tail <3 >();
121+
122+ // Compute rotation using Expmap
123+ Rot3 R = Rot3::Expmap (w);
124+
125+ // Compute translations and optionally their Jacobians
126+ Matrix3 Qt, Qv;
127+ Vector3 t = Pose3::ExpmapTranslation (w, rho, Hxi ? &Qt : nullptr , R);
128+ Vector3 v = Pose3::ExpmapTranslation (w, nu, Hxi ? &Qv : nullptr , R);
129+
130+ if (Hxi) {
131+ const Matrix3 Jw = Rot3::ExpmapDerivative (w);
132+ *Hxi << Jw, Z_3x3, Z_3x3,
133+ Qt, Jw, Z_3x3,
134+ Qv, Z_3x3, Jw;
135+ }
136+
137+ return NavState (R, t, v);
138+ }
139+
140+ // ------------------------------------------------------------------------------
141+ Vector9 NavState::Logmap (const NavState& state, OptionalJacobian<9 , 9 > Hstate) {
142+ if (Hstate) *Hstate = LogmapDerivative (state);
143+
144+ const Vector3 phi = Rot3::Logmap (state.rotation ());
145+ const Vector3& p = state.position ();
146+ const Vector3& v = state.velocity ();
147+ const double t = phi.norm ();
148+ if (t < 1e-8 ) {
149+ Vector9 log;
150+ log << phi, p, v;
151+ return log;
152+
153+ } else {
154+ const Matrix3 W = skewSymmetric (phi / t);
155+
156+ const double Tan = tan (0.5 * t);
157+ const Vector3 Wp = W * p;
158+ const Vector3 Wv = W * v;
159+ const Vector3 rho = p - (0.5 * t) * Wp + (1 - t / (2 . * Tan)) * (W * Wp);
160+ const Vector3 nu = v - (0.5 * t) * Wv + (1 - t / (2 . * Tan)) * (W * Wv);
161+ Vector9 log;
162+ // Order is ω, p, v
163+ log << phi, rho, nu;
164+ return log;
165+ }
166+ }
167+
168+ // ------------------------------------------------------------------------------
169+ Matrix9 NavState::AdjointMap () const {
170+ const Matrix3 R = R_.matrix ();
171+ Matrix3 A = skewSymmetric (t_.x (), t_.y (), t_.z ()) * R;
172+ Matrix3 B = skewSymmetric (v_.x (), v_.y (), v_.z ()) * R;
173+ // Eqn 2 in Barrau20icra
174+ Matrix9 adj;
175+ adj << R, Z_3x3, Z_3x3, A, R, Z_3x3, B, Z_3x3, R;
176+ return adj;
177+ }
178+
179+ // ------------------------------------------------------------------------------
180+ Vector9 NavState::Adjoint (const Vector9& xi_b, OptionalJacobian<9 , 9 > H_state,
181+ OptionalJacobian<9 , 9 > H_xib) const {
182+ const Matrix9 Ad = AdjointMap ();
183+
184+ // Jacobians
185+ if (H_state) *H_state = -Ad * adjointMap (xi_b);
186+ if (H_xib) *H_xib = Ad;
187+
188+ return Ad * xi_b;
189+ }
190+
191+ // ------------------------------------------------------------------------------
192+ Matrix9 NavState::adjointMap (const Vector9& xi) {
193+ Matrix3 w_hat = skewSymmetric (xi (0 ), xi (1 ), xi (2 ));
194+ Matrix3 v_hat = skewSymmetric (xi (3 ), xi (4 ), xi (5 ));
195+ Matrix3 a_hat = skewSymmetric (xi (6 ), xi (7 ), xi (8 ));
196+ Matrix9 adj;
197+ adj << w_hat, Z_3x3, Z_3x3, v_hat, w_hat, Z_3x3, a_hat, Z_3x3, w_hat;
198+ return adj;
199+ }
200+
201+ // ------------------------------------------------------------------------------
202+ Vector9 NavState::adjoint (const Vector9& xi, const Vector9& y,
203+ OptionalJacobian<9 , 9 > Hxi,
204+ OptionalJacobian<9 , 9 > H_y) {
205+ if (Hxi) {
206+ Hxi->setZero ();
207+ for (int i = 0 ; i < 9 ; ++i) {
208+ Vector9 dxi;
209+ dxi.setZero ();
210+ dxi (i) = 1.0 ;
211+ Matrix9 Gi = adjointMap (dxi);
212+ Hxi->col (i) = Gi * y;
213+ }
214+ }
215+
216+ const Matrix9& ad_xi = adjointMap (xi);
217+ if (H_y) *H_y = ad_xi;
218+
219+ return ad_xi * y;
220+ }
221+
222+ // ------------------------------------------------------------------------------
223+ Matrix9 NavState::ExpmapDerivative (const Vector9& xi) {
224+ Matrix9 J;
225+ Expmap (xi, J);
226+ return J;
227+ }
228+
229+ // ------------------------------------------------------------------------------
230+ Matrix9 NavState::LogmapDerivative (const NavState& state) {
231+ const Vector9 xi = Logmap (state);
232+ const Vector3 w = xi.head <3 >();
233+ Vector3 rho = xi.segment <3 >(3 );
234+ Vector3 nu = xi.tail <3 >();
235+
236+ Matrix3 Qt, Qv;
237+ const Rot3 R = Rot3::Expmap (w);
238+ Pose3::ExpmapTranslation (w, rho, Qt, R);
239+ Pose3::ExpmapTranslation (w, nu, Qv, R);
240+ const Matrix3 Jw = Rot3::LogmapDerivative (w);
241+ const Matrix3 Qt2 = -Jw * Qt * Jw;
242+ const Matrix3 Qv2 = -Jw * Qv * Jw;
243+
244+ Matrix9 J;
245+ J << Jw, Z_3x3, Z_3x3,
246+ Qt2, Jw, Z_3x3,
247+ Qv2, Z_3x3, Jw;
248+ return J;
249+ }
250+
251+
252+ // ------------------------------------------------------------------------------
253+ NavState NavState::ChartAtOrigin::Retract (const Vector9& xi,
254+ ChartJacobian Hxi) {
255+ return Expmap (xi, Hxi);
256+ }
257+
258+ // ------------------------------------------------------------------------------
259+ Vector9 NavState::ChartAtOrigin::Local (const NavState& state,
260+ ChartJacobian Hstate) {
261+ return Logmap (state, Hstate);
262+ }
263+
106264// ------------------------------------------------------------------------------
107265NavState NavState::retract (const Vector9& xi, //
108266 OptionalJacobian<9 , 9 > H1, OptionalJacobian<9 , 9 > H2) const {
@@ -142,15 +300,16 @@ Vector9 NavState::localCoordinates(const NavState& g, //
142300 Matrix3 D_xi_R;
143301 xi << Rot3::Logmap (dR, (H1 || H2) ? &D_xi_R : 0 ), dP, dV;
144302 if (H1) {
145- *H1 << D_xi_R * D_dR_R, Z_3x3, Z_3x3, //
146- D_dt_R, -I_3x3, Z_3x3, //
147- D_dv_R, Z_3x3, -I_3x3;
303+ *H1 << D_xi_R * D_dR_R, Z_3x3, Z_3x3, //
304+ D_dt_R, -I_3x3, Z_3x3, //
305+ D_dv_R, Z_3x3, -I_3x3;
148306 }
149307 if (H2) {
150- *H2 << D_xi_R, Z_3x3, Z_3x3, //
151- Z_3x3, dR.matrix (), Z_3x3, //
152- Z_3x3, Z_3x3, dR.matrix ();
308+ *H2 << D_xi_R, Z_3x3, Z_3x3, //
309+ Z_3x3, dR.matrix (), Z_3x3, //
310+ Z_3x3, Z_3x3, dR.matrix ();
153311 }
312+
154313 return xi;
155314}
156315
@@ -213,7 +372,8 @@ NavState NavState::update(const Vector3& b_acceleration, const Vector3& b_omega,
213372// ------------------------------------------------------------------------------
214373Vector9 NavState::coriolis (double dt, const Vector3& omega, bool secondOrder,
215374 OptionalJacobian<9 , 9 > H) const {
216- auto [nRb, n_t , n_v] = (*this );
375+ Rot3 nRb = R_;
376+ Point3 n_t = t_, n_v = v_;
217377
218378 const double dt2 = dt * dt;
219379 const Vector3 omega_cross_vel = omega.cross (n_v);
0 commit comments