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 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 OPTIONS_PARSER_HPP
21#define OPTIONS_PARSER_HPP
22
23#include <yaml-cpp/yaml.h>
24
25#include <numeric>
26#include <sstream>
27#include <opencv2/opencv.hpp>
28
29#include "msceqf/options/msceqf_options.hpp"
30#include "types/fptypes.hpp"
31#include "utils/logger.hpp"
32#include "utils/tools.hpp"
33
34namespace msceqf
35{
37 {
38 public:
44 OptionParser(const std::string &filepath);
45
52
53 private:
66 template <int Rows, int Cols>
67 [[nodiscard]] bool read(Matrix<Rows, Cols> &x, const std::string &param)
68 {
69 if (node_[param])
70 {
71 using vector = std::vector<fp>;
72 using vectorvector = std::vector<std::vector<fp>>;
73
74 int rows = Rows;
75 int cols = Cols;
76
77 if constexpr (Rows == 1 || Cols == 1)
78 {
79 vector vec = node_[param].as<vector>();
80 if constexpr (Rows == -1)
81 {
82 rows = vec.size();
83 }
84 else if (Cols == -1)
85 {
86 cols = vec.size();
87 }
88 x = Map<Matrix<Rows, Cols>>(vec.data(), rows, cols);
89 }
90 else
91 {
92 vectorvector mat = node_[param].as<vectorvector>();
93 vector vec = utils::flatten(mat);
94 if constexpr (Rows == 1 && Cols == 1)
95 {
96 rows = mat.size();
97 cols = vec.size() / mat.size();
98 }
99 x = Map<Matrix<Rows, Cols, Eigen::RowMajor>>(vec.data(), rows, cols);
100 }
101 if constexpr (Rows == 1)
102 {
103 utils::Logger::info("Parameter: [" + param + "] found. Option set to:" +
104 (std::ostringstream{} << x).str());
105 }
106 else if (Cols == 1)
107 {
108 utils::Logger::info("Parameter: [" + param + "] found. Option set to: " +
109 (std::ostringstream{} << x.transpose()).str());
110 }
111 else
112 {
113 utils::Logger::info("Parameter: [" + param + "] found. Option set to: \n" +
114 (std::ostringstream{} << x).str());
115 }
116
117 return true;
118 }
119 utils::Logger::warn("Parameter: [" + param + "] not found");
120 return false;
121 }
122
133 template <typename Scalar>
134 [[nodiscard]] bool read(Quaternion &q, const std::string &param)
135 {
136 if (node_[param])
137 {
138 using vector = std::vector<fp>;
139 vector vec = node_[param].as<vector>();
140 q = Quaternion(vec).normalize();
141 utils::Logger::info("Parameter: [" + param + "] found. Option set to: \n" +
142 (std::ostringstream{} << q).str());
143 return true;
144 }
145 utils::Logger::warn("Parameter: [" + param + "] not found");
146 return false;
147 }
148
157 template <typename T>
158 [[nodiscard]] bool read(T &p, const std::string &param)
159 {
160 if (node_[param])
161 {
162 p = node_[param].as<T>();
163 utils::Logger::info("Parameter: [" + param + "] found. Option set to: " +
164 (std::ostringstream{} << p).str());
165 return true;
166 }
167 utils::Logger::warn("Parameter: [" + param + "] not found");
168 return false;
169 }
170
171 template <typename T, typename Convertible>
172 void readDefault(T &p, const Convertible &def, const std::string &param)
173 {
174 static_assert(std::is_convertible_v<Convertible, T>);
175 if (!read(p, param))
176 {
177 p = def;
178 utils::Logger::warn("Parameter: [" + param + "] set to default value: " +
179 (std::ostringstream{} << p).str());
180 }
181 }
182
196 void parseCameraParameters(SE3 &extrinsics,
197 In &intrinsics,
198 DistortionModel &distortion_model,
199 VectorX &distortion_coefficients,
200 Vector2 &resolution,
201 fp &timeshift_cam_imu,
202 cv::Mat &mask,
203 MaskType &mask_type);
204
212 void parseGivenOrigin(SE23 &T, Vector6 &b, fp &t0);
213
219 void parseEqualizationMethod(EqualizationMethod &eq);
220
226 void parseFeatureRepresentation(FeatureRepresentation &rep);
227
233 void parseProjectionMethod(ProjectionMethod &proj);
234
240 void parseDetectorType(FeatureDetector &detector);
241
251 void parseInitialCovariance(Matrix9 &D_cov, Matrix6 &delta_cov, Matrix6 &E_cov, Matrix4 &L_cov);
252
261 void parseProcessNoise(fp &w_std, fp &a_std, fp &bw_std, fp &ba_std);
262
270 void parsePixStd(fp &pix_std, const StateOptions &opts);
271
277 void parseZeroVelocityUpdate(ZeroVelocityUpdate &zvu);
278
279 YAML::Node node_;
280 std::string filepath_;
281 };
282
283} // namespace msceqf
284
285#endif // OPTIONS_HPP
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:108
static void info(const T &msg)
Format a info message and log it in white.
Definition logger.hpp:75
Definition msceqf_options.hpp:214