My Project 1.0
Holistic Fusion: A Generic Framework for Multimodal Sensor Fusion
Loading...
Searching...
No Matches
HolisticFusionClassic.cpp
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// CPP
9#include <stdexcept>
10
11// Implementation
13
14// Workspace
16
17// Unary Factors
21
22namespace holistic_fusion {
23
24// Constructor
26 REGULAR_COUT << GREEN_START << " HolisticFusionClassic-Constructor called." << COLOR_END << std::endl;
27}
28
29// Unary ----------------------------
31 // Only take actions if graph has been initialized
32 if (!initedGraphFlag_) {
33 return;
34 }
35
36 // Check for covariance violation
37 bool covarianceViolatedFlag =
39
40 // The factor evaluates the yaw on the measurement frame, so it needs the rotation of that frame in the IMU frame
41 const gtsam::Rot3 R_I_frame =
42 gtsam::Rot3(staticTransformsPtr_->rv_T_frame1_frame2(yaw_W_frame.sensorFrameName(), staticTransformsPtr_->getImuFrame()).rotation())
43 .inverse();
44
45 // Add factor
46 if (!covarianceViolatedFlag) {
47 graphMgrPtr_->addUnaryClassicFactor<double, 1, YawFactor, gtsam::symbol_shorthand::X>(
48 yaw_W_frame.unaryMeasurement(), yaw_W_frame.unaryMeasurementNoiseDensity(), yaw_W_frame.timeK(), R_I_frame);
49 {
50 // Mutex for optimizeGraph Flag
51 const std::lock_guard<std::mutex> optimizeGraphLock(optimizeGraphMutex_);
52 optimizeGraphFlag_ = true;
53 }
54 } else {
55 std::cout << YELLOW_START << "GMsf-Classic" << RED_START
56 << " Covariance violation detected in yaw unary measurement at time " << yaw_W_frame.timeK()
57 << ". Measurement not added to graph." << COLOR_END << std::endl;
58 }
59}
60
62 // Only take actions if graph has been initialized
63 if (!initedGraphFlag_) {
64 return;
65 }
66
67 // Check for covariance violation
68 bool covarianceViolatedFlag =
70
71 // Transform roll to imu frame
72 gtsam::Rot3 rollR_W_frame = gtsam::Rot3::Roll(roll_W_frame.unaryMeasurement());
73 gtsam::Rot3 rollR_W_I =
74 rollR_W_frame *
75 gtsam::Rot3(staticTransformsPtr_->rv_T_frame1_frame2(roll_W_frame.sensorFrameName(), staticTransformsPtr_->getImuFrame()).rotation());
76
77 // Add factor
78 if (!covarianceViolatedFlag) {
79 graphMgrPtr_->addUnaryClassicFactor<double, 1, RollFactor, gtsam::symbol_shorthand::X>(
80 rollR_W_I.roll(), roll_W_frame.unaryMeasurementNoiseDensity(), roll_W_frame.timeK());
81 {
82 // Mutex for optimizeGraph Flag
83 const std::lock_guard<std::mutex> optimizeGraphLock(optimizeGraphMutex_);
84 optimizeGraphFlag_ = true;
85 }
86 } else {
87 std::cout << YELLOW_START << "GMsf-Classic" << RED_START
88 << " Covariance violation detected in roll unary measurement at time " << roll_W_frame.timeK()
89 << ". Measurement not added to graph." << COLOR_END << std::endl;
90 }
91}
92
94 // Only take actions if graph has been initialized
95 if (!initedGraphFlag_) {
96 return;
97 }
98
99 // Check for covariance violation
100 bool covarianceViolatedFlag =
102
103 // Transform pitch to imu frame
104 gtsam::Rot3 pitchR_W_frame = gtsam::Rot3::Pitch(pitch_W_frame.unaryMeasurement());
105 gtsam::Rot3 pitchR_W_I =
106 pitchR_W_frame *
107 gtsam::Rot3(staticTransformsPtr_->rv_T_frame1_frame2(pitch_W_frame.sensorFrameName(), staticTransformsPtr_->getImuFrame()).rotation());
108
109 // Add factor
110 if (!covarianceViolatedFlag) {
111 graphMgrPtr_->addUnaryClassicFactor<double, 1, PitchFactor, gtsam::symbol_shorthand::X>(
112 pitchR_W_I.pitch(), pitch_W_frame.unaryMeasurementNoiseDensity(), pitch_W_frame.timeK());
113 {
114 // Mutex for optimizeGraph Flag
115 const std::lock_guard<std::mutex> optimizeGraphLock(optimizeGraphMutex_);
116 optimizeGraphFlag_ = true;
117 }
118 } else {
119 std::cout << YELLOW_START << "GMsf-Classic" << RED_START
120 << " Covariance violation detected in pitch unary measurement at time " << pitch_W_frame.timeK()
121 << ". Measurement not added to graph." << COLOR_END << std::endl;
122 }
123}
124
125// Binary ----------------------------
126// Binary Measurements
128 // Valid measurement received
131 }
132
133 // Only take actions if graph has been initialized
134 if (!initedGraphFlag_) {
135 return;
136 }
137
138 Eigen::Isometry3d T_fkm1_fk = deltaMeasurement.deltaMeasurement();
139
140 // Check frame of measuremnts
141 if (deltaMeasurement.measurementName() != staticTransformsPtr_->getImuFrame()) {
142 T_fkm1_fk = staticTransformsPtr_->rv_T_frame1_frame2(staticTransformsPtr_->getImuFrame(), deltaMeasurement.sensorFrameName()) *
143 T_fkm1_fk *
144 staticTransformsPtr_->rv_T_frame1_frame2(deltaMeasurement.sensorFrameName(), staticTransformsPtr_->getImuFrame());
145 }
146
147 static_cast<void>(graphMgrPtr_->addPoseBetweenFactor(
148 gtsam::Pose3(T_fkm1_fk.matrix()), deltaMeasurement.measurementNoiseDensity(), deltaMeasurement.timeKm1(), deltaMeasurement.timeK(),
149 deltaMeasurement.measurementRate(), deltaMeasurement.robustNormEnum(), deltaMeasurement.robustNormConstant()));
150
151 // Optimize
152 {
153 // Mutex for optimizeGraph Flag
154 const std::lock_guard<std::mutex> optimizeGraphLock(optimizeGraphMutex_);
155 optimizeGraphFlag_ = true;
156 }
157}
158
159} // namespace holistic_fusion
#define REGULAR_COUT
#define COLOR_END
#define GREEN_START
#define RED_START
#define YELLOW_START
const MEASUREMENT_TYPE & deltaMeasurement() const
const Eigen::Matrix< double, DIM, 1 > & measurementNoiseDensity() const
void addUnaryYawAbsoluteMeasurement(const UnaryMeasurementXDAbsolute< double, 1 > &yaw_W_S) override
void addUnaryRollAbsoluteMeasurement(const UnaryMeasurementXDAbsolute< double, 1 > &roll_F_S) override
Unary Measurements / Absolute Measurements.
void addUnaryPitchAbsoluteMeasurement(const UnaryMeasurementXDAbsolute< double, 1 > &pitch_F_S) override
void addBinaryPose3Measurement(const BinaryMeasurementXD< Eigen::Isometry3d, 6 > &F_T_F_S) override
Binary Measurements.
std::shared_ptr< GraphManager > graphMgrPtr_
std::shared_ptr< StaticTransforms > staticTransformsPtr_
bool isCovarianceViolated_(const Eigen::Matrix< double, DIM, 1 > &covariance, const double covarianceViolationThreshold)
Convenience functions.
const std::string & sensorFrameName() const
Definition Measurement.h:83
const RobustNormEnum & robustNormEnum() const
Definition Measurement.h:88
const double & robustNormConstant() const
Definition Measurement.h:89
int measurementRate() const
Rest.
Definition Measurement.h:86
const std::string & measurementName() const
Names.
Definition Measurement.h:82
Class to represent x-dimensional absolute unary measurement in the graph.
const Eigen::Matrix< double, DIM, 1 > & unaryMeasurementNoiseDensity() const
const MEASUREMENT_TYPE & unaryMeasurement() const