Update wedge and vee to Rot3 Hat and Vee for EqF

release/4.3a0
jenniferoum 2025-03-26 21:41:07 -07:00
parent d1673b7df9
commit 39a7a5b627
5 changed files with 11 additions and 30 deletions

View File

@ -38,12 +38,12 @@ State stateAction(const G& X, const State& xi) {
} }
return State(xi.R * X.A, return State(xi.R * X.A,
X.A.inverse().matrix() * (xi.b - vee(X.a)), X.A.inverse().matrix() * (xi.b - Rot3::Vee(X.a)),
new_S); new_S);
} }
Input velocityAction(const G& X, const Input& u) { Input velocityAction(const G& X, const Input& u) {
return Input(X.A.inverse().matrix() * (u.w - vee(X.a)), u.Sigma); return Input(X.A.inverse().matrix() * (u.w - Rot3::Vee(X.a)), u.Sigma);
} }
Vector3 outputAction(const G& X, const Direction& y, int idx) { Vector3 outputAction(const G& X, const Direction& y, int idx) {
@ -182,7 +182,7 @@ void EqF::update(const Measurement& y) {
Matrix Ct = __measurementMatrixC(y.d, y.cal_idx); Matrix Ct = __measurementMatrixC(y.d, y.cal_idx);
Vector3 action_result = outputAction(__X_hat.inv(), y.y, y.cal_idx); Vector3 action_result = outputAction(__X_hat.inv(), y.y, y.cal_idx);
Vector3 delta_vec = wedge(y.d.d.unitVector()) * action_result; // Ensure this is the right operation Vector3 delta_vec = Rot3::Hat(y.d.d.unitVector()) * action_result; // Ensure this is the right operation
Matrix Dt = __outputMatrixDt(y.cal_idx); Matrix Dt = __outputMatrixDt(y.cal_idx);
Matrix S = Ct * __Sigma * Ct.transpose() + Dt * y.Sigma * Dt.transpose(); Matrix S = Ct * __Sigma * Ct.transpose() + Dt * y.Sigma * Dt.transpose();
Matrix K = __Sigma * Ct.transpose() * S.inverse(); Matrix K = __Sigma * Ct.transpose() * S.inverse();
@ -255,10 +255,10 @@ Matrix EqF::__measurementMatrixC(const Direction& d, int idx) const {
if (idx >= 0) { if (idx >= 0) {
// Cc.block<3, 3>(0, 3 * idx) = wedge(d.d.unitVector()); // WRONG // Cc.block<3, 3>(0, 3 * idx) = wedge(d.d.unitVector()); // WRONG
// Set the correct 3x3 block in Cc // Set the correct 3x3 block in Cc
Cc.block<3, 3>(0, 3 * idx) = wedge(d.d.unitVector()); Cc.block<3, 3>(0, 3 * idx) = Rot3::Hat(d.d.unitVector());
} }
Matrix3 wedge_d = wedge(d.d.unitVector()); Matrix3 wedge_d = Rot3::Hat(d.d.unitVector());
// This Matrix concatenation was different from the Python version // This Matrix concatenation was different from the Python version
// Create the equivalent of: // Create the equivalent of:

View File

@ -19,7 +19,7 @@ G G::operator*(const G& other) const {
} }
return G(A * other.A, return G(A * other.A,
a + wedge(A.matrix() * vee(other.a)), a + Rot3::Hat(A.matrix() * Rot3::Vee(other.a)),
new_B); new_B);
} }
@ -32,7 +32,7 @@ G G::inv() const {
} }
return G(A.inverse(), return G(A.inverse(),
-wedge(A_inv * vee(a)), -Rot3::Hat(A_inv * Rot3::Vee(a)),
B_inv); B_inv);
} }
@ -50,7 +50,7 @@ G G::exp(const Vector& x) {
Rot3 A = Rot3::Expmap(x.head<3>()); Rot3 A = Rot3::Expmap(x.head<3>());
Vector3 a_vee = Rot3::ExpmapDerivative(-x.head<3>()) * x.segment<3>(3); Vector3 a_vee = Rot3::ExpmapDerivative(-x.head<3>()) * x.segment<3>(3);
Matrix3 a = wedge(a_vee); Matrix3 a = Rot3::Hat(a_vee);
std::vector<Rot3> B; std::vector<Rot3> B;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {

View File

@ -5,6 +5,7 @@
#include "utilities.h" #include "utilities.h"
#include <Eigen/Dense> #include <Eigen/Dense>
#include <stdexcept> #include <stdexcept>
#include "gtsam/geometry/Rot3.h"
Input::Input(const Vector3& w, const Matrix& Sigma) Input::Input(const Vector3& w, const Matrix& Sigma)
: w(w), Sigma(Sigma) { : w(w), Sigma(Sigma) {
@ -20,7 +21,7 @@ Input::Input(const Vector3& w, const Matrix& Sigma)
} }
Matrix3 Input::W() const { Matrix3 Input::W() const {
return wedge(w); return Rot3::Hat(w);
} }
Input Input::random() { Input Input::random() {

View File

@ -5,26 +5,8 @@
#include <cmath> #include <cmath>
// Global configuration // Global configuration
const std::string COORDINATE = "EXPONENTIAL"; const std::string COORDINATE = "EXPONENTIAL"; // Alternative: "NORMAL"
Matrix3 wedge(const Vector3& vec) {
Matrix3 mat;
mat << 0.0, -vec(2), vec(1),
vec(2), 0.0, -vec(0),
-vec(1), vec(0), 0.0;
return mat;
}
Vector3 vee(const Matrix3& mat) {
Vector3 vec;
vec << mat(2, 1), mat(0, 2), mat(1, 0);
return vec;
}
// Matrix3 Rot3LeftJacobian(const Vector3& arr) {
// return Rot3::ExpmapDerivative(-arr);
//
// }
bool checkNorm(const Vector3& x, double tol) { bool checkNorm(const Vector3& x, double tol) {
return abs(x.norm() - 1) < tol || std::isnan(x.norm()); return abs(x.norm() - 1) < tol || std::isnan(x.norm());

View File

@ -9,7 +9,6 @@
#include <gtsam/base/Matrix.h> #include <gtsam/base/Matrix.h>
#include <gtsam/base/Vector.h> #include <gtsam/base/Vector.h>
#include <gtsam/geometry/Rot3.h>
#include <Eigen/Dense> #include <Eigen/Dense>
#include <functional> #include <functional>
@ -22,7 +21,6 @@ extern const std::string COORDINATE; // "EXPONENTIAL" or "NORMAL"
* Utility functions * Utility functions
*/ */
Matrix3 wedge(const Vector3& vec); Matrix3 wedge(const Vector3& vec);
Vector3 vee(const Matrix3& mat);
bool checkNorm(const Vector3& x, double tol = 1e-3); bool checkNorm(const Vector3& x, double tol = 1e-3);
Matrix blockDiag(const Matrix& A, const Matrix& B); Matrix blockDiag(const Matrix& A, const Matrix& B);
Matrix repBlock(const Matrix& A, int n); Matrix repBlock(const Matrix& A, int n);