MSCEqF 1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Loading...
Searching...
No Matches
updater_helper.hpp
1// Copyright (C) 2023 Alessandro Fornasier.
2// Control of Networked Systems, University of Klagenfurt, Austria.
3//
4// All rights reserved.
5//
6// This software is licensed under the terms of the BSD-2-Clause-License with
7// no commercial use allowed, the full terms of which are made available
8// in the LICENSE file. No license in patents is granted.
9//
10// You can contact the authors at <alessandro.fornasier@ieee.org>
11
12#ifndef UPDATER_HELPER_HPP
13#define UPDATER_HELPER_HPP
14
15#include <opencv2/opencv.hpp>
16#include <functional>
17#include <boost/math/distributions/chi_squared.hpp>
18
19#include "types/fptypes.hpp"
20#include "msceqf/state/state.hpp"
21#include "utils/tools.hpp"
22
23namespace msceqf
24{
25using MatrixXBlockRowRef = Ref<MatrixX::RowsBlockXpr>;
26using VectorXBlockRowRef = Ref<VectorX::RowsBlockXpr>;
27
29
36{
38 const Vector3& A_f, const Vector2& uv, const Vector2& uvn, const fp& anchor_timestamp, const fp& clone_timestamp)
39 : A_f_(A_f), uv_(uv), uvn_(uvn), anchor_timestamp_(anchor_timestamp), clone_timestamp_(clone_timestamp){};
40
41 const Vector3& A_f_;
42 const Vector2& uv_;
43 const Vector2& uvn_;
45 const fp& clone_timestamp_;
46};
47
54{
55 public:
56 virtual ~ProjectionHelper() = default;
57
64 [[nodiscard]] virtual Vector3 pi(const Vector3& f) = 0;
65
72 [[nodiscard]] virtual MatrixX dpi(const Vector3& f) = 0;
73
85 virtual void residualJacobianBlock(const MSCEqFState& X,
86 const SystemState& xi0,
87 const FeatHelper& feat,
88 MatrixXBlockRowRef C_block_row,
89 VectorXBlockRowRef delta_block_row,
90 MatrixXBlockRowRef Cf_block_row,
91 const ColsMap& cols_map) = 0;
92
98 [[nodiscard]] const size_t& block_rows() const { return block_rows_; }
99
105 [[nodiscard]] const size_t& dim_loss() const { return dim_loss_; }
106
107 protected:
109 ProjectionHelper(const FeatureRepresentation& feature_representation);
110 ProjectionHelper(const ProjectionHelper&) = default;
112 ProjectionHelper& operator=(const ProjectionHelper&) = default;
113 ProjectionHelper& operator=(ProjectionHelper&&) = default;
114
115 FeatureRepresentation feature_representation_;
116
117 size_t block_rows_;
118 size_t dim_loss_;
119};
120
127{
128 public:
129 ProjectionHelperS2(const FeatureRepresentation& feature_representation) : ProjectionHelper(feature_representation)
130 {
131 block_rows_ = 3;
132 }
133
140 [[nodiscard]] Vector3 pi(const Vector3& f) override;
141
148 [[nodiscard]] MatrixX dpi(const Vector3& f) override;
149
162 const SystemState& xi0,
163 const FeatHelper& feat,
164 MatrixXBlockRowRef C_block_row,
165 VectorXBlockRowRef delta_block_row,
166 MatrixXBlockRowRef Cf_block_row,
167 const ColsMap& cols_map) override;
168};
169
176{
177 public:
178 ProjectionHelperZ1(const FeatureRepresentation& feature_representation) : ProjectionHelper(feature_representation)
179 {
180 block_rows_ = 2;
181 }
182
189 [[nodiscard]] Vector3 pi(const Vector3& f) override;
190
197 [[nodiscard]] MatrixX dpi(const Vector3& f) override;
198
211 const SystemState& xi0,
212 const FeatHelper& feat,
213 MatrixXBlockRowRef C_block_row,
214 VectorXBlockRowRef delta_block_row,
215 MatrixXBlockRowRef Cf_block_row,
216 const ColsMap& cols_map) override;
217};
218
219using ProjectionHelperSharedPtr = std::shared_ptr<ProjectionHelper>;
220using ProjectionHelperUniquePtr = std::unique_ptr<ProjectionHelper>;
221using ProjectionHelperZ1SharedPtr = std::shared_ptr<ProjectionHelperZ1>;
222using ProjectionHelperZ1UniquePtr = std::unique_ptr<ProjectionHelperZ1>;
223using ProjectionHelperS2SharedPtr = std::shared_ptr<ProjectionHelperS2>;
224using ProjectionHelperS2UniquePtr = std::unique_ptr<ProjectionHelperS2>;
225
232template <typename T>
233[[nodiscard]] static ProjectionHelperUniquePtr createProjectionHelper(
234 const FeatureRepresentation& feature_representation)
235{
236 if constexpr (std::is_base_of_v<ProjectionHelper, T>)
237 {
238 return std::make_unique<T>(feature_representation);
239 }
240 else
241 {
242 return nullptr;
243 }
244}
245
252{
259 [[nodiscard]] static Matrix<2, 4> Xi(const Vector3& f);
260
267 [[nodiscard]] static Matrix3 inverseDepthJacobian(const Vector3& A_f);
268
277 static void nullspaceProjection(Ref<MatrixX> Cf, MatrixXBlockRowRef Ct, VectorXBlockRowRef delta);
278
285 static void updateQRCompression(MatrixX& C, VectorX& delta);
286
295 [[nodiscard]] static bool chi2Test(const fp& chi2, const size_t& dof, const std::map<uint, fp>& chi2_table);
296};
297
298} // namespace msceqf
299
300#endif // UPDATER_HELPER_HPP
this class represent the state of the MSCEqF. This includes the state of the lifted system (element o...
Definition state.hpp:30
ProjectionHelper interface. This class provides an interface to the implementation of the projection ...
Definition updater_helper.hpp:54
size_t block_rows_
Number of rows of a C matrix block and a residual block.
Definition updater_helper.hpp:117
size_t dim_loss_
Dimension lost due to nullspace projection.
Definition updater_helper.hpp:118
const size_t & dim_loss() const
Get the dimension lost due to nullspace projection.
Definition updater_helper.hpp:105
ProjectionHelper(const FeatureRepresentation &feature_representation)
Rule of 5.
virtual MatrixX dpi(const Vector3 &f)=0
Projection differential function. This function computes the differential of the projection function.
virtual void residualJacobianBlock(const MSCEqFState &X, const SystemState &xi0, const FeatHelper &feat, MatrixXBlockRowRef C_block_row, VectorXBlockRowRef delta_block_row, MatrixXBlockRowRef Cf_block_row, const ColsMap &cols_map)=0
Computes a block row of the C matrix and a block of the residual, corresponding to the given feature ...
const size_t & block_rows() const
Get the number of rows of a C matrix block and a residual block.
Definition updater_helper.hpp:98
FeatureRepresentation feature_representation_
Feature representation.
Definition updater_helper.hpp:115
virtual Vector3 pi(const Vector3 &f)=0
Projection function. This function projects a 3D point.
ProjectionHelperS2 class. This class provides an implementation of the projection on the unit sphere ...
Definition updater_helper.hpp:127
MatrixX dpi(const Vector3 &f) override
Projection differential function. This function computes the differential of the projection function.
Vector3 pi(const Vector3 &f) override
Projection function. This function projects a 3D point on the unit sphere.
void residualJacobianBlock(const MSCEqFState &X, const SystemState &xi0, const FeatHelper &feat, MatrixXBlockRowRef C_block_row, VectorXBlockRowRef delta_block_row, MatrixXBlockRowRef Cf_block_row, const ColsMap &cols_map) override
Computes a block row of the C matrix and a block of the residual, corresponding to the given feature ...
ProjectionHelperZ1 class. This class provides an implementation of the projection on the unit plane a...
Definition updater_helper.hpp:176
MatrixX dpi(const Vector3 &f) override
Projection differential function. This function computes the differential of the projection function.
void residualJacobianBlock(const MSCEqFState &X, const SystemState &xi0, const FeatHelper &feat, MatrixXBlockRowRef C_block_row, VectorXBlockRowRef delta_block_row, MatrixXBlockRowRef Cf_block_row, const ColsMap &cols_map) override
Computes a block row of the C matrix and a block of the residual, corresponding to the given feature ...
Vector3 pi(const Vector3 &f) override
Projection function. This function projects a 3D point on the unit plane.
The SystemState class represent the state of the system posed on the Homogenous space.
Definition system.hpp:29
This calss define a map that keeps the insertion order.
Definition tools.hpp:34
FeatHelper struct. This struct implements a helper structure holding all the information related to a...
Definition updater_helper.hpp:36
const Vector3 & A_f_
Triangulated feature in anchor frame.
Definition updater_helper.hpp:41
const Vector2 & uv_
(measured) feature coordinates
Definition updater_helper.hpp:42
const fp & anchor_timestamp_
Timestamp of the anchor.
Definition updater_helper.hpp:44
const fp & clone_timestamp_
Timestamp of the feature measurement.
Definition updater_helper.hpp:45
const Vector2 & uvn_
Normalized (measured) feature coordinates.
Definition updater_helper.hpp:43
Updater helper struct. This structs implements common helper methods for MSCEqF update.
Definition updater_helper.hpp:252
static Matrix< 2, 4 > Xi(const Vector3 &f)
Xi operator R^3 -> R^2x4.
static Matrix3 inverseDepthJacobian(const Vector3 &A_f)
Compute the Jacobian for inverse depth parametrization, used in the Cf matrix.
static bool chi2Test(const fp &chi2, const size_t &dof, const std::map< uint, fp > &chi2_table)
Perform chi2 test (based on precomputed table) on the given block of the residual.
static void nullspaceProjection(Ref< MatrixX > Cf, MatrixXBlockRowRef Ct, VectorXBlockRowRef delta)
Perform in-place nullspace projection of the Cf matrix on the Ct matrix and the residual using QR dec...
static void updateQRCompression(MatrixX &C, VectorX &delta)
Perform in-place compression of the C matrix and the residual using QR decomposition.