13 #ifndef BODYVELSENSORCLASS_H
14 #define BODYVELSENSORCLASS_H
39 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 std::cout <<
"Created: [" << this->
name_ <<
"] Sensor" << std::endl;
75 std::shared_ptr<CoreType> latest_core_data)
80 std::string calibration_type;
84 calibration_type =
"Given";
93 calibration_type =
"Auto";
95 std::cout <<
"Bodyvel calibration AUTO init not implemented yet" << std::endl;
100 BufferDataType result(std::make_shared<CoreType>(*latest_core_data.get()),
101 std::make_shared<BodyvelSensorData>(sensor_state));
105 std::cout <<
"Info: Initialized [" <<
name_ <<
"] with [" << calibration_type <<
"] Calibration at t=" << timestamp
110 std::cout <<
"Info: [" <<
name_ <<
"] Calibration(rounded):" << std::endl;
111 std::cout <<
"\tPosition[m]: [" << sensor_state.
state_.p_ib_.transpose() <<
" ]" << std::endl;
112 std::cout <<
"\tOrientation[deg]: ["
113 << sensor_state.
state_.q_ib_.toRotationMatrix().eulerAngles(0, 1, 2).transpose() * (180 / M_PI) <<
" ]"
121 std::shared_ptr<void> latest_sensor_data,
const Eigen::MatrixXd& prior_cov,
129 Eigen::Vector3d v_meas = meas->
velocity_;
136 Eigen::MatrixXd R_meas_dyn;
143 R_meas_dyn = this->
R_.asDiagonal();
145 const Eigen::Matrix<double, 3, 3> R_meas = R_meas_dyn;
148 const int size_of_sensor_state = prior_sensor_state.
cov_size_;
149 const int size_of_full_error_state = size_of_core_state + size_of_sensor_state;
150 const Eigen::MatrixXd P = prior_cov;
151 assert(P.size() == size_of_full_error_state * size_of_full_error_state);
155 const Eigen::Matrix3d Z_3 = Eigen::Matrix3d::Zero();
157 const Eigen::Vector3d V_wi = prior_core_state.
v_wi_;
158 const Eigen::Matrix3d R_wi = prior_core_state.
q_wi_.toRotationMatrix();
159 const Eigen::Vector3d P_ib = prior_sensor_state.
p_ib_;
160 const Eigen::Matrix3d R_ib = prior_sensor_state.
q_ib_.toRotationMatrix();
162 const Eigen::Vector3d w_wi = prior_core_state.
w_m_ - prior_core_state.
b_w_;
163 const Eigen::Matrix3d w_wi_skew =
Utils::Skew(w_wi);
166 const Eigen::Matrix3d Hv_pwi = Z_3;
167 const Eigen::Matrix3d Hv_vwi = R_ib.transpose() * R_wi.transpose();
168 const Eigen::Matrix3d Hv_rwi = R_ib.transpose() *
Utils::Skew(R_wi.transpose() * V_wi);
169 const Eigen::Matrix3d Hv_bw = R_ib.transpose() *
Utils::Skew(P_ib);
170 const Eigen::Matrix3d Hv_ba = Z_3;
171 const Eigen::Matrix3d Hv_pib = R_ib.transpose() * w_wi_skew;
172 const Eigen::Matrix3d Hv_rib =
173 Utils::Skew(R_ib.transpose() * R_wi.transpose() * V_wi) +
Utils::Skew(R_ib.transpose() * w_wi_skew * P_ib);
177 Eigen::MatrixXd H_v(3, Hv_pwi.cols() + Hv_vwi.cols() + Hv_rwi.cols() + Hv_bw.cols() + Hv_ba.cols() + Hv_pib.cols() +
179 H_v << Hv_pwi, Hv_vwi, Hv_rwi, Hv_bw, Hv_ba, Hv_pib, Hv_rib;
182 Eigen::MatrixXd H(H_v.rows(), H_v.cols());
187 const Eigen::Vector3d v_est = R_ib.transpose() * R_wi.transpose() * V_wi + R_ib.transpose() * w_wi_skew * P_ib;
188 residual_ = Eigen::MatrixXd(v_est.rows(), 1);
194 assert(correction.size() == size_of_full_error_state * 1);
204 assert(P_updated.size() == size_of_full_error_state * size_of_full_error_state);
212 const Eigen::MatrixXd sensor_correction = correction.block(size_of_core_state, 0, size_of_sensor_state, 1);
219 core_data.
state_ = corrected_core_state;
222 std::shared_ptr<BodyvelSensorData> sensor_data(std::make_shared<BodyvelSensorData>());
223 sensor_data->set_cov(P_updated);
224 sensor_data->state_ = corrected_sensor_state;
226 BufferDataType state_entry(std::make_shared<CoreType>(core_data), sensor_data);
237 *new_state_data = state_entry;
243 const Eigen::MatrixXd& correction)
249 corrected_sensor_state.
p_ib_ = prior_sensor_state.
p_ib_ + correction.block(0, 0, 3, 1);
250 corrected_sensor_state.
q_ib_ =
252 return corrected_sensor_state;
bool has_meas_noise
Definition: measurement_base_class.h:23
bool get_meas_noise(Eigen::MatrixXd *meas_noise)
get the measurement noise associated with the current sensor measurement
Definition: measurement_base_class.h:25
int cov_size_
Definition: base_states.h:25
The BaseSensorData class binds the sensor state and covariance matrix.
Definition: bind_sensor_data.h:29
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T state_
Definition: bind_sensor_data.h:30
Eigen::MatrixXd get_full_cov() const
get_full_cov builds the full covariance matrix
Definition: bind_sensor_data.h:63
Eigen::MatrixXd sensor_cov_
covariance of the sensor states
Definition: bind_sensor_data.h:37
Definition: bodyvel_measurement_type.h:23
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d velocity_
Velocity [x y z].
Definition: bodyvel_measurement_type.h:27
Definition: bodyvel_sensor_class.h:37
virtual ~BodyvelSensorClass()=default
void set_initial_calib(std::shared_ptr< void > calibration)
set_initial_calib Sets the calibration of an individual sensor
Definition: bodyvel_sensor_class.h:68
BodyvelSensorStateType ApplyCorrection(const BodyvelSensorStateType &prior_sensor_state, const Eigen::MatrixXd &correction)
Definition: bodyvel_sensor_class.h:242
Eigen::MatrixXd get_covariance(const std::shared_ptr< void > &sensor_data)
get_covariance Resolves a void pointer to the covariance matrix of the corresponding sensor type Each...
Definition: bodyvel_sensor_class.h:62
BodyvelSensorStateType get_state(const std::shared_ptr< void > &sensor_data)
Definition: bodyvel_sensor_class.h:56
bool CalcUpdate(const Time &, std::shared_ptr< void > measurement, const CoreStateType &prior_core_state, std::shared_ptr< void > latest_sensor_data, const Eigen::MatrixXd &prior_cov, BufferDataType *new_state_data)
CalcUpdate Calculates the update for an individual sensor definition.
Definition: bodyvel_sensor_class.h:120
EIGEN_MAKE_ALIGNED_OPERATOR_NEW BodyvelSensorClass(const std::string &name, std::shared_ptr< CoreState > core_states)
Definition: bodyvel_sensor_class.h:41
BufferDataType Initialize(const Time ×tamp, std::shared_ptr< void >, std::shared_ptr< CoreType > latest_core_data)
Initialize the state of an individual sensor.
Definition: bodyvel_sensor_class.h:74
Definition: bodyvel_sensor_state_type.h:22
Eigen::Quaternion< double > q_ib_
Definition: bodyvel_sensor_state_type.h:27
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d p_ib_
Definition: bodyvel_sensor_state_type.h:26
The BufferDataType binds the core and sensor state in form of a shared void pointer.
Definition: buffer_data_type.h:36
bool passed_
Determine if the test is performed or not.
Definition: ekf.h:84
bool do_test_
Upper critival value.
Definition: ekf.h:83
void set_dof(const int &value)
set_dof Set degree of freedom for the X2 distribution
void PrintReport(const std::string &name)
PrintReport Print a formated report e.g. if the test did not pass.
Definition: core_state_type.h:21
Eigen::Vector3d w_m_
Definition: core_state_type.h:34
static constexpr int size_error_
Definition: core_state_type.h:38
Eigen::Vector3d v_wi_
Definition: core_state_type.h:28
Eigen::Vector3d b_w_
Definition: core_state_type.h:30
Eigen::Quaternion< double > q_wi_
Definition: core_state_type.h:29
static CoreStateType ApplyCorrection(CoreStateType state_prior, Eigen::Matrix< double, CoreStateType::size_error_, 1 > correction)
ApplyCorrection.
Definition: core_state_type.h:46
Definition: core_type.h:19
CoreStateMatrix cov_
Definition: core_type.h:22
CoreStateType state_
Definition: core_type.h:21
Eigen::MatrixXd CalculateCovUpdate()
CalculateCovUpdate Updating the state covariance after the state update.
Eigen::MatrixXd CalculateCorrection()
Kalman gain.
std::string name_
Name of the individual sensor instance.
Definition: sensor_abs_class.h:23
bool is_initialized_
True if the sensor has been initialized.
Definition: sensor_abs_class.h:24
bool const_ref_to_nav_
True if the reference should not be estimated.
Definition: sensor_abs_class.h:27
bool use_dynamic_meas_noise_
True if dynamic noise values from measurements should be used.
Definition: sensor_abs_class.h:29
Definition: update_sensor_abs_class.h:24
bool initial_calib_provided_
True if an initial calibration was provided.
Definition: update_sensor_abs_class.h:38
std::shared_ptr< CoreState > core_states_
Definition: update_sensor_abs_class.h:42
Eigen::VectorXd R_
Measurement noise "squared".
Definition: update_sensor_abs_class.h:32
std::shared_ptr< void > initial_calib_
Definition: update_sensor_abs_class.h:37
Chi2 chi2_
Definition: update_sensor_abs_class.h:40
Eigen::MatrixXd residual_
Definition: update_sensor_abs_class.h:31
static Eigen::MatrixXd EnforceMatrixSymmetry(const Eigen::Ref< const Eigen::MatrixXd > &mat_in)
EnforceMatrixSymmetry.
static Eigen::Matrix3d Skew(const Eigen::Vector3d &v)
skew generate the skew symmetric matrix of v
static Eigen::Quaterniond ApplySmallAngleQuatCorr(const Eigen::Quaterniond &q_prior, const Eigen::Vector3d &correction)
ApplySmallAngleQuatCorr.
Eigen::Matrix< double, CoreStateType::size_error_, 1 > CoreStateVector
Definition: core_state_type.h:135