|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Port of scripts/calibration/robust_calibration.py RobustCalibrationFramework: 9-parameter environmental basis, TLS, Bayesian update, RLS, GLR drift, Gauss–Markov bias, optional Allan σ_meas (AllanVariance.hpp). More...
#include <RobustCalibrationFramework.hpp>
Classes | |
| struct | PhysicalParams |
Public Member Functions | |
| RobustCalibrationFramework (int sensor_id) | |
| void | seed_from_factory_cubic (const PTCalibrationCoeffs &c) |
| Seed θ by ridge LS so Φ·θ ≈ factory cubic P(adc) on an ADC grid (same env as streaming). | |
| double | max_abs_error_vs_factory (const PTCalibrationCoeffs &factory_cubic) const |
| Max |Φ·θ − P_factory(adc)| over a dense ADC grid — sanity-check saved adjustments.json. | |
| void | set_theta_from_polynomial (const std::vector< double > &poly_coeffs, double adc_norm_min, double adc_norm_scale) |
| void | set_noise_coeffs (const NoiseCoefficients &c, double tau0=0.01) |
| std::pair< double, double > | predict_pressure_with_uncertainty (double adc_code, const EnvironmentalState &env) |
| Mean + σ; updates bias propagation clock. | |
| double | predict_pressure_psi (double adc_code) |
| Mean PSI for streaming (default env, used by calibration_service). | |
| void | add_calibration_point (const CalibrationPoint &point) |
| Zero / capture / reference — full Python add_calibration_point logic. | |
| int | sensor_id () const |
| size_t | calibration_points_count () const |
| Eigen::VectorXd | theta_mean () const |
| Eigen::MatrixXd | theta_cov () const |
| void | set_theta_mean_for_restore (const Eigen::VectorXd &t) |
| void | set_theta_cov_for_restore (const Eigen::MatrixXd &cov) |
| Eigen::MatrixXd | rls_P_matrix () const |
| void | set_rls_P_for_restore (const Eigen::MatrixXd &p) |
Static Public Attributes | |
| static constexpr int | N = 9 |
Private Member Functions | |
| Eigen::VectorXd | environmental_basis (double adc_code, const EnvironmentalState &env) const |
| std::pair< Eigen::VectorXd, Eigen::MatrixXd > | total_least_squares_calibration (const std::vector< CalibrationPoint > &points) const |
| std::pair< Eigen::VectorXd, Eigen::MatrixXd > | bayesian_update (const std::vector< CalibrationPoint > &new_points) |
| std::pair< Eigen::VectorXd, Eigen::MatrixXd > | recursive_least_squares_update (const CalibrationPoint &point) |
| std::pair< double, bool > | generalized_likelihood_ratio_test (const std::vector< CalibrationPoint > &points) const |
| double | extrapolation_variance (double adc_code) const |
| double | compute_measurement_variance (double adc_code, double tau) const |
| void | bias_propagate (double dt) |
| void | bias_update (double residual, double sigma_meas, double dt) |
| double | bias_contribution () const |
| double | bias_variance () const |
Private Attributes | |
| int | sensor_id_ |
| std::vector< CalibrationPoint > | calibration_points_ |
| Eigen::VectorXd | theta_mean_ |
| Eigen::MatrixXd | theta_cov_ |
| Eigen::MatrixXd | rls_P_ |
| double | forgetting_factor_ |
| double | glr_threshold_ |
| int | glr_window_size_ |
| double | env_variance_base_ |
| double | alpha_v_ |
| double | alpha_extrap_ |
| Eigen::MatrixXd | env_var_env_ |
| Eigen::MatrixXd | env_var_interaction_ |
| struct fsw::calibration::RobustCalibrationFramework::PhysicalParams | physical_ |
| Eigen::Vector3d | bias_b_ |
| Eigen::Matrix3d | bias_P_ |
| Eigen::Vector3d | bias_tau_ |
| double | bias_process_noise_ |
| std::chrono::steady_clock::time_point | last_pred_time_ |
| double | last_bias_update_t_ |
| double | inflation_factor_ |
| std::optional< NoiseCoefficients > | noise_coeffs_ |
| double | allan_tau0_ |
| std::deque< double > | recent_residuals_ |
| std::deque< double > | recent_uncertainties_ |
| double | sigma_ref_ |
Static Private Attributes | |
| static constexpr size_t | kCalibrationPointsMax = 50 |
Port of scripts/calibration/robust_calibration.py RobustCalibrationFramework: 9-parameter environmental basis, TLS, Bayesian update, RLS, GLR drift, Gauss–Markov bias, optional Allan σ_meas (AllanVariance.hpp).
Definition at line 40 of file RobustCalibrationFramework.hpp.
|
explicit |
Definition at line 21 of file RobustCalibrationFramework.cpp.
References allan_tau0_, alpha_extrap_, alpha_v_, bias_b_, bias_P_, bias_process_noise_, bias_tau_, env_var_env_, env_var_interaction_, env_variance_base_, forgetting_factor_, glr_threshold_, glr_window_size_, inflation_factor_, last_bias_update_t_, last_pred_time_, N, rls_P_, sensor_id(), sensor_id_, sigma_ref_, theta_cov_, and theta_mean_.
| void fsw::calibration::RobustCalibrationFramework::add_calibration_point | ( | const CalibrationPoint & | point | ) |
Zero / capture / reference — full Python add_calibration_point logic.
Definition at line 369 of file RobustCalibrationFramework.cpp.
References fsw::calibration::CalibrationPoint::adc_code, bayesian_update(), bias_b_, bias_contribution(), bias_P_, bias_update(), calibration_points_, fsw::calibration::CalibrationPoint::env, environmental_basis(), forgetting_factor_, generalized_likelihood_ratio_test(), kCalibrationPointsMax, last_bias_update_t_, N, fsw::calibration::CalibrationPoint::pressure, recent_residuals_, recursive_least_squares_update(), rls_P_, theta_cov_, theta_mean_, fsw::calibration::CalibrationPoint::timestamp, and fsw::calibration::CalibrationPoint::uncertainty.
|
private |
Definition at line 219 of file RobustCalibrationFramework.cpp.
References N, theta_cov_, theta_mean_, and total_least_squares_calibration().
Referenced by add_calibration_point(), and robust_calibration.RobustCalibrationFramework::add_calibration_point().
|
private |
Definition at line 154 of file RobustCalibrationFramework.cpp.
References bias_b_.
Referenced by add_calibration_point(), and predict_pressure_with_uncertainty().
|
private |
Definition at line 132 of file RobustCalibrationFramework.cpp.
References bias_b_, bias_P_, bias_process_noise_, and bias_tau_.
Referenced by bias_update(), and predict_pressure_with_uncertainty().
|
private |
Definition at line 144 of file RobustCalibrationFramework.cpp.
References bias_b_, bias_P_, and bias_propagate().
Referenced by add_calibration_point().
|
private |
Definition at line 158 of file RobustCalibrationFramework.cpp.
References bias_P_.
Referenced by predict_pressure_with_uncertainty().
|
inline |
Definition at line 71 of file RobustCalibrationFramework.hpp.
References calibration_points_.
|
private |
Definition at line 314 of file RobustCalibrationFramework.cpp.
References alpha_v_, env_variance_base_, fsw::calibration::measurement_uncertainty(), and noise_coeffs_.
Referenced by predict_pressure_with_uncertainty().
|
private |
Definition at line 163 of file RobustCalibrationFramework.cpp.
References fsw::calibration::EnvironmentalState::aging_factor, fsw::calibration::EnvironmentalState::humidity, fsw::calibration::EnvironmentalState::mounting_torque, N, physical_, fsw::calibration::EnvironmentalState::temperature, and fsw::calibration::EnvironmentalState::vibration.
Referenced by add_calibration_point(), generalized_likelihood_ratio_test(), max_abs_error_vs_factory(), predict_pressure_with_uncertainty(), recursive_least_squares_update(), seed_from_factory_cubic(), and total_least_squares_calibration().
|
private |
Definition at line 288 of file RobustCalibrationFramework.cpp.
References alpha_extrap_, calibration_points_, and p.
Referenced by predict_pressure_with_uncertainty().
|
private |
Definition at line 257 of file RobustCalibrationFramework.cpp.
References env_variance_base_, environmental_basis(), glr_threshold_, glr_window_size_, res, theta_mean_, and total_least_squares_calibration().
Referenced by add_calibration_point(), and robust_calibration.RobustCalibrationFramework::add_calibration_point().
| double fsw::calibration::RobustCalibrationFramework::max_abs_error_vs_factory | ( | const PTCalibrationCoeffs & | factory_cubic | ) | const |
Max |Φ·θ − P_factory(adc)| over a dense ADC grid — sanity-check saved adjustments.json.
Definition at line 95 of file RobustCalibrationFramework.cpp.
References fsw::calibration::PTCalibrationCoeffs::calculate_pressure(), environmental_basis(), and theta_mean_.
| double fsw::calibration::RobustCalibrationFramework::predict_pressure_psi | ( | double | adc_code | ) |
Mean PSI for streaming (default env, used by calibration_service).
Definition at line 364 of file RobustCalibrationFramework.cpp.
References predict_pressure_with_uncertainty().
| std::pair< double, double > fsw::calibration::RobustCalibrationFramework::predict_pressure_with_uncertainty | ( | double | adc_code, |
| const EnvironmentalState & | env ) |
Mean + σ; updates bias propagation clock.
Definition at line 324 of file RobustCalibrationFramework.cpp.
References fsw::calibration::EnvironmentalState::aging_factor, bias_contribution(), bias_propagate(), bias_variance(), compute_measurement_variance(), env_var_env_, env_var_interaction_, environmental_basis(), extrapolation_variance(), fsw::calibration::EnvironmentalState::humidity, inflation_factor_, last_pred_time_, fsw::calibration::EnvironmentalState::mounting_torque, recent_uncertainties_, fsw::calibration::EnvironmentalState::temperature, theta_cov_, theta_mean_, and fsw::calibration::EnvironmentalState::vibration.
Referenced by predict_pressure_psi().
|
private |
Definition at line 243 of file RobustCalibrationFramework.cpp.
References fsw::calibration::CalibrationPoint::adc_code, fsw::calibration::CalibrationPoint::env, environmental_basis(), forgetting_factor_, N, fsw::calibration::CalibrationPoint::pressure, rls_P_, theta_cov_, and theta_mean_.
Referenced by add_calibration_point(), and robust_calibration.RobustCalibrationFramework::add_calibration_point().
|
inline |
Definition at line 83 of file RobustCalibrationFramework.hpp.
References rls_P_.
| void fsw::calibration::RobustCalibrationFramework::seed_from_factory_cubic | ( | const PTCalibrationCoeffs & | c | ) |
Seed θ by ridge LS so Φ·θ ≈ factory cubic P(adc) on an ADC grid (same env as streaming).
The old 2-parameter linear seed could not match a cubic → robust read low vs factory.
Definition at line 61 of file RobustCalibrationFramework.cpp.
References fsw::calibration::PTCalibrationCoeffs::calculate_pressure(), environmental_basis(), N, rhs, rls_P_, theta_cov_, and theta_mean_.
|
inline |
Definition at line 68 of file RobustCalibrationFramework.hpp.
References sensor_id_.
Referenced by RobustCalibrationFramework().
| void fsw::calibration::RobustCalibrationFramework::set_noise_coeffs | ( | const NoiseCoefficients & | c, |
| double | tau0 = 0.01 ) |
Definition at line 127 of file RobustCalibrationFramework.cpp.
References allan_tau0_, and noise_coeffs_.
| void fsw::calibration::RobustCalibrationFramework::set_rls_P_for_restore | ( | const Eigen::MatrixXd & | p | ) |
Definition at line 433 of file RobustCalibrationFramework.cpp.
| void fsw::calibration::RobustCalibrationFramework::set_theta_cov_for_restore | ( | const Eigen::MatrixXd & | cov | ) |
Definition at line 428 of file RobustCalibrationFramework.cpp.
References N, and theta_cov_.
| void fsw::calibration::RobustCalibrationFramework::set_theta_from_polynomial | ( | const std::vector< double > & | poly_coeffs, |
| double | adc_norm_min, | ||
| double | adc_norm_scale ) |
Definition at line 113 of file RobustCalibrationFramework.cpp.
References theta_mean_.
| void fsw::calibration::RobustCalibrationFramework::set_theta_mean_for_restore | ( | const Eigen::VectorXd & | t | ) |
Definition at line 423 of file RobustCalibrationFramework.cpp.
References N, and theta_mean_.
|
inline |
Definition at line 78 of file RobustCalibrationFramework.hpp.
References theta_cov_.
Referenced by total_least_squares_calibration().
|
inline |
Definition at line 75 of file RobustCalibrationFramework.hpp.
References theta_mean_.
Referenced by total_least_squares_calibration().
|
private |
Definition at line 189 of file RobustCalibrationFramework.cpp.
References env_variance_base_, environmental_basis(), N, rhs, theta_cov(), theta_cov_, theta_mean(), and theta_mean_.
Referenced by bayesian_update(), robust_calibration.RobustCalibrationFramework::bayesian_update(), generalized_likelihood_ratio_test(), and robust_calibration.RobustCalibrationFramework::generalized_likelihood_ratio_test().
|
private |
Definition at line 127 of file RobustCalibrationFramework.hpp.
Referenced by RobustCalibrationFramework(), and set_noise_coeffs().
|
private |
Definition at line 104 of file RobustCalibrationFramework.hpp.
Referenced by extrapolation_variance(), and RobustCalibrationFramework().
|
private |
Definition at line 103 of file RobustCalibrationFramework.hpp.
Referenced by compute_measurement_variance(), and RobustCalibrationFramework().
|
private |
Definition at line 117 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), bias_contribution(), bias_propagate(), bias_update(), and RobustCalibrationFramework().
|
private |
Definition at line 118 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), bias_propagate(), bias_update(), bias_variance(), and RobustCalibrationFramework().
|
private |
Definition at line 120 of file RobustCalibrationFramework.hpp.
Referenced by bias_propagate(), and RobustCalibrationFramework().
|
private |
Definition at line 119 of file RobustCalibrationFramework.hpp.
Referenced by bias_propagate(), and RobustCalibrationFramework().
|
private |
Definition at line 91 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), calibration_points_count(), and extrapolation_variance().
|
private |
Definition at line 106 of file RobustCalibrationFramework.hpp.
Referenced by predict_pressure_with_uncertainty(), and RobustCalibrationFramework().
|
private |
Definition at line 107 of file RobustCalibrationFramework.hpp.
Referenced by predict_pressure_with_uncertainty(), and RobustCalibrationFramework().
|
private |
Definition at line 102 of file RobustCalibrationFramework.hpp.
Referenced by compute_measurement_variance(), generalized_likelihood_ratio_test(), RobustCalibrationFramework(), and total_least_squares_calibration().
|
private |
Definition at line 98 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), recursive_least_squares_update(), and RobustCalibrationFramework().
|
private |
Definition at line 99 of file RobustCalibrationFramework.hpp.
Referenced by generalized_likelihood_ratio_test(), and RobustCalibrationFramework().
|
private |
Definition at line 100 of file RobustCalibrationFramework.hpp.
Referenced by generalized_likelihood_ratio_test(), and RobustCalibrationFramework().
|
private |
Definition at line 124 of file RobustCalibrationFramework.hpp.
Referenced by predict_pressure_with_uncertainty(), and RobustCalibrationFramework().
|
staticconstexprprivate |
Definition at line 92 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point().
|
private |
Definition at line 123 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), and RobustCalibrationFramework().
|
private |
Definition at line 122 of file RobustCalibrationFramework.hpp.
Referenced by predict_pressure_with_uncertainty(), and RobustCalibrationFramework().
|
staticconstexpr |
Definition at line 42 of file RobustCalibrationFramework.hpp.
Referenced by engine.control.robust_ddp.data_models.ControllerConfig::__post_init__(), add_calibration_point(), bayesian_update(), environmental_basis(), fsw::calibration::RobustCalibrationManager::load_adjustments(), recursive_least_squares_update(), RobustCalibrationFramework(), fsw::calibration::RobustCalibrationManager::save_adjustments(), seed_from_factory_cubic(), set_rls_P_for_restore(), set_theta_cov_for_restore(), set_theta_mean_for_restore(), test_numba_ab_parity.TestRandomizedSweep::test_sweep(), and total_least_squares_calibration().
|
private |
Definition at line 126 of file RobustCalibrationFramework.hpp.
Referenced by compute_measurement_variance(), and set_noise_coeffs().
|
private |
Referenced by environmental_basis().
|
private |
Definition at line 129 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point().
|
private |
Definition at line 130 of file RobustCalibrationFramework.hpp.
Referenced by predict_pressure_with_uncertainty().
|
private |
Definition at line 96 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), recursive_least_squares_update(), rls_P_matrix(), RobustCalibrationFramework(), seed_from_factory_cubic(), and set_rls_P_for_restore().
|
private |
Definition at line 89 of file RobustCalibrationFramework.hpp.
Referenced by RobustCalibrationFramework(), and sensor_id().
|
private |
Definition at line 131 of file RobustCalibrationFramework.hpp.
Referenced by RobustCalibrationFramework().
|
private |
Definition at line 95 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), bayesian_update(), predict_pressure_with_uncertainty(), recursive_least_squares_update(), RobustCalibrationFramework(), seed_from_factory_cubic(), set_theta_cov_for_restore(), theta_cov(), and total_least_squares_calibration().
|
private |
Definition at line 94 of file RobustCalibrationFramework.hpp.
Referenced by add_calibration_point(), bayesian_update(), generalized_likelihood_ratio_test(), max_abs_error_vs_factory(), predict_pressure_with_uncertainty(), recursive_least_squares_update(), RobustCalibrationFramework(), seed_from_factory_cubic(), set_theta_from_polynomial(), set_theta_mean_for_restore(), theta_mean(), and total_least_squares_calibration().