ABC.h
Go to the documentation of this file.
1 
10 #ifndef ABC_H
11 #define ABC_H
12 #include <gtsam/base/Matrix.h>
13 #include <gtsam/base/Vector.h>
14 #include <gtsam/geometry/Rot3.h>
15 #include <gtsam/geometry/Unit3.h>
16 
17 namespace gtsam {
18 namespace abc_eqf_lib {
19 using namespace std;
20 using namespace gtsam;
21 //========================================================================
22 // Utility Functions
23 //========================================================================
24 
25 //========================================================================
26 // Utility Functions
27 //========================================================================
28 
30 
31 bool checkNorm(const Vector3& x, double tol = 1e-3);
32 
34 
35 bool hasNaN(const Vector3& vec);
36 
38 
39 Matrix blockDiag(const Matrix& A, const Matrix& B);
40 
42 
43 Matrix repBlock(const Matrix& A, int n);
44 
45 // Utility Functions Implementation
46 
53 bool checkNorm(const Vector3& x, double tol) {
54  return abs(x.norm() - 1) < tol || std::isnan(x.norm());
55 }
56 
62 bool hasNaN(const Vector3& vec) {
63  return std::isnan(vec[0]) || std::isnan(vec[1]) || std::isnan(vec[2]);
64 }
65 
73 Matrix blockDiag(const Matrix& A, const Matrix& B) {
74  if (A.size() == 0) {
75  return B;
76  } else if (B.size() == 0) {
77  return A;
78  } else {
79  Matrix result(A.rows() + B.rows(), A.cols() + B.cols());
80  result.setZero();
81  result.block(0, 0, A.rows(), A.cols()) = A;
82  result.block(A.rows(), A.cols(), B.rows(), B.cols()) = B;
83  return result;
84  }
85 }
86 
93 Matrix repBlock(const Matrix& A, int n) {
94  if (n <= 0) return Matrix();
95 
96  Matrix result = A;
97  for (int i = 1; i < n; i++) {
99  }
100  return result;
101 }
102 
103 //========================================================================
104 // Core Data Types
105 //========================================================================
106 
108 
109 struct Input {
112  static Input random();
113  Matrix3 W() const {
114  return Rot3::Hat(w);
115  }
116 };
117 
119 struct Measurement {
122  Matrix3 Sigma;
123  int cal_idx = -1;
124 };
125 
127 template <size_t N>
128 class State {
129  public:
130  Rot3 R; // Attitude rotation matrix R
131  Vector3 b; // Gyroscope bias b
132  std::array<Rot3, N> S; // Sensor calibrations S
133 
135  State(const Rot3& R = Rot3::Identity(), const Vector3& b = Vector3::Zero(),
136  const std::array<Rot3, N>& S = std::array<Rot3, N>{})
137  : R(R), b(b), S(S) {}
138 
140  static State identity() {
141  std::array<Rot3, N> S_id{};
142  S_id.fill(Rot3::Identity());
143  return State(Rot3::Identity(), Vector3::Zero(), S_id);
144  }
151  Vector eps(6 + 3 * N);
152 
153  // First 3 elements - attitude
154  eps.head<3>() = Rot3::Logmap(R.between(other.R));
155  // Next 3 elements - bias
156  // Next 3 elements - bias
157  eps.segment<3>(3) = other.b - b;
158 
159  // Remaining elements - calibrations
160  for (size_t i = 0; i < N; i++) {
161  eps.segment<3>(6 + 3 * i) = Rot3::Logmap(S[i].between(other.S[i]));
162  }
163 
164  return eps;
165  }
166 
172  State retract(const Vector& v) const {
173  if (v.size() != static_cast<Eigen::Index>(6 + 3 * N)) {
174  throw std::invalid_argument(
175  "Vector size does not match state dimensions");
176  }
177  Rot3 newR = R * Rot3::Expmap(v.head<3>());
178  Vector3 newB = b + v.segment<3>(3);
179  std::array<Rot3, N> newS;
180  for (size_t i = 0; i < N; i++) {
181  newS[i] = S[i] * Rot3::Expmap(v.segment<3>(6 + 3 * i));
182  }
183  return State(newR, newB, newS);
184  }
185 };
186 
187 //========================================================================
188 // Symmetry Group
189 //========================================================================
190 
195 template <size_t N>
196 struct G {
197  Rot3 A;
198  Matrix3 a;
199  std::array<Rot3, N> B;
200 
202  G(const Rot3& A = Rot3::Identity(), const Matrix3& a = Matrix3::Zero(),
203  const std::array<Rot3, N>& B = std::array<Rot3, N>{})
204  : A(A), a(a), B(B) {}
205 
207  G operator*(const G<N>& other) const {
208  std::array<Rot3, N> newB;
209  for (size_t i = 0; i < N; i++) {
210  newB[i] = B[i] * other.B[i];
211  }
212  return G(A * other.A, a + Rot3::Hat(A.matrix() * Rot3::Vee(other.a)), newB);
213  }
214 
216  G inv() const {
217  Matrix3 Ainv = A.inverse().matrix();
218  std::array<Rot3, N> Binv;
219  for (size_t i = 0; i < N; i++) {
220  Binv[i] = B[i].inverse();
221  }
222  return G(A.inverse(), -Rot3::Hat(Ainv * Rot3::Vee(a)), Binv);
223  }
224 
226  static G identity(int n) {
227  std::array<Rot3, N> B;
228  B.fill(Rot3::Identity());
229  return G(Rot3::Identity(), Matrix3::Zero(), B);
230  }
231 
233  static G exp(const Vector& x) {
234  if (x.size() != static_cast<Eigen::Index>(6 + 3 * N)) {
235  throw std::invalid_argument("Vector size mismatch for group exponential");
236  }
237  Rot3 A = Rot3::Expmap(x.head<3>());
238  Vector3 a_vee = Rot3::ExpmapDerivative(-x.head<3>()) * x.segment<3>(3);
239  Matrix3 a = Rot3::Hat(a_vee);
240  std::array<Rot3, N> B;
241  for (size_t i = 0; i < N; i++) {
242  B[i] = Rot3::Expmap(x.segment<3>(6 + 3 * i));
243  }
244  return G(A, a, B);
245  }
246 };
247 } // namespace abc_eqf_lib
248 
249 template <size_t N>
250 struct traits<abc_eqf_lib::State<N>>
251  : internal::LieGroupTraits<abc_eqf_lib::State<N>> {};
252 
253 template <size_t N>
254 struct traits<abc_eqf_lib::G<N>> : internal::LieGroupTraits<abc_eqf_lib::G<N>> {
255 };
256 
257 } // namespace gtsam
258 
259 #endif // ABC_H
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
gtsam::LieGroup::between
Class between(const Class &g) const
Definition: Lie.h:52
gtsam::abc_eqf_lib::State::localCoordinates
Vector localCoordinates(const State< N > &other) const
Definition: ABC.h:150
gtsam::abc_eqf_lib::G::G
G(const Rot3 &A=Rot3::Identity(), const Matrix3 &a=Matrix3::Zero(), const std::array< Rot3, N > &B=std::array< Rot3, N >{})
List of SO(3) elements for calibration.
Definition: ABC.h:202
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
gtsam::between
Expression< T > between(const Expression< T > &t1, const Expression< T > &t2)
Definition: nonlinear/expressions.h:17
Vector.h
typedef and functions to augment Eigen's VectorXd
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::abc_eqf_lib::G::a
Matrix3 a
First SO(3) element.
Definition: ABC.h:198
gtsam::abc_eqf_lib::Input::Sigma
Matrix Sigma
Angular velocity (3-vector)
Definition: ABC.h:111
Matrix.h
typedef and functions to augment Eigen's MatrixXd
gtsam::Rot3::Identity
static Rot3 Identity()
identity rotation for group operation
Definition: Rot3.h:304
gtsam::internal::DoglegState
Definition: DoglegOptimizer.cpp:54
gtsam::abc_eqf_lib::State
State class representing the state of the Biased Attitude System.
Definition: ABC.h:128
x
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 x
Definition: gnuplot_common_settings.hh:12
gtsam::abc_eqf_lib::G::inv
G inv() const
Group inverse.
Definition: ABC.h:216
gtsam::abc_eqf_lib::State::identity
static State identity()
Identity function.
Definition: ABC.h:140
gtsam::abc_eqf_lib::G::identity
static G identity(int n)
Identity element.
Definition: ABC.h:226
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
isnan
#define isnan(X)
Definition: main.h:93
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:44
gtsam::abc_eqf_lib::Measurement::Sigma
Matrix3 Sigma
Known direction in global frame.
Definition: ABC.h:122
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::Rot3::Expmap
static Rot3 Expmap(const Vector3 &v, OptionalJacobian< 3, 3 > H={})
Definition: Rot3M.cpp:156
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
Unit3.h
Rot3.h
3D rotation represented as a rotation matrix or quaternion
n
int n
Definition: BiCGSTAB_simple.cpp:1
gtsam::abc_eqf_lib::checkNorm
bool checkNorm(const Vector3 &x, double tol=1e-3)
Check if a vector is a unit vector.
Definition: ABC.h:53
gtsam::abc_eqf_lib::Input::W
Matrix3 W() const
Random input.
Definition: ABC.h:113
gtsam::abc_eqf_lib::G::A
Rot3 A
Definition: ABC.h:197
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::State
internal::DoglegState State
Definition: DoglegOptimizer.cpp:62
gtsam::abc_eqf_lib::State::S
std::array< Rot3, N > S
Definition: ABC.h:132
gtsam::abc_eqf_lib::State::State
State(const Rot3 &R=Rot3::Identity(), const Vector3 &b=Vector3::Zero(), const std::array< Rot3, N > &S=std::array< Rot3, N >{})
Constructor.
Definition: ABC.h:135
gtsam::abc_eqf_lib::G::operator*
G operator*(const G< N > &other) const
Group multiplication.
Definition: ABC.h:207
gtsam::abc_eqf_lib::repBlock
Matrix repBlock(const Matrix &A, int n)
Repeat a block matrix n times along the diagonal.
Definition: ABC.h:93
gtsam::abc_eqf_lib::G::B
std::array< Rot3, N > B
so(3) element (skew-symmetric matrix)
Definition: ABC.h:199
gtsam::internal::LieGroupTraits
Definition: Lie.h:174
gtsam::abc_eqf_lib::Input
Input struct for the Biased Attitude System.
Definition: ABC.h:109
gtsam::abc_eqf_lib::Input::w
Vector3 w
Definition: ABC.h:110
gtsam::abc_eqf_lib::State::b
Vector3 b
Definition: ABC.h:131
gtsam::abc_eqf_lib::G::exp
static G exp(const Vector &x)
Exponential map of the tangent space elements to the group.
Definition: ABC.h:233
gtsam::b
const G & b
Definition: Group.h:79
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: ABC.h:17
gtsam::Rot3::Hat
static Matrix3 Hat(const Vector3 &xi)
Hat maps from tangent vector to Lie algebra.
Definition: Rot3.h:406
gtsam::traits
Definition: Group.h:36
gtsam::Rot3::ExpmapDerivative
static Matrix3 ExpmapDerivative(const Vector3 &x)
Derivative of Expmap.
Definition: Rot3.cpp:239
std
Definition: BFloat16.h:88
gtsam::abc_eqf_lib::hasNaN
bool hasNaN(const Vector3 &vec)
Check if vector contains NaN values.
Definition: ABC.h:62
G
JacobiRotation< float > G
Definition: Jacobi_makeGivens.cpp:2
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::abc_eqf_lib::blockDiag
Matrix blockDiag(const Matrix &A, const Matrix &B)
Create a block diagonal matrix from two matrices.
Definition: ABC.h:73
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::abc_eqf_lib::Measurement
Measurement struct.
Definition: ABC.h:119
gtsam::abc_eqf_lib::State::retract
State retract(const Vector &v) const
Definition: ABC.h:172
gtsam::Rot3::Logmap
static Vector3 Logmap(const Rot3 &R, OptionalJacobian< 3, 3 > H={})
Definition: Rot3M.cpp:161
abs
#define abs(x)
Definition: datatypes.h:17
gtsam::Rot3::Vee
static Vector3 Vee(const Matrix3 &X)
Vee maps from Lie algebra to tangent vector.
Definition: Rot3.h:409
N
#define N
Definition: igam.h:9
gtsam::Unit3
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
gtsam::abc_eqf_lib::G
Definition: ABC.h:196
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::abc_eqf_lib::Measurement::y
Unit3 y
Definition: ABC.h:120
R
Rot2 R(Rot2::fromAngle(0.1))
gtsam::abc_eqf_lib::Measurement::d
Unit3 d
Measurement direction in sensor frame.
Definition: ABC.h:121
S
DiscreteKey S(1, 2)
for
for(size_t i=1;i< poses.size();++i)
Definition: doc/Code/VisualISAMExample.cpp:7
gtsam::abc_eqf_lib::State::R
Rot3 R
Definition: ABC.h:130
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Wed May 28 2025 03:00:48