My Project 1.0
Holistic Fusion: A Generic Framework for Multimodal Sensor Fusion
Loading...
Searching...
No Matches
unaryRollFactor.h
Go to the documentation of this file.
1/*
2Copyright 2022 by Julian Nubert, Timo Schoenegg, 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 HOLISTIC_FUSION_ROLL_FACTOR_H
9#define HOLISTIC_FUSION_ROLL_FACTOR_H
10
11// C++
12#include <cmath>
13
14// GTSAM
15#include <gtsam/base/OptionalJacobian.h>
16#include <gtsam/base/Vector.h>
17#include <gtsam/geometry/Pose3.h>
18#include <gtsam/inference/Key.h>
19#include <gtsam/linear/NoiseModel.h>
20#include <gtsam/nonlinear/NoiseModelFactorN.h>
21
22namespace holistic_fusion {
23
27class RollFactor : public gtsam::NoiseModelFactorN<gtsam::Pose3> {
28 public:
29 using Base = gtsam::NoiseModelFactorN<gtsam::Pose3>;
30 // Bring the convenience overloads (without Jacobian, with Jacobian by reference) into scope
31 using Base::evaluateError;
32
39 RollFactor(gtsam::Key j, double roll, const gtsam::SharedNoiseModel& model) : Base(model, j), roll_(roll) {}
40
41 // Destructor
42 ~RollFactor() override = default;
43
48 gtsam::Vector evaluateError(const gtsam::Pose3& robotPose, gtsam::OptionalMatrixType H_Ptr = OptionalNone) const override {
49 // If close to singularity, do not add measurement
50 if (std::abs(robotPose.rotation().roll()) >= M_PI / 2.0 - 0.1) {
51 if (H_Ptr) {
52 (*H_Ptr) = gtsam::Matrix::Zero(1, 6);
53 }
54 return gtsam::Vector1::Zero();
55 }
56
57 // Measurement function (with Jacobian w.r.t. the rotation only if requested)
58 gtsam::Matrix13 H_rot;
59 const double estimatedRoll = H_Ptr ? robotPose.rotation().roll(H_rot) : robotPose.rotation().roll();
60
61 // Calculate error
62 double rollError = estimatedRoll - roll_;
63
64 // Smaller half circle
65 while (rollError < -M_PI) rollError += 2 * M_PI;
66 while (rollError > M_PI) rollError -= 2 * M_PI;
67
68 // Jacobian: Pose3 tangent space is [rotation (3), translation (3)] --> [rad] [m]
69 if (H_Ptr) {
70 (*H_Ptr) = gtsam::Matrix::Zero(1, 6);
71 H_Ptr->block<1, 3>(0, 0) = H_rot;
72 }
73
74 return gtsam::Vector1(rollError);
75 }
76
77 private:
78 double roll_; // roll measurement
79};
80
81} // namespace holistic_fusion
82
83#endif // HOLISTIC_FUSION_ROLL_FACTOR_H
gtsam::Vector evaluateError(const gtsam::Pose3 &robotPose, gtsam::OptionalMatrixType H_Ptr=OptionalNone) const override
vector of errors
gtsam::NoiseModelFactorN< gtsam::Pose3 > Base
RollFactor(gtsam::Key j, double roll, const gtsam::SharedNoiseModel &model)
~RollFactor() override=default