11 #ifndef GPSSENSORCLASS_H
12 #define GPSSENSORCLASS_H
35 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 GpsSensorClass(
const std::string& name, std::shared_ptr<CoreState> core_states)
53 std::cout <<
"Created: [" << this->
name_ <<
"] Sensor" << std::endl;
88 std::cout <<
"Info: [" <<
name_ <<
"] Set External GPS Reference: \n" << gps_reference << std::endl;
92 std::cout <<
"Warning: [" <<
name_ <<
"] "
93 <<
"Trying to set GPS reference but reference was already set. Action has no effect." << std::endl;
98 std::shared_ptr<CoreType> latest_core_data)
110 std::cout <<
"Info: [" <<
name_ <<
"] Set Internal GPS Reference: \n" << gps_reference << std::endl;
114 std::string calibration_type;
118 calibration_type =
"Given";
127 calibration_type =
"Auto";
128 std::cout <<
"GPS calibration AUTO init not implemented yet" << std::endl;
133 BufferDataType result(std::make_shared<CoreType>(*latest_core_data.get()),
134 std::make_shared<GpsSensorData>(sensor_state));
138 std::cout <<
"Info: Initialized [" <<
name_ <<
"] with [" << calibration_type <<
"] Calibration at t=" << timestamp
141 std::cout <<
"Info: [" <<
name_ <<
"] Calibration(rounded):" << std::endl;
142 std::cout <<
"\tPosition[m]: [" << sensor_state.
state_.p_ig_.transpose() <<
" ]" << std::endl;
149 std::shared_ptr<void> latest_sensor_data,
const Eigen::MatrixXd& prior_cov,
164 Eigen::MatrixXd R_meas_dyn;
171 R_meas_dyn = this->
R_.asDiagonal();
173 const Eigen::Matrix<double, 3, 3> R_meas = R_meas_dyn;
176 const int size_of_sensor_state = prior_sensor_state.
cov_size_;
177 const int size_of_full_error_state = size_of_core_state + size_of_sensor_state;
178 const Eigen::MatrixXd P = prior_cov;
179 assert(P.size() == size_of_full_error_state * size_of_full_error_state);
183 const Eigen::Vector3d P_wi = prior_core_state.
p_wi_;
184 const Eigen::Matrix3d R_wi = prior_core_state.
q_wi_.toRotationMatrix();
185 const Eigen::Vector3d P_ig = prior_sensor_state.
p_ig_;
187 const Eigen::Vector3d P_gw_w = prior_sensor_state.
p_gw_w_;
188 const Eigen::Matrix3d R_gw_w = prior_sensor_state.
q_gw_w_.toRotationMatrix();
191 const Eigen::Matrix3d Hp_pwi = R_gw_w;
192 const Eigen::Matrix3d Hp_vwi = Eigen::Matrix3d::Zero();
193 const Eigen::Matrix3d Hp_rwi = -R_gw_w * R_wi *
Utils::Skew(P_ig);
194 const Eigen::Matrix3d Hp_bw = Eigen::Matrix3d::Zero();
195 const Eigen::Matrix3d Hp_ba = Eigen::Matrix3d::Zero();
197 const Eigen::Matrix3d Hp_pig = R_gw_w * R_wi;
198 const Eigen::Matrix3d Hp_pgw_w = Eigen::Matrix3d::Zero();
199 const Eigen::Matrix3d Hp_rgw_w = Eigen::Matrix3d::Zero();
203 Eigen::MatrixXd H(3, Hp_pwi.cols() + Hp_vwi.cols() + Hp_rwi.cols() + Hp_bw.cols() + Hp_ba.cols() + Hp_pig.cols() +
204 Hp_pgw_w.cols() + Hp_rgw_w.cols());
206 H << Hp_pwi, Hp_vwi, Hp_rwi, Hp_bw, Hp_ba, Hp_pig, Hp_pgw_w, Hp_rgw_w;
210 const Eigen::Vector3d p_est = P_gw_w + R_gw_w * (P_wi + R_wi * P_ig);
211 residual_ = Eigen::MatrixXd(p_est.rows(), 1);
217 assert(correction.size() == size_of_full_error_state * 1);
227 assert(P_updated.size() == size_of_full_error_state * size_of_full_error_state);
235 const Eigen::MatrixXd sensor_correction = correction.block(size_of_core_state, 0, size_of_sensor_state, 1);
242 core_data.
state_ = corrected_core_state;
245 std::shared_ptr<GpsSensorData> sensor_data(std::make_shared<GpsSensorData>());
246 sensor_data->set_cov(P_updated);
247 sensor_data->state_ = corrected_sensor_state;
249 BufferDataType state_entry(std::make_shared<CoreType>(core_data), sensor_data);
260 *new_state_data = state_entry;
271 corrected_sensor_state.
p_ig_ = prior_sensor_state.
p_ig_ + correction.block(0, 0, 3, 1);
272 corrected_sensor_state.
p_gw_w_ = prior_sensor_state.
p_gw_w_ + correction.block(3, 0, 3, 1);
273 corrected_sensor_state.
q_gw_w_ =
275 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
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
static constexpr int size_error_
Definition: core_state_type.h:38
Eigen::Vector3d p_wi_
Definition: core_state_type.h:27
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.
The GpsConversion class.
Definition: gps_conversion.h:66
void set_gps_reference(mars::GpsCoordinates coordinates)
set_gps_reference
mars::GpsCoordinates get_gps_reference()
get_gps_reference
Eigen::Matrix< double, 3, 1 > get_enu(mars::GpsCoordinates coordinates)
get_enu get current GPS reference coordinates
Definition: gps_measurement_type.h:21
GpsCoordinates coordinates_
Definition: gps_measurement_type.h:23
Definition: gps_sensor_class.h:33
GpsSensorStateType ApplyCorrection(const GpsSensorStateType &prior_sensor_state, const Eigen::MatrixXd &correction)
Definition: gps_sensor_class.h:265
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GpsConversion gps_conversion_
Definition: gps_sensor_class.h:37
GpsSensorStateType get_state(const std::shared_ptr< void > &sensor_data)
Definition: gps_sensor_class.h:58
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: gps_sensor_class.h:148
void set_gps_reference_coordinates(const double &latitude, const double &longitude, const double &altitude)
Definition: gps_sensor_class.h:76
void set_initial_calib(std::shared_ptr< void > calibration)
set_initial_calib Sets the calibration of an individual sensor
Definition: gps_sensor_class.h:70
bool gps_reference_is_set_
Definition: gps_sensor_class.h:39
GpsSensorClass(const std::string &name, std::shared_ptr< CoreState > core_states)
Definition: gps_sensor_class.h:41
void set_gps_reference_coordinates(const mars::GpsCoordinates &gps_reference)
Definition: gps_sensor_class.h:81
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: gps_sensor_class.h:64
virtual ~GpsSensorClass()=default
bool using_external_gps_reference_
Definition: gps_sensor_class.h:38
BufferDataType Initialize(const Time ×tamp, std::shared_ptr< void > sensor_data, std::shared_ptr< CoreType > latest_core_data)
Initialize the state of an individual sensor.
Definition: gps_sensor_class.h:97
Definition: gps_sensor_state_type.h:20
Eigen::Quaterniond q_gw_w_
Definition: gps_sensor_state_type.h:26
Eigen::Vector3d p_gw_w_
Definition: gps_sensor_state_type.h:25
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d p_ig_
Definition: gps_sensor_state_type.h:24
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
The GpsCoordinates struct.
Definition: gps_conversion.h:22
double longitude_
Definition: gps_conversion.h:29
double altitude_
Definition: gps_conversion.h:30
double latitude_
Definition: gps_conversion.h:28