mars_lib  0.1.0.3dc76ee85e09
Modular and Robust Sensor-Fusion
Public Member Functions | Public Attributes | Private Attributes | List of all members
mars::GpsVelSensorClass Class Reference

#include </home/runner/work/mars_lib/mars_lib/source/mars/include/mars/sensors/gps_w_vel/gps_w_vel_sensor_class.h>

+ Inheritance diagram for mars::GpsVelSensorClass:
+ Collaboration diagram for mars::GpsVelSensorClass:

Public Member Functions

 GpsVelSensorClass (const std::string &name, std::shared_ptr< CoreState > core_states)
 
virtual ~GpsVelSensorClass ()=default
 
void set_v_rot_axis (const Eigen::Vector3d &vec)
 
void set_use_vel_rot (const bool &value)
 
void set_vel_rot_thr (const double &value)
 
GpsVelSensorStateType get_state (const std::shared_ptr< void > &sensor_data)
 
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 sensor is responsible to cast its own data type More...
 
void set_initial_calib (std::shared_ptr< void > calibration)
 set_initial_calib Sets the calibration of an individual sensor More...
 
void set_gps_reference_coordinates (const double &latitude, const double &longitude, const double &altitude)
 
void set_gps_reference_coordinates (const mars::GpsCoordinates &gps_reference)
 
BufferDataType Initialize (const Time &timestamp, std::shared_ptr< void > sensor_data, std::shared_ptr< CoreType > latest_core_data)
 Initialize the state of an individual sensor. More...
 
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. More...
 
GpsVelSensorStateType ApplyCorrection (const GpsVelSensorStateType &prior_sensor_state, const Eigen::MatrixXd &correction)
 
- Public Member Functions inherited from mars::SensorInterface
virtual EIGEN_MAKE_ALIGNED_OPERATOR_NEW ~SensorInterface ()=default
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW GpsConversion gps_conversion_
 
bool using_external_gps_reference_
 
bool gps_reference_is_set_
 
- Public Attributes inherited from mars::UpdateSensorAbsClass
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int aux_states_
 
int aux_error_states_
 
int ref_to_nav_
 
Eigen::MatrixXd residual_
 
Eigen::VectorXd R_
 Measurement noise "squared". More...
 
Eigen::MatrixXd F_
 
Eigen::MatrixXd H_
 
Eigen::MatrixXd Q_
 
std::shared_ptr< void > initial_calib_ { nullptr }
 
bool initial_calib_provided_ { false }
 True if an initial calibration was provided. More...
 
Chi2 chi2_
 
std::shared_ptr< CoreStatecore_states_
 
- Public Attributes inherited from mars::SensorAbsClass
int id_ { -1 }
 
std::string name_
 Name of the individual sensor instance. More...
 
bool is_initialized_ { false }
 True if the sensor has been initialized. More...
 
bool do_update_ { true }
 True if updates should be performed with the sensor. More...
 
int type_ { -1 }
 Future feature, holds information such as position or orientation for highlevel decissions. More...
 
bool const_ref_to_nav_ { true }
 True if the reference should not be estimated. More...
 
bool ref_to_nav_given_ { false }
 True if the reference to the navigation frame is given by initial calibration. More...
 
bool use_dynamic_meas_noise_ { false }
 True if dynamic noise values from measurements should be used. More...
 

Private Attributes

Eigen::Vector3d v_rot_axis_ { 1, 0, 0 }
 
bool use_vel_rot_ { false }
 
double vel_rot_thr_ { 0.3 }
 

Constructor & Destructor Documentation

◆ GpsVelSensorClass()

mars::GpsVelSensorClass::GpsVelSensorClass ( const std::string &  name,
std::shared_ptr< CoreState core_states 
)
inline
48  {
49  name_ = name;
50  core_states_ = std::move(core_states);
51  const_ref_to_nav_ = false;
54  gps_reference_is_set_ = false;
55 
56  chi2_.set_dof(6);
57 
58  std::cout << "Created: [" << this->name_ << "] Sensor" << std::endl;
59  }
void set_dof(const int &value)
set_dof Set degree of freedom for the X2 distribution
bool using_external_gps_reference_
Definition: gps_w_vel_sensor_class.h:44
bool gps_reference_is_set_
Definition: gps_w_vel_sensor_class.h:45
std::string name_
Name of the individual sensor instance.
Definition: sensor_abs_class.h:23
bool const_ref_to_nav_
True if the reference should not be estimated.
Definition: sensor_abs_class.h:27
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
Chi2 chi2_
Definition: update_sensor_abs_class.h:40
+ Here is the call graph for this function:

◆ ~GpsVelSensorClass()

virtual mars::GpsVelSensorClass::~GpsVelSensorClass ( )
virtualdefault

Member Function Documentation

◆ set_v_rot_axis()

void mars::GpsVelSensorClass::set_v_rot_axis ( const Eigen::Vector3d &  vec)
inline
64  {
65  v_rot_axis_ = vec.normalized();
66  }
Eigen::Vector3d v_rot_axis_
Definition: gps_w_vel_sensor_class.h:36

◆ set_use_vel_rot()

void mars::GpsVelSensorClass::set_use_vel_rot ( const bool &  value)
inline
69  {
70  use_vel_rot_ = value;
71  }
bool use_vel_rot_
Definition: gps_w_vel_sensor_class.h:37

◆ set_vel_rot_thr()

void mars::GpsVelSensorClass::set_vel_rot_thr ( const double &  value)
inline
74  {
75  vel_rot_thr_ = fabs(value);
76  }
double vel_rot_thr_
Definition: gps_w_vel_sensor_class.h:38

◆ get_state()

GpsVelSensorStateType mars::GpsVelSensorClass::get_state ( const std::shared_ptr< void > &  sensor_data)
inline
79  {
80  GpsVelSensorData data = *static_cast<GpsVelSensorData*>(sensor_data.get());
81  return data.state_;
82  }
BindSensorData< GpsVelSensorStateType > GpsVelSensorData
Definition: gps_w_vel_sensor_class.h:31

◆ get_covariance()

Eigen::MatrixXd mars::GpsVelSensorClass::get_covariance ( const std::shared_ptr< void > &  sensor_data)
inlinevirtual

get_covariance Resolves a void pointer to the covariance matrix of the corresponding sensor type Each sensor is responsible to cast its own data type

Parameters
sensor_data
Returns
Covariance matrix contained in the sensor data struct

Implements mars::SensorInterface.

85  {
86  GpsVelSensorData data = *static_cast<GpsVelSensorData*>(sensor_data.get());
87  return data.get_full_cov();
88  }
+ Here is the call graph for this function:

◆ set_initial_calib()

void mars::GpsVelSensorClass::set_initial_calib ( std::shared_ptr< void >  calibration)
inlinevirtual

set_initial_calib Sets the calibration of an individual sensor

Parameters
calibration

Implements mars::SensorInterface.

91  {
92  initial_calib_ = calibration;
94  }
std::shared_ptr< void > initial_calib_
Definition: update_sensor_abs_class.h:37

◆ set_gps_reference_coordinates() [1/2]

void mars::GpsVelSensorClass::set_gps_reference_coordinates ( const double &  latitude,
const double &  longitude,
const double &  altitude 
)
inline
97  {
98  set_gps_reference_coordinates(mars::GpsCoordinates(latitude, longitude, altitude));
99  }
void set_gps_reference_coordinates(const double &latitude, const double &longitude, const double &altitude)
Definition: gps_w_vel_sensor_class.h:96
The GpsCoordinates struct.
Definition: gps_conversion.h:22

◆ set_gps_reference_coordinates() [2/2]

void mars::GpsVelSensorClass::set_gps_reference_coordinates ( const mars::GpsCoordinates gps_reference)
inline
102  {
104  {
105  gps_conversion_.set_gps_reference(gps_reference);
106  gps_reference_is_set_ = true;
108  std::cout << "Info: [" << name_ << "] Set External GPS Reference: \n" << gps_reference << std::endl;
109  }
110  else
111  {
112  std::cout << "Warning: [" << name_ << "] "
113  << "Trying to set GPS reference but reference was already set. Action has no effect." << std::endl;
114  }
115  }
void set_gps_reference(mars::GpsCoordinates coordinates)
set_gps_reference
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GpsConversion gps_conversion_
Definition: gps_w_vel_sensor_class.h:43
+ Here is the call graph for this function:

◆ Initialize()

BufferDataType mars::GpsVelSensorClass::Initialize ( const Time timestamp,
std::shared_ptr< void >  measurement,
std::shared_ptr< CoreType latest_core_data 
)
inlinevirtual

Initialize the state of an individual sensor.

Parameters
timestampcurrent timestamp
measurementcurrent sensor measurement
latest_core_data
Returns

Implements mars::SensorInterface.

119  {
120  GpsVelMeasurementType measurement = *static_cast<GpsVelMeasurementType*>(sensor_data.get());
121 
123  {
124  GpsCoordinates gps_reference(measurement.coordinates_.latitude_, measurement.coordinates_.longitude_,
125  measurement.coordinates_.altitude_);
126 
127  gps_conversion_.set_gps_reference(gps_reference);
128  gps_reference_is_set_ = true;
129 
130  std::cout << "Info: [" << name_ << "] Set Internal GPS Reference: \n" << gps_reference << std::endl;
131  }
132 
133  GpsVelSensorData sensor_state;
134  std::string calibration_type;
135 
136  if (this->initial_calib_provided_)
137  {
138  calibration_type = "Given";
139 
140  GpsVelSensorData calib = *static_cast<GpsVelSensorData*>(initial_calib_.get());
141 
142  sensor_state.state_ = calib.state_;
143  sensor_state.sensor_cov_ = calib.sensor_cov_;
144  }
145  else
146  {
147  calibration_type = "Auto";
148  std::cout << "GPS calibration AUTO init not implemented yet" << std::endl;
149  exit(EXIT_FAILURE);
150  }
151 
152  // Bypass core state for the returned object
153  BufferDataType result(std::make_shared<CoreType>(*latest_core_data.get()),
154  std::make_shared<GpsVelSensorData>(sensor_state));
155 
156  is_initialized_ = true;
157 
158  std::cout << "Info: Initialized [" << name_ << "] with [" << calibration_type << "] Calibration at t=" << timestamp
159  << std::endl;
160 
161  std::cout << "Info: [" << name_ << "] Calibration(rounded):" << std::endl;
162  std::cout << "\tPosition[m]: [" << sensor_state.state_.p_ig_.transpose() << " ]" << std::endl;
163  std::cout << "\tReference: \n" << gps_conversion_.get_gps_reference() << std::endl;
164 
165  return result;
166  }
mars::GpsCoordinates get_gps_reference()
get_gps_reference
bool is_initialized_
True if the sensor has been initialized.
Definition: sensor_abs_class.h:24
+ Here is the call graph for this function:

◆ CalcUpdate()

bool mars::GpsVelSensorClass::CalcUpdate ( const Time timestamp,
std::shared_ptr< void >  measurement,
const CoreStateType prior_core_state_data,
std::shared_ptr< void >  latest_sensor_data,
const Eigen::MatrixXd &  prior_cov,
BufferDataType new_state_data 
)
inlinevirtual

CalcUpdate Calculates the update for an individual sensor definition.

Parameters
timestampcurrent timestamp
measurementcurrent sensor measurement
prior_core_state_data
latest_sensor_data
prior_covPrior covariance containing core, sensor and sensor cross covariance
new_state_dataUpdated state data
Returns
True if the update was successful, false if the update was rejected

< Angular Velocity of the IMU Frame

Implements mars::SensorInterface.

171  {
172  // Cast the sensor measurement and prior state information
173  GpsVelMeasurementType* meas = static_cast<GpsVelMeasurementType*>(measurement.get());
174  GpsVelSensorData* prior_sensor_data = static_cast<GpsVelSensorData*>(latest_sensor_data.get());
175 
176  // Decompose sensor measurement
177  Eigen::Vector3d p_meas = gps_conversion_.get_enu(meas->coordinates_);
178  Eigen::Vector3d v_meas = meas->velocity_;
179 
180  // Extract sensor state
181  GpsVelSensorStateType prior_sensor_state(prior_sensor_data->state_);
182 
183  // Generate measurement noise matrix and check
184  // if noisevalues from the measurement object should be used
185  Eigen::MatrixXd R_meas_dyn;
186  if (meas->has_meas_noise && use_dynamic_meas_noise_)
187  {
188  meas->get_meas_noise(&R_meas_dyn);
189  }
190  else
191  {
192  R_meas_dyn = this->R_.asDiagonal();
193  }
194  Eigen::MatrixXd R_meas(R_meas_dyn);
195 
196  const int size_of_core_state = CoreStateType::size_error_;
197  const int size_of_sensor_state = prior_sensor_state.cov_size_;
198  const int size_of_full_error_state = size_of_core_state + size_of_sensor_state;
199  const Eigen::MatrixXd P = prior_cov;
200  assert(P.size() == size_of_full_error_state * size_of_full_error_state);
201 
202  // Calculate the measurement jacobian H
203  const Eigen::Matrix3d I_3 = Eigen::Matrix3d::Identity();
204  const Eigen::Matrix3d O_3 = Eigen::Matrix3d::Zero();
205 
206  const Eigen::Vector3d omega_i = prior_core_state.w_m_;
207 
208  const Eigen::Vector3d P_wi = prior_core_state.p_wi_;
209  const Eigen::Vector3d V_wi = prior_core_state.v_wi_;
210  const Eigen::Vector3d b_w = prior_core_state.b_w_;
211  const Eigen::Matrix3d R_wi = prior_core_state.q_wi_.toRotationMatrix();
212  const Eigen::Vector3d P_ig = prior_sensor_state.p_ig_;
213 
214  const Eigen::Vector3d P_gw_w = prior_sensor_state.p_gw_w_;
215  const Eigen::Matrix3d R_gw_w = prior_sensor_state.q_gw_w_.toRotationMatrix();
216 
217  // Position
218  const Eigen::Matrix3d Hp_pwi = R_gw_w;
219  const Eigen::Matrix3d Hp_vwi = O_3;
220  const Eigen::Matrix3d Hp_rwi = -R_gw_w * R_wi * Utils::Skew(P_ig);
221  const Eigen::Matrix3d Hp_bw = O_3;
222  const Eigen::Matrix3d Hp_ba = O_3;
223 
224  const Eigen::Matrix3d Hp_pig = R_gw_w * R_wi;
225  const Eigen::Matrix3d Hp_pgw_w = O_3;
226  const Eigen::Matrix3d Hp_rgw_w = O_3;
227 
228  const int num_states = static_cast<int>(Hp_pwi.cols() + Hp_vwi.cols() + Hp_rwi.cols() + Hp_bw.cols() +
229  Hp_ba.cols() + Hp_pig.cols() + Hp_pgw_w.cols() + Hp_rgw_w.cols());
230 
231  // Assemble the jacobian for the position (horizontal)
232  Eigen::MatrixXd H_p(3, num_states);
233  H_p << Hp_pwi, Hp_vwi, Hp_rwi, Hp_bw, Hp_ba, Hp_pig, Hp_pgw_w, Hp_rgw_w;
234 
235  // Assemble the jacobian for the velocity (horizontal)
236  Eigen::MatrixXd H_v(3, num_states);
237  Eigen::Vector3d v_est;
238 
239  if (use_vel_rot_ && (v_meas.norm() > vel_rot_thr_))
240  {
241  // Velocity
242  const Eigen::Vector3d mu = V_wi + R_wi * Utils::Skew(omega_i - b_w) * P_ig;
243  const Eigen::Vector3d d_mu = mu / mu.norm();
244  const Eigen::Vector3d alpha = v_rot_axis_;
245 
246  const Eigen::Matrix3d Hv_pwi = O_3;
247  const Eigen::Matrix3d Hv_vwi = R_wi * alpha * d_mu.transpose();
248  const Eigen::Matrix3d Hv_rwi =
249  -R_wi * Utils::Skew(alpha) * mu.norm() -
250  R_wi * alpha * d_mu.transpose() * R_wi * Utils::Skew(Utils::Skew(omega_i - b_w) * P_ig);
251 
252  const Eigen::Matrix3d Hv_bw = O_3;
253  const Eigen::Matrix3d Hv_ba = O_3;
254 
255  const Eigen::Matrix3d Hv_pig = R_wi * alpha * d_mu.transpose() * R_wi * Utils::Skew(omega_i - b_w);
256  const Eigen::Matrix3d Hv_pgw_w = O_3;
257  const Eigen::Matrix3d Hv_rgw_w = O_3;
258 
259  H_v << Hv_pwi, Hv_vwi, Hv_rwi, Hv_bw, Hv_ba, Hv_pig, Hv_pgw_w, Hv_rgw_w;
260  v_est = R_wi * alpha * (mu).norm();
261  }
262  else
263  {
264  const Eigen::Matrix3d Hv_pwi = O_3;
265  const Eigen::Matrix3d Hv_vwi = I_3;
266  const Eigen::Matrix3d Hv_rwi = -R_wi * Utils::Skew(Utils::Skew(omega_i - b_w) * P_ig);
267  const Eigen::Matrix3d Hv_bw = O_3;
268  const Eigen::Matrix3d Hv_ba = O_3;
269 
270  const Eigen::Matrix3d Hv_pig = R_wi * Utils::Skew(omega_i - b_w);
271  const Eigen::Matrix3d Hv_pgw_w = O_3;
272  const Eigen::Matrix3d Hv_rgw_w = O_3;
273 
274  H_v << Hv_pwi, Hv_vwi, Hv_rwi, Hv_bw, Hv_ba, Hv_pig, Hv_pgw_w, Hv_rgw_w;
275  v_est = V_wi + R_wi * Utils::Skew(omega_i - b_w) * P_ig;
276  }
277 
278  // Combine all jacobians (vertical)
279  Eigen::MatrixXd H(H_p.rows() + H_v.rows(), H_v.cols());
280  H << H_p, H_v;
281 
282  // Calculate the residual z = z~ - (estimate)
283  // Position
284  const Eigen::Vector3d p_est = P_gw_w + R_gw_w * (P_wi + R_wi * P_ig);
285  const Eigen::Vector3d res_p = p_meas - p_est;
286 
287  // Velocity
288  const Eigen::Vector3d res_v = v_meas - v_est;
289 
290  // Combine residuals (vertical)
291  residual_ = Eigen::MatrixXd(res_p.rows() + res_v.rows(), 1);
292  residual_ << res_p, res_v;
293 
294  // Perform EKF calculations
295  mars::Ekf ekf(H, R_meas, residual_, P);
296  const Eigen::MatrixXd correction = ekf.CalculateCorrection(&chi2_);
297  assert(correction.size() == size_of_full_error_state * 1);
298 
299  // Check Chi2 test results
300  if (!chi2_.passed_ && chi2_.do_test_)
301  {
303  return false;
304  }
305 
306  Eigen::MatrixXd P_updated = ekf.CalculateCovUpdate();
307  assert(P_updated.size() == size_of_full_error_state * size_of_full_error_state);
308  P_updated = Utils::EnforceMatrixSymmetry(P_updated);
309 
310  // Apply Core Correction
311  CoreStateVector core_correction = correction.block(0, 0, CoreStateType::size_error_, 1);
312  CoreStateType corrected_core_state = CoreStateType::ApplyCorrection(prior_core_state, core_correction);
313 
314  // Apply Sensor Correction
315  const Eigen::MatrixXd sensor_correction = correction.block(size_of_core_state, 0, size_of_sensor_state, 1);
316  const GpsVelSensorStateType corrected_sensor_state = ApplyCorrection(prior_sensor_state, sensor_correction);
317 
318  // Return Results
319  // CoreState data
320  CoreType core_data;
321  core_data.cov_ = P_updated.block(0, 0, CoreStateType::size_error_, CoreStateType::size_error_);
322  core_data.state_ = corrected_core_state;
323 
324  // SensorState data
325  std::shared_ptr<GpsVelSensorData> sensor_data(std::make_shared<GpsVelSensorData>());
326  sensor_data->set_cov(P_updated);
327  sensor_data->state_ = corrected_sensor_state;
328 
329  BufferDataType state_entry(std::make_shared<CoreType>(core_data), sensor_data);
330 
331  if (const_ref_to_nav_)
332  {
333  // corrected_sensor_data.ref_to_nav = prior_ref_to_nav;
334  }
335  else
336  {
337  // TODO also estimate ref to nav
338  }
339 
340  *new_state_data = state_entry;
341 
342  return true;
343  }
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 PrintReport(const std::string &name)
PrintReport Print a formated report e.g. if the test did not pass.
static constexpr int size_error_
Definition: core_state_type.h:38
static CoreStateType ApplyCorrection(CoreStateType state_prior, Eigen::Matrix< double, CoreStateType::size_error_, 1 > correction)
ApplyCorrection.
Definition: core_state_type.h:46
Definition: ekf.h:92
Eigen::Matrix< double, 3, 1 > get_enu(mars::GpsCoordinates coordinates)
get_enu get current GPS reference coordinates
GpsVelSensorStateType ApplyCorrection(const GpsVelSensorStateType &prior_sensor_state, const Eigen::MatrixXd &correction)
Definition: gps_w_vel_sensor_class.h:345
bool use_dynamic_meas_noise_
True if dynamic noise values from measurements should be used.
Definition: sensor_abs_class.h:29
Eigen::VectorXd R_
Measurement noise "squared".
Definition: update_sensor_abs_class.h:32
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
Eigen::Matrix< double, CoreStateType::size_error_, 1 > CoreStateVector
Definition: core_state_type.h:135
+ Here is the call graph for this function:

◆ ApplyCorrection()

GpsVelSensorStateType mars::GpsVelSensorClass::ApplyCorrection ( const GpsVelSensorStateType prior_sensor_state,
const Eigen::MatrixXd &  correction 
)
inline
347  {
348  // state + error state correction
349  // with quaternion from small angle approx -> new state
350 
351  GpsVelSensorStateType corrected_sensor_state;
352  corrected_sensor_state.p_ig_ = prior_sensor_state.p_ig_ + correction.block(0, 0, 3, 1);
353  corrected_sensor_state.p_gw_w_ = prior_sensor_state.p_gw_w_ + correction.block(3, 0, 3, 1);
354  corrected_sensor_state.q_gw_w_ =
355  Utils::ApplySmallAngleQuatCorr(prior_sensor_state.q_gw_w_, correction.block(6, 0, 3, 1));
356  return corrected_sensor_state;
357  }
static Eigen::Quaterniond ApplySmallAngleQuatCorr(const Eigen::Quaterniond &q_prior, const Eigen::Vector3d &correction)
ApplySmallAngleQuatCorr.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ v_rot_axis_

Eigen::Vector3d mars::GpsVelSensorClass::v_rot_axis_ { 1, 0, 0 }
private

◆ use_vel_rot_

bool mars::GpsVelSensorClass::use_vel_rot_ { false }
private

◆ vel_rot_thr_

double mars::GpsVelSensorClass::vel_rot_thr_ { 0.3 }
private

◆ gps_conversion_

EIGEN_MAKE_ALIGNED_OPERATOR_NEW GpsConversion mars::GpsVelSensorClass::gps_conversion_

◆ using_external_gps_reference_

bool mars::GpsVelSensorClass::using_external_gps_reference_

◆ gps_reference_is_set_

bool mars::GpsVelSensorClass::gps_reference_is_set_

The documentation for this class was generated from the following file: