My Project 1.0
Holistic Fusion: A Generic Framework for Multimodal Sensor Fusion
Loading...
Searching...
No Matches
GmsfUnaryExpressionAbsolutePosition3.h
Go to the documentation of this file.
1/*
2Copyright 2024 by Julian Nubert, Robotic Systems Lab, ETH Zurich.
3All rights reserved.
4This file is released under the "BSD-3-Clause License".
5Please see the LICENSE file that has been included as part of this package.
6 */
7
8#ifndef GMSF_UNARY_EXPRESSION_POSITION3_H
9#define GMSF_UNARY_EXPRESSION_POSITION3_H
10
11// GTSAM
12#include <gtsam/base/types.h>
13#include <gtsam/inference/Symbol.h>
14#include <gtsam/slam/expressions.h>
15
16// Workspace
19
20namespace holistic_fusion {
21
22class GmsfUnaryExpressionAbsolutePosition3 final : public GmsfUnaryExpressionAbsolut<gtsam::Point3, 'd'> {
23 public:
24 // Constructor
26 const std::string& imuFrameName, const Eigen::Isometry3d& T_I_sensorFrame,
27 const double createReferenceAlignmentKeyframeEveryNSeconds)
28 : GmsfUnaryExpressionAbsolut(positionUnaryMeasurementPtr, imuFrameName, T_I_sensorFrame,
29 createReferenceAlignmentKeyframeEveryNSeconds),
30 positionUnaryMeasurementPtr_(positionUnaryMeasurementPtr),
31 exp_fixedFrame_t_fixedFrame_sensorFrame_(gtsam::Point3::Zero()),
32 exp_R_fixedFrame_I_(gtsam::Rot3::Identity()) {}
33
34 // Destructor
36
37 // Noise as GTSAM Datatype
38 [[nodiscard]] const gtsam::Vector getNoiseDensity() const override {
39 return positionUnaryMeasurementPtr_->unaryMeasurementNoiseDensity();
40 }
41
42 // Return Measurement as GTSAM Datatype
43 [[nodiscard]] const gtsam::Point3 getGtsamMeasurementValue() const override {
44 return gtsam::Point3(positionUnaryMeasurementPtr_->unaryMeasurement().matrix());
45 }
46
47 protected:
48 // i) Generate Expression for Basic IMU State in World Frame at Key -------------------------------------
49 void generateImuStateInWorldFrameAtKey(const gtsam::Key& closestGeneralKey) final {
50 // Translation (core part)
52 gtsam::translation(gtsam::Expression<gtsam::Pose3>(gtsam::symbol_shorthand::X(closestGeneralKey))); // W_t_W_I at this point
53
54 // Rotation (needed for the transformation to the sensor frame)
56 gtsam::rotation(gtsam::Expression<gtsam::Pose3>(gtsam::symbol_shorthand::X(closestGeneralKey))); // R_W_I at this point
57 }
58
59 // Interface with three cases (non-exclusive):
60 // ii) Holistically Optimize over Fixed Frames -----------------------------------------------------------
61 gtsam::Pose3 computeT_W_fixedFrame_initial(const gtsam::NavState& W_currentPropagatedState) final {
62 gtsam::Pose3 T_fixedFrame_sensorFrame_meas_noOrientation =
63 gtsam::Pose3(gtsam::Rot3::Identity(), positionUnaryMeasurementPtr_->unaryMeasurement());
64 gtsam::Pose3 T_W_sensorFrame_est = W_currentPropagatedState.pose() * gtsam::Pose3(T_I_sensorFrameInit_.matrix());
65 return T_W_sensorFrame_est * T_fixedFrame_sensorFrame_meas_noOrientation.inverse(); // TODO: Does not yet include orientation
66 }
67
68 bool measuresPosition() const final { return true; }
69
70 const Eigen::Vector3d getMeasurementPosition() final {
71 // Get Measurement
72 return positionUnaryMeasurementPtr_->unaryMeasurement();
73 }
74
75 void setMeasurementPosition(const Eigen::Vector3d& position) final {
76 // Set Measurement
77 positionUnaryMeasurementPtr_->unaryMeasurement() = position;
78 }
79
80 void transformStateToReferenceFrameMeasurement(const gtsam::Pose3_& exp_T_W_fixedFrame) override {
81 // Transform state to fixed frame
83 gtsam::transformTo(exp_T_W_fixedFrame, exp_fixedFrame_t_fixedFrame_sensorFrame_); // T_fixedFrame_I at this point
84
85 // Transform rotation from world to fixed frame
86 exp_R_fixedFrame_I_ = inverseRot3(gtsam::rotation(exp_T_W_fixedFrame)) * exp_R_fixedFrame_I_; // R_fixedFrame_I at this point
87 }
88
89 // iii) Transform Measurement to Core Imu Frame -----------------------------------------------------------
91 // Get relative translation
92 Eigen::Vector3d I_t_I_sensorFrame = T_I_sensorFrameInit_.translation();
93
94 // Rotation of IMU frame
97 gtsam::rotate(exp_R_fixedFrame_I_, I_t_I_sensorFrame); // fixedFrame_t_fixedFrame_sensorFrameInit
98 }
99
100 // iv) Extrinsic Calibration ---------------------------------------------------------------------
101 void applyExtrinsicCalibrationCorrection(const gtsam::Point3_& exp_sensorFrame_t_sensorFrame_correctSensorFrame) final {
102 // Apply Correction
103 gtsam::Rot3_ exp_R_fixedFrame_sensorFrame = exp_R_fixedFrame_I_ * gtsam::Rot3_(gtsam::Rot3(T_I_sensorFrameInit_.rotation()));
106 gtsam::rotate(exp_R_fixedFrame_sensorFrame,
107 exp_sensorFrame_t_sensorFrame_correctSensorFrame); // fixedFrame_t_fixedFrame_sensorFrameCorrected
108 }
109
110 gtsam::Pose3 convertToPose3(const gtsam::Point3& measurement) final { return gtsam::Pose3(gtsam::Rot3::Identity(), measurement); }
111
112 gtsam::Point3 convertFromPose3(const gtsam::Pose3& measurement) final { return measurement.translation(); }
113
114 // Return Expression
115 [[nodiscard]] const gtsam::Expression<gtsam::Point3> getGtsamExpression() const override {
117 }
118
119 private:
120 // Full Measurement Type
121 std::shared_ptr<UnaryMeasurementXDAbsolute<Eigen::Vector3d, 3>> positionUnaryMeasurementPtr_;
122
123 // Expression
124 gtsam::Expression<gtsam::Point3> exp_fixedFrame_t_fixedFrame_sensorFrame_; // Translation
125 gtsam::Expression<gtsam::Rot3> exp_R_fixedFrame_I_; // Rotation
126};
127} // namespace holistic_fusion
128
129#endif // GMSF_UNARY_EXPRESSION_POSITION3_H
GmsfUnaryExpressionAbsolut(const std::shared_ptr< UnaryMeasurementAbsolute > &gmsfUnaryAbsoluteMeasurementPtr, const std::string &imuFrameName, const Eigen::Isometry3d &T_I_sensorFrame, const double createReferenceAlignmentKeyframeEveryNSeconds)
void applyExtrinsicCalibrationCorrection(const gtsam::Point3_ &exp_sensorFrame_t_sensorFrame_correctSensorFrame) final
gtsam::Point3 convertFromPose3(const gtsam::Pose3 &measurement) final
GmsfUnaryExpressionAbsolutePosition3(const std::shared_ptr< UnaryMeasurementXDAbsolute< Eigen::Vector3d, 3 > > &positionUnaryMeasurementPtr, const std::string &imuFrameName, const Eigen::Isometry3d &T_I_sensorFrame, const double createReferenceAlignmentKeyframeEveryNSeconds)
void transformStateToReferenceFrameMeasurement(const gtsam::Pose3_ &exp_T_W_fixedFrame) override
gtsam::Pose3 computeT_W_fixedFrame_initial(const gtsam::NavState &W_currentPropagatedState) final
void generateImuStateInWorldFrameAtKey(const gtsam::Key &closestGeneralKey) final
std::shared_ptr< UnaryMeasurementXDAbsolute< Eigen::Vector3d, 3 > > positionUnaryMeasurementPtr_
const gtsam::Expression< gtsam::Point3 > getGtsamExpression() const override
gtsam::Pose3 convertToPose3(const gtsam::Point3 &measurement) final
Class to represent x-dimensional absolute unary measurement in the graph.
gtsam::Rot3_ inverseRot3(const gtsam::Rot3_ &R)