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 Apache License, Version 2.0
7// (the "License"); you may not use this file except in compliance with the
8// License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15// License for the specific language governing permissions and limitations
16// under the License.
17//
18// You can contact the authors at <alessandro.fornasier@ieee.org>
19
20#ifndef UPDATER_HELPER_HPP
21#define UPDATER_HELPER_HPP
22
23#include <opencv2/opencv.hpp>
24#include <functional>
25#include <boost/math/distributions/chi_squared.hpp>
26
27#include "types/fptypes.hpp"
28#include "msceqf/state/state.hpp"
29#include "utils/tools.hpp"
30
31namespace msceqf
32{
33using MatrixXBlockRowRef = Ref<MatrixX::RowsBlockXpr>;
34using VectorXBlockRowRef = Ref<VectorX::RowsBlockXpr>;
35
36using ColsMap = utils::InsertionOrderedMap<MSCEqFState::MSCEqFKey, size_t>;
37
43struct FeatHelper
44{
45 FeatHelper(
46 const Vector3& A_f, const Vector2& uv, const Vector2& uvn, const fp& anchor_timestamp, const fp& clone_timestamp)
47 : A_f_(A_f), uv_(uv), uvn_(uvn), anchor_timestamp_(anchor_timestamp), clone_timestamp_(clone_timestamp){};
48
49 const Vector3& A_f_;
50 const Vector2& uv_;
51 const Vector2& uvn_;
53 const fp& clone_timestamp_;
54};
55
62{
63 public:
64 virtual ~ProjectionHelper() = default;
65
72 [[nodiscard]] virtual Vector3 pi(const Vector3& f) = 0;
73
80 [[nodiscard]] virtual MatrixX dpi(const Vector3& f) = 0;
81
93 virtual void residualJacobianBlock(const MSCEqFState& X,
94 const SystemState& xi0,
95 const FeatHelper& feat,
96 MatrixXBlockRowRef C_block_row,
97 VectorXBlockRowRef delta_block_row,
98 MatrixXBlockRowRef Cf_block_row,
99 const ColsMap& cols_map) = 0;
100
106 [[nodiscard]] const size_t& block_rows() const { return block_rows_; }
107
113 [[nodiscard]] const size_t& dim_loss() const { return dim_loss_; }
114
115 protected:
117 ProjectionHelper(const FeatureRepresentation& feature_representation);
118 ProjectionHelper(const ProjectionHelper&) = default;
120 ProjectionHelper& operator=(const ProjectionHelper&) = default;
121 ProjectionHelper& operator=(ProjectionHelper&&) = default;
122
123 FeatureRepresentation feature_representation_;
124
125 size_t block_rows_;
126 size_t dim_loss_;
127};
128
134class ProjectionHelperS2 : public ProjectionHelper
135{
136 public:
137 ProjectionHelperS2(const FeatureRepresentation& feature_representation) : ProjectionHelper(feature_representation)
138 {
139 block_rows_ = 3;
140 }
141
148 [[nodiscard]] Vector3 pi(const Vector3& f) override;
149
156 [[nodiscard]] MatrixX dpi(const Vector3& f) override;
157
170 const SystemState& xi0,
171 const FeatHelper& feat,
172 MatrixXBlockRowRef C_block_row,
173 VectorXBlockRowRef delta_block_row,
174 MatrixXBlockRowRef Cf_block_row,
175 const ColsMap& cols_map) override;
176};
177
183class ProjectionHelperZ1 : public ProjectionHelper
184{
185 public:
186 ProjectionHelperZ1(const FeatureRepresentation& feature_representation) : ProjectionHelper(feature_representation)
187 {
188 block_rows_ = 2;
189 }
190
197 [[nodiscard]] Vector3 pi(const Vector3& f) override;
198
205 [[nodiscard]] MatrixX dpi(const Vector3& f) override;
206
219 const SystemState& xi0,
220 const FeatHelper& feat,
221 MatrixXBlockRowRef C_block_row,
222 VectorXBlockRowRef delta_block_row,
223 MatrixXBlockRowRef Cf_block_row,
224 const ColsMap& cols_map) override;
225};
226
227using ProjectionHelperSharedPtr = std::shared_ptr<ProjectionHelper>;
228using ProjectionHelperUniquePtr = std::unique_ptr<ProjectionHelper>;
229using ProjectionHelperZ1SharedPtr = std::shared_ptr<ProjectionHelperZ1>;
230using ProjectionHelperZ1UniquePtr = std::unique_ptr<ProjectionHelperZ1>;
231using ProjectionHelperS2SharedPtr = std::shared_ptr<ProjectionHelperS2>;
232using ProjectionHelperS2UniquePtr = std::unique_ptr<ProjectionHelperS2>;
233
240template <typename T>
241[[nodiscard]] static ProjectionHelperUniquePtr createProjectionHelper(
242 const FeatureRepresentation& feature_representation)
243{
244 if constexpr (std::is_base_of_v<ProjectionHelper, T>)
245 {
246 return std::make_unique<T>(feature_representation);
247 }
248 else
249 {
250 return nullptr;
251 }
252}
253
260{
267 [[nodiscard]] static Matrix<2, 4> Xi(const Vector3& f);
268
275 [[nodiscard]] static Matrix3 inverseDepthJacobian(const Vector3& A_f);
276
285 static void nullspaceProjection(Ref<MatrixX> Cf, MatrixXBlockRowRef Ct, VectorXBlockRowRef delta);
286
293 static void updateQRCompression(MatrixX& C, VectorX& delta);
294
303 [[nodiscard]] static bool chi2Test(const fp& chi2, const size_t& dof, const std::map<uint, fp>& chi2_table);
304};
305
306} // namespace msceqf
307
308#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:38
size_t block_rows_
Number of rows of a C matrix block and a residual block.
Definition updater_helper.hpp:125
size_t dim_loss_
Dimension lost due to nullspace projection.
Definition updater_helper.hpp:126
const size_t & dim_loss() const
Get the dimension lost due to nullspace projection.
Definition updater_helper.hpp:113
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:106
FeatureRepresentation feature_representation_
Feature representation.
Definition updater_helper.hpp:123
virtual Vector3 pi(const Vector3 &f)=0
Projection function. This function projects a 3D point.
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 ...
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:37
FeatHelper struct. This struct implements a helper structure holding all the information related to a...
Definition updater_helper.hpp:44
const Vector3 & A_f_
Triangulated feature in anchor frame.
Definition updater_helper.hpp:49
const Vector2 & uv_
(measured) feature coordinates
Definition updater_helper.hpp:50
const fp & anchor_timestamp_
Timestamp of the anchor.
Definition updater_helper.hpp:52
const fp & clone_timestamp_
Timestamp of the feature measurement.
Definition updater_helper.hpp:53
const Vector2 & uvn_
Normalized (measured) feature coordinates.
Definition updater_helper.hpp:51
Updater helper struct. This structs implements common helper methods for MSCEqF update.
Definition updater_helper.hpp:260
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.