|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Owns the per-channel captured points and the fitted cubic for the calibration service. More...
#include <CubicCalibrationStore.hpp>
Public Member Functions | |
| CubicCalibrationStore (std::string file_path) | |
| void | register_channel (uint16_t uid, uint8_t board_id, uint8_t connector, uint8_t logical_ch, const std::string &role, const std::string &active_model="cubic", SensorKind kind=SensorKind::PT, const std::string &raw_unit="adc") |
| Attach/refresh identity + role + streaming model for a uid (idempotent; call at startup). | |
| CubicFit | add_point (uint16_t uid, double adc, double psi) |
| Append a capture point (raw ADC, reference PSI), cap history, and re-fit. | |
| void | note_capture (uint16_t uid, const CaptureQuality &q) |
| Record how the last capture on this uid went, for the UI to show. | |
| void | set_fit_curve (uint16_t uid, const std::vector< std::pair< double, double > > &curve) |
| Replace a robust uid's display fit-curve (sampled predict_pressure_psi points). | |
| void | clear_channel (uint16_t uid) |
| Drop all points, fit, and fit-curve for a uid (channel goes back to PENDING). | |
| const CubicFit * | fit_for (uint16_t uid) const |
| const CubicChannel * | channel (uint16_t uid) const |
| std::vector< uint16_t > | uids () const |
| bool | save () const |
| Atomically write the JSON record (temp + rename). | |
| size_t | load () |
| Load the JSON record, resume points, and re-fit each channel. | |
| bool | load_failed () const |
| True when load() could not read an existing file, so every curve here is a fallback rather than the operator's. | |
Static Public Member Functions | |
| static CubicFit | compute_fit (const std::vector< CubicPoint > &pts, int max_degree=3) |
| Least-squares polynomial of degree min(max_degree, n - 1) over pts. | |
Static Public Attributes | |
| static constexpr size_t | kMaxPoints = 20 |
Private Member Functions | |
| std::string | serialize () const |
Static Private Member Functions | |
| static void | refit (CubicChannel &ch) |
| Recompute fit_cubic / fit_linear / fit / status from ch.points per ch.active_model. | |
Private Attributes | |
| std::mutex | mutex_ |
| std::string | file_path_ |
| bool | load_failed_ = false |
| Set when load() could not read an existing file. | |
| std::map< uint16_t, CubicChannel > | channels_ |
Owns the per-channel captured points and the fitted cubic for the calibration service.
Thread-safe. Persists atomically to a single JSON file that is:
Definition at line 161 of file CubicCalibrationStore.hpp.
|
explicit |
Definition at line 32 of file CubicCalibrationStore.cpp.
References file_path_.
| CubicFit fsw::calibration::CubicCalibrationStore::add_point | ( | uint16_t | uid, |
| double | adc, | ||
| double | psi ) |
Append a capture point (raw ADC, reference PSI), cap history, and re-fit.
Returns the fit. For a robust uid the point is recorded for display only and an invalid fit is returned (the robust learner is updated by the service, not here).
Definition at line 153 of file CubicCalibrationStore.cpp.
References adc(), fsw::calibration::CubicPoint::adc, ch(), channels_, kMaxPoints, lock, mutex_, fsw::calibration::CubicPoint::psi, refit(), and fsw::calibration::CubicPoint::t.
Referenced by anonymous_namespace{test_cubic_store_namespace.cpp}::add_lc_points(), anonymous_namespace{test_cubic_store_namespace.cpp}::add_point_rejects_unknown_uid(), anonymous_namespace{test_cubic_store_namespace.cpp}::add_pt_points(), anonymous_namespace{test_lc_linear_fit.cpp}::cubic_model_is_unchanged(), disabled_board_orphan_is_not_applied(), anonymous_namespace{test_lc_linear_fit.cpp}::fill(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_needs_two_points(), main(), removed_board_does_not_win_the_logical_map(), and t7_role_follows_within_t7().
| const CubicChannel * fsw::calibration::CubicCalibrationStore::channel | ( | uint16_t | uid | ) | const |
Definition at line 226 of file CubicCalibrationStore.cpp.
References channels_, lock, mutex_, and nullptr.
Referenced by anonymous_namespace{test_cubic_store_namespace.cpp}::add_point_rejects_unknown_uid(), disabled_board_orphan_is_not_applied(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_model_fits_a_line(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_needs_two_points(), main(), removed_board_does_not_win_the_logical_map(), role_moved_to_t7_keeps_its_unit(), and t7_role_follows_within_t7().
| void fsw::calibration::CubicCalibrationStore::clear_channel | ( | uint16_t | uid | ) |
|
static |
Least-squares polynomial of degree min(max_degree, n - 1) over pts.
Public for tests.
Definition at line 90 of file CubicCalibrationStore.cpp.
References fsw::calibration::CubicFit::A, a, fsw::calibration::CubicFit::B, b, fsw::calibration::CubicFit::C, fsw::calibration::CubicFit::D, fsw::calibration::CubicFit::degree, fsw::calibration::CubicFit::norm_min, fsw::calibration::CubicFit::norm_scale, p, fsw::calibration::CubicFit::poly, fsw::calibration::CubicFit::rmse, and fsw::calibration::CubicFit::valid.
Referenced by refit().
| const CubicFit * fsw::calibration::CubicCalibrationStore::fit_for | ( | uint16_t | uid | ) | const |
Definition at line 218 of file CubicCalibrationStore.cpp.
References channels_, lock, and mutex_.
Referenced by anonymous_namespace{test_lc_linear_fit.cpp}::a_model_change_refits_without_a_capture(), anonymous_namespace{test_lc_linear_fit.cpp}::both_fits_are_serialized(), anonymous_namespace{test_lc_linear_fit.cpp}::cubic_model_is_unchanged(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_model_fits_a_line(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_needs_two_points(), main(), anonymous_namespace{test_lc_linear_fit.cpp}::raw_coefficients_match_the_normalized_form(), and anonymous_namespace{test_lc_linear_fit.cpp}::tare_cancels_zero_drift_on_linear_not_cubic().
| size_t fsw::calibration::CubicCalibrationStore::load | ( | ) |
Load the JSON record, resume points, and re-fit each channel.
Returns channels loaded.
Definition at line 387 of file CubicCalibrationStore.cpp.
References ch(), channels_, file_path_, kMaxPoints, fsw::calibration::kRawUnitAdc, fsw::calibration::kRawUnitMicrovolts, fsw::calibration::LC, load_failed_, lock, mutex_, p, fsw::calibration::PT, fsw::calibration::pt_logical_calibration_channel(), and refit().
Referenced by anonymous_namespace{test_lc_linear_fit.cpp}::both_fits_are_serialized(), disabled_board_orphan_is_not_applied(), engine.layerx.measurements.MeasurementStore::get(), anonymous_namespace{test_cubic_store_namespace.cpp}::kind_round_trip(), anonymous_namespace{test_cubic_store_namespace.cpp}::legacy_file_without_kind(), main(), anonymous_namespace{test_cubic_store_namespace.cpp}::recovery_regenerates_overwritten_pt_curve(), removed_board_does_not_win_the_logical_map(), role_moved_to_t7_keeps_its_unit(), t7_role_follows_within_t7(), and anonymous_namespace{test_cubic_store_namespace.cpp}::unreadable_file_is_not_overwritten().
|
inline |
True when load() could not read an existing file, so every curve here is a fallback rather than the operator's.
Callers that DERIVE from a curve (the LC tare recompute) must skip rather than persist a number computed against one.
Definition at line 201 of file CubicCalibrationStore.hpp.
References load_failed_, lock, and mutex_.
Referenced by main().
| void fsw::calibration::CubicCalibrationStore::note_capture | ( | uint16_t | uid, |
| const CaptureQuality & | q ) |
|
staticprivate |
Recompute fit_cubic / fit_linear / fit / status from ch.points per ch.active_model.
Caller holds mutex_. Robust channels are left to their own branch (no fit).
Definition at line 61 of file CubicCalibrationStore.cpp.
References ch(), and compute_fit().
Referenced by add_point(), load(), and register_channel().
| void fsw::calibration::CubicCalibrationStore::register_channel | ( | uint16_t | uid, |
| uint8_t | board_id, | ||
| uint8_t | connector, | ||
| uint8_t | logical_ch, | ||
| const std::string & | role, | ||
| const std::string & | active_model = "cubic", | ||
| SensorKind | kind = SensorKind::PT, | ||
| const std::string & | raw_unit = "adc" ) |
Attach/refresh identity + role + streaming model for a uid (idempotent; call at startup).
active_model is the config truth ("cubic"|"robust"|"linear"|"physics"); it takes precedence over a value restored from disk by load(). A channel that already holds points is re-fitted when its model changes, so switching cubic <-> linear in config needs no recapture.
Definition at line 36 of file CubicCalibrationStore.cpp.
References board_id, ch(), channels_, lock, mutex_, and refit().
Referenced by anonymous_namespace{test_lc_linear_fit.cpp}::a_model_change_refits_without_a_capture(), anonymous_namespace{test_cubic_store_namespace.cpp}::add_point_rejects_unknown_uid(), anonymous_namespace{test_lc_linear_fit.cpp}::both_fits_are_serialized(), anonymous_namespace{test_lc_linear_fit.cpp}::cubic_model_is_unchanged(), disabled_board_orphan_is_not_applied(), anonymous_namespace{test_lc_linear_fit.cpp}::fill(), anonymous_namespace{test_cubic_store_namespace.cpp}::kind_round_trip(), anonymous_namespace{test_cubic_store_namespace.cpp}::legacy_file_without_kind(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_needs_two_points(), anonymous_namespace{test_cubic_store_namespace.cpp}::logical_1_collision(), main(), anonymous_namespace{test_cubic_store_namespace.cpp}::pt_lc_logical_collision(), anonymous_namespace{test_cubic_store_namespace.cpp}::recovery_regenerates_overwritten_pt_curve(), removed_board_does_not_win_the_logical_map(), role_moved_to_t7_keeps_its_unit(), and t7_role_follows_within_t7().
| bool fsw::calibration::CubicCalibrationStore::save | ( | ) | const |
Atomically write the JSON record (temp + rename).
Definition at line 359 of file CubicCalibrationStore.cpp.
References file_path_, load_failed_, lock, mutex_, p, and serialize().
Referenced by anonymous_namespace{test_lc_linear_fit.cpp}::both_fits_are_serialized(), disabled_board_orphan_is_not_applied(), anonymous_namespace{test_cubic_store_namespace.cpp}::kind_round_trip(), anonymous_namespace{test_cubic_store_namespace.cpp}::legacy_file_without_kind(), combined_fsw_gui.ConfigManager::load(), anonymous_namespace{test_cubic_store_namespace.cpp}::logical_1_collision(), main(), anonymous_namespace{test_cubic_store_namespace.cpp}::pt_lc_logical_collision(), anonymous_namespace{test_cubic_store_namespace.cpp}::recovery_regenerates_overwritten_pt_curve(), removed_board_does_not_win_the_logical_map(), role_moved_to_t7_keeps_its_unit(), combined_fsw_gui.ConfigManager::set_actuator_label(), combined_fsw_gui.ConfigManager::set_sensor_label(), t7_role_follows_within_t7(), and anonymous_namespace{test_cubic_store_namespace.cpp}::unreadable_file_is_not_overwritten().
|
private |
Definition at line 241 of file CubicCalibrationStore.cpp.
References adc(), basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass >::array(), ch(), channels_, contains(), fsw::calibration::LC, p, and state.
Referenced by save().
| void fsw::calibration::CubicCalibrationStore::set_fit_curve | ( | uint16_t | uid, |
| const std::vector< std::pair< double, double > > & | curve ) |
| std::vector< uint16_t > fsw::calibration::CubicCalibrationStore::uids | ( | ) | const |
Definition at line 232 of file CubicCalibrationStore.cpp.
References ch(), channels_, lock, and mutex_.
Referenced by anonymous_namespace{test_cubic_store_namespace.cpp}::add_point_rejects_unknown_uid(), and main().
|
private |
Definition at line 214 of file CubicCalibrationStore.hpp.
Referenced by add_point(), channel(), clear_channel(), fit_for(), load(), note_capture(), register_channel(), serialize(), set_fit_curve(), and uids().
|
private |
Definition at line 210 of file CubicCalibrationStore.hpp.
Referenced by CubicCalibrationStore(), load(), and save().
|
staticconstexpr |
Definition at line 206 of file CubicCalibrationStore.hpp.
Referenced by add_point(), and load().
|
private |
Set when load() could not read an existing file.
Blocks save(), so an unreadable store is never replaced by the empty one we fell back to.
Definition at line 213 of file CubicCalibrationStore.hpp.
Referenced by load(), load_failed(), and save().
|
mutableprivate |
Definition at line 209 of file CubicCalibrationStore.hpp.
Referenced by add_point(), channel(), clear_channel(), fit_for(), load(), load_failed(), note_capture(), register_channel(), save(), set_fit_curve(), and uids().