STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
EKFNavigationEnhanced.hpp
Go to the documentation of this file.
1#ifndef EKF_NAVIGATION_ENHANCED_HPP
2#define EKF_NAVIGATION_ENHANCED_HPP
3
5#include "EKFNavigation.hpp"
6
7namespace fsw {
8namespace nav {
9
10/**
11 * @brief Enhanced EKF Navigation with Magnetometer Support
12 *
13 * Extends EKFNavigation to properly integrate magnetometer measurements
14 * for heading estimation and attitude correction.
15 */
16class EKFNavigationEnhanced : public EKFNavigation {
17public:
18 /**
19 * @brief Enhanced configuration with magnetometer parameters
20 */
21 struct EnhancedConfig : public EKFConfig {
22 // Magnetometer noise
23 double magnetometer_noise = 0.01; // Magnetometer noise (T²)
24 double magnetic_declination = 0.0; // Magnetic declination [rad]
25
26 // Magnetometer calibration
27 bool use_magnetometer = true; // Enable magnetometer fusion
28 bool use_magnetometer_for_heading = true; // Use mag for heading
29 double magnetometer_weight = 0.1; // Weight relative to gyro
30
31 // Heading estimation
33 double heading_process_noise = 0.01; // Heading process noise [rad²/s]
34 };
35
38
39 /**
40 * @brief Initialize with enhanced configuration
41 */
42 bool initialize(const EnhancedConfig& config, const NavigationState& initial_state);
43
44 /**
45 * @brief Process magnetometer measurement with calibration
46 * @param measurement Raw magnetometer reading
47 * @param calibrated Calibrated magnetometer reading
48 * @return true if processed successfully
49 */
51 const IMUMeasurement& measurement,
53
54 /**
55 * @brief Get heading estimate (from magnetometer + gyro fusion)
56 */
57 double getHeading() const;
58
59 /**
60 * @brief Get magnetic field estimate
61 */
62 Eigen::Vector3d getMagneticField() const;
63
64 /**
65 * @brief Set IMU calibration system
66 */
67 void setIMUCalibration(std::shared_ptr<calibration::IMUCalibrationSystem> calib_system);
68
69private:
70 // Enhanced measurement processing
71 void updateWithMagnetometer(const Eigen::Vector3d& mag_field);
72 Eigen::Vector3d computeMagnetometerMeasurement(const Eigen::VectorXd& state) const;
73 Eigen::MatrixXd computeMagnetometerJacobian(const Eigen::VectorXd& state) const;
74
75 // Heading estimation
76 double computeHeadingFromQuaternion(const Eigen::Quaterniond& q) const;
77 double computeHeadingFromMagnetometer(const Eigen::Vector3d& mag_field,
78 const Eigen::Quaterniond& q) const;
79
81 std::shared_ptr<calibration::IMUCalibrationSystem> imu_calibration_;
82
83 // Magnetic field state
84 Eigen::Vector3d magnetic_field_; // Estimated magnetic field [T]
85 double heading_; // Estimated heading [rad]
86 mutable std::mutex mag_mutex_;
87};
88
89} // namespace nav
90} // namespace fsw
91
92#endif // EKF_NAVIGATION_ENHANCED_HPP
static bool calibrated
Definition board_adc.c:17
bool initialize(const EnhancedConfig &config, const NavigationState &initial_state)
Initialize with enhanced configuration.
Eigen::MatrixXd computeMagnetometerJacobian(const Eigen::VectorXd &state) const
Eigen::Vector3d getMagneticField() const
Get magnetic field estimate.
bool processMagnetometerMeasurement(const IMUMeasurement &measurement, const calibration::IMUCalibration::CalibratedReading &calibrated)
Process magnetometer measurement with calibration.
double computeHeadingFromMagnetometer(const Eigen::Vector3d &mag_field, const Eigen::Quaterniond &q) const
void setIMUCalibration(std::shared_ptr< calibration::IMUCalibrationSystem > calib_system)
Set IMU calibration system.
void updateWithMagnetometer(const Eigen::Vector3d &mag_field)
double getHeading() const
Get heading estimate (from magnetometer + gyro fusion).
std::shared_ptr< calibration::IMUCalibrationSystem > imu_calibration_
double computeHeadingFromQuaternion(const Eigen::Quaterniond &q) const
Eigen::Vector3d computeMagnetometerMeasurement(const Eigen::VectorXd &state) const
static ActuatorControllerState state
Definition main.cpp:57
Motorized ball valve position: raw ADC counts -> % open.
Enhanced configuration with magnetometer parameters.