mars_lib 0.1.0.2abe2576fe7f
Modular and Robust Sensor-Fusion
Loading...
Searching...
No Matches
core_state_type.h
Go to the documentation of this file.
1// Copyright (C) 2021 Christian Brommer, Control of Networked Systems, University of Klagenfurt, Austria.
2//
3// All rights reserved.
4//
5// This software is licensed under the terms of the BSD-2-Clause-License with
6// no commercial use allowed, the full terms of which are made available
7// in the LICENSE file. No license in patents is granted.
8//
9// You can contact the author at <christian.brommer@ieee.org>
10
11#ifndef CORESTATETYPE_H
12#define CORESTATETYPE_H
13
15#include <Eigen/Dense>
16#include <string>
17
18namespace mars
19{
21{
22public:
23 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24
25 CoreStateType() = default;
26
27 Eigen::Vector3d p_wi_{ Eigen::Vector3d::Zero() };
28 Eigen::Vector3d v_wi_{ Eigen::Vector3d::Zero() };
29 Eigen::Quaternion<double> q_wi_{ Eigen::Quaternion<double>::Identity() };
30 Eigen::Vector3d b_w_{ Eigen::Vector3d::Zero() };
31 Eigen::Vector3d b_a_{ Eigen::Vector3d::Zero() };
32
33 // will be removed in next version ISSUE: #14
34 Eigen::Vector3d w_m_{ Eigen::Vector3d::Zero() };
35 Eigen::Vector3d a_m_{ Eigen::Vector3d::Zero() };
36
37 static constexpr int size_true_ = 16;
38 static constexpr int size_error_ = 15;
39
47 Eigen::Matrix<double, CoreStateType::size_error_, 1> correction)
48 {
49 // APPLY_CORRECTION Applies the given correction to the provided state_prior
50 // state + error state correction
51 // with quaternion from small-angle approx -> new state
52
53 CoreStateType corrected_state;
54
55 corrected_state.p_wi_ = state_prior.p_wi_ + correction.block(0, 0, 3, 1);
56 corrected_state.v_wi_ = state_prior.v_wi_ + correction.block(3, 0, 3, 1);
57
58 // Attention: due to small-angle to quaternion conversion,
59 // the index for the corrected state does not map 1:1 (7:9 to 7:10)
60 // this is important for the mapping idx after the quaternion.
61 corrected_state.q_wi_ = Utils::ApplySmallAngleQuatCorr(state_prior.q_wi_, correction.block(6, 0, 3, 1));
62
63 // %if obj.fixed_bias
64 // % correction(10:12) = zeros(3,1);
65 // % correction(13:15) = zeros(3,1);
66 // %end
67
68 corrected_state.b_w_ = state_prior.b_w_ + correction.block(9, 0, 3, 1);
69 corrected_state.b_a_ = state_prior.b_a_ + correction.block(12, 0, 3, 1);
70
71 // Pass through IMU measurements
72 corrected_state.a_m_ = state_prior.a_m_;
73 corrected_state.w_m_ = state_prior.w_m_;
74
75 return corrected_state;
76 }
77
78 friend std::ostream& operator<<(std::ostream& out, const CoreStateType& data)
79 {
80 out.precision(10);
81 out << std::fixed;
82 out << "p_wi:\t[ " << data.p_wi_.transpose() << " ]" << std::endl
83 << "v_wi:\t[ " << data.v_wi_.transpose() << " ]" << std::endl
84 << "q_wi:\t[ " << data.q_wi_.w() << " " << data.q_wi_.vec().transpose() << " ]" << std::endl
85 << "b_w:\t[ " << data.b_w_.transpose() << " ]" << std::endl
86 << "b_a:\t[ " << data.b_a_.transpose() << " ]" << std::endl
87 << "w_m:\t[ " << data.w_m_.transpose() << " ]" << std::endl
88 << "a_m:\t[ " << data.a_m_.transpose() << " ]" << std::endl;
89
90 return out;
91 }
92
93 static std::string get_csv_state_header_string()
94 {
95 std::stringstream os;
96 os << "t, ";
97 os << "w_m_x, w_m_y, w_m_z, ";
98 os << "a_m_x, a_m_y, a_m_z, ";
99 os << "p_wi_x, p_wi_y, p_wi_z, ";
100 os << "v_wi_x, v_wi_y, v_wi_z, ";
101 os << "q_wi_w, q_wi_x, q_wi_y, q_wi_z, ";
102 os << "b_w_x, b_w_y, b_w_z, ";
103 os << "b_a_x, b_a_y, b_a_z";
104
105 return os.str();
106 }
107
113 std::string to_csv_string(const double& timestamp) const
114 {
115 std::stringstream os;
116 os.precision(17);
117 os << timestamp;
118
119 os << ", " << w_m_(0) << ", " << w_m_(1) << ", " << w_m_(2);
120 os << ", " << a_m_(0) << ", " << a_m_(1) << ", " << a_m_(2);
121 os << ", " << p_wi_(0) << ", " << p_wi_(1) << ", " << p_wi_(2);
122 os << ", " << v_wi_(0) << ", " << v_wi_(1) << ", " << v_wi_(2);
123
124 Eigen::Vector4d q_wi = q_wi_.coeffs(); // x y z w
125 os << ", " << q_wi(3) << ", " << q_wi(0) << ", " << q_wi(1) << ", " << q_wi(2);
126
127 os << ", " << b_w_(0) << ", " << b_w_(1) << ", " << b_w_(2);
128 os << ", " << b_a_(0) << ", " << b_a_(1) << ", " << b_a_(2);
129
130 return os.str();
131 }
132};
133
134using CoreStateMatrix = Eigen::Matrix<double, CoreStateType::size_error_, CoreStateType::size_error_>;
135using CoreStateVector = Eigen::Matrix<double, CoreStateType::size_error_, 1>;
136} // namespace mars
137#endif // CORESTATETYPE_H
Definition core_state_type.h:21
Eigen::Vector3d w_m_
Definition core_state_type.h:34
static constexpr int size_true_
Definition core_state_type.h:37
static constexpr int size_error_
Definition core_state_type.h:38
Eigen::Vector3d v_wi_
Definition core_state_type.h:28
Eigen::Vector3d b_a_
Definition core_state_type.h:31
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CoreStateType()=default
Eigen::Vector3d b_w_
Definition core_state_type.h:30
Eigen::Vector3d p_wi_
Definition core_state_type.h:27
std::string to_csv_string(const double &timestamp) const
to_csv_string export state to single csv string
Definition core_state_type.h:113
static std::string get_csv_state_header_string()
Definition core_state_type.h:93
Eigen::Quaternion< double > q_wi_
Definition core_state_type.h:29
friend std::ostream & operator<<(std::ostream &out, const CoreStateType &data)
Definition core_state_type.h:78
static CoreStateType ApplyCorrection(CoreStateType state_prior, Eigen::Matrix< double, CoreStateType::size_error_, 1 > correction)
ApplyCorrection.
Definition core_state_type.h:46
Eigen::Vector3d a_m_
Definition core_state_type.h:35
static Eigen::Quaterniond ApplySmallAngleQuatCorr(const Eigen::Quaterniond &q_prior, const Eigen::Vector3d &correction)
ApplySmallAngleQuatCorr.
Definition buffer.h:27
Eigen::Matrix< double, CoreStateType::size_error_, 1 > CoreStateVector
Definition core_state_type.h:135
Eigen::Matrix< double, CoreStateType::size_error_, CoreStateType::size_error_ > CoreStateMatrix
Definition core_state_type.h:134