MSCEqF 1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Loading...
Searching...
No Matches
msceqf_option_parser.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 OPTIONS_PARSER_HPP
13#define OPTIONS_PARSER_HPP
14
15#include <yaml-cpp/yaml.h>
16
17#include <numeric>
18#include <sstream>
19#include <opencv2/opencv.hpp>
20
21#include "msceqf/options/msceqf_options.hpp"
22#include "types/fptypes.hpp"
23#include "utils/logger.hpp"
24#include "utils/tools.hpp"
25
26namespace msceqf
27{
29 {
30 public:
36 OptionParser(const std::string &filepath);
37
44
45 private:
58 template <int Rows, int Cols>
59 [[nodiscard]] bool read(Matrix<Rows, Cols> &x, const std::string &param)
60 {
61 if (node_[param])
62 {
63 using vector = std::vector<fp>;
64 using vectorvector = std::vector<std::vector<fp>>;
65
66 int rows = Rows;
67 int cols = Cols;
68
69 if constexpr (Rows == 1 || Cols == 1)
70 {
71 vector vec = node_[param].as<vector>();
72 if constexpr (Rows == -1)
73 {
74 rows = vec.size();
75 }
76 else if (Cols == -1)
77 {
78 cols = vec.size();
79 }
80 x = Map<Matrix<Rows, Cols>>(vec.data(), rows, cols);
81 }
82 else
83 {
84 vectorvector mat = node_[param].as<vectorvector>();
85 vector vec = utils::flatten(mat);
86 if constexpr (Rows == 1 && Cols == 1)
87 {
88 rows = mat.size();
89 cols = vec.size() / mat.size();
90 }
91 x = Map<Matrix<Rows, Cols, Eigen::RowMajor>>(vec.data(), rows, cols);
92 }
93 if constexpr (Rows == 1)
94 {
95 utils::Logger::info("Parameter: [" + param + "] found. Option set to:" +
96 (std::ostringstream{} << x).str());
97 }
98 else if (Cols == 1)
99 {
100 utils::Logger::info("Parameter: [" + param + "] found. Option set to: " +
101 (std::ostringstream{} << x.transpose()).str());
102 }
103 else
104 {
105 utils::Logger::info("Parameter: [" + param + "] found. Option set to: \n" +
106 (std::ostringstream{} << x).str());
107 }
108
109 return true;
110 }
111 utils::Logger::warn("Parameter: [" + param + "] not found");
112 return false;
113 }
114
125 template <typename Scalar>
126 [[nodiscard]] bool read(Quaternion &q, const std::string &param)
127 {
128 if (node_[param])
129 {
130 using vector = std::vector<fp>;
131 vector vec = node_[param].as<vector>();
132 q = Quaternion(vec).normalize();
133 utils::Logger::info("Parameter: [" + param + "] found. Option set to: \n" +
134 (std::ostringstream{} << q).str());
135 return true;
136 }
137 utils::Logger::warn("Parameter: [" + param + "] not found");
138 return false;
139 }
140
149 template <typename T>
150 [[nodiscard]] bool read(T &p, const std::string &param)
151 {
152 if (node_[param])
153 {
154 p = node_[param].as<T>();
155 utils::Logger::info("Parameter: [" + param + "] found. Option set to: " +
156 (std::ostringstream{} << p).str());
157 return true;
158 }
159 utils::Logger::warn("Parameter: [" + param + "] not found");
160 return false;
161 }
162
163 template <typename T, typename Convertible>
164 void readDefault(T &p, const Convertible &def, const std::string &param)
165 {
166 static_assert(std::is_convertible_v<Convertible, T>);
167 if (!read(p, param))
168 {
169 p = def;
170 utils::Logger::warn("Parameter: [" + param + "] set to default value: " +
171 (std::ostringstream{} << p).str());
172 }
173 }
174
188 void parseCameraParameters(SE3 &extrinsics,
189 In &intrinsics,
190 DistortionModel &distortion_model,
191 VectorX &distortion_coefficients,
192 Vector2 &resolution,
193 fp &timeshift_cam_imu,
194 cv::Mat &mask,
195 MaskType &mask_type);
196
204 void parseGivenOrigin(SE23 &T, Vector6 &b, fp &t0);
205
211 void parseEqualizationMethod(EqualizationMethod &eq);
212
218 void parseFeatureRepresentation(FeatureRepresentation &rep);
219
225 void parseProjectionMethod(ProjectionMethod &proj);
226
232 void parseDetectorType(FeatureDetector &detector);
233
243 void parseInitialCovariance(Matrix9 &D_cov, Matrix6 &delta_cov, Matrix6 &E_cov, Matrix4 &L_cov);
244
253 void parseProcessNoise(fp &w_std, fp &a_std, fp &bw_std, fp &ba_std);
254
262 void parsePixStd(fp &pix_std, const StateOptions &opts);
263
269 void parseZeroVelocityUpdate(ZeroVelocityUpdate &zvu);
270
271 YAML::Node node_;
272 std::string filepath_;
273 };
274
275} // namespace msceqf
276
277#endif // OPTIONS_HPP
Definition msceqf_option_parser.hpp:29
MSCEqFOptions parseOptions()
Parse oprion and create MSCEqFOptions struct.
OptionParser(const std::string &filepath)
Option parser constructor.
static void warn(const T &msg)
Format a warn message and log it in yellow.
Definition logger.hpp:100
static void info(const T &msg)
Format a info message and log it in white.
Definition logger.hpp:67
Definition msceqf_options.hpp:206