Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions projects/rc_vehicle/firmware/common/calibration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void CalibrationManager::ProcessForwardDirectionRequest() {
// до следующей полной калибровки.
const auto& d = imu_calib_.GetData();
madgwick_.SetVehicleFrame(d.gravity_vec, d.accel_forward_vec, true);
frame_changed_ = true;
pending_effects_.reference_frame_changed = true;

// Сбросить EKF — симметрично ProcessCompletion() (код-ревью PR #290,
// 10-й раунд): vx/vy персистентны и выражены в СТАРЫХ осях forward/
Expand All @@ -179,6 +179,7 @@ void CalibrationManager::ProcessForwardDirectionRequest() {
// апдейты после ручной смены направления «вперёд» посреди сессии.
if (ekf_) {
ekf_->Reset();
pending_effects_.ekf_reset = true;
platform_.Log(LogLevel::Info,
"EKF state reset after forward direction change");
}
Expand Down Expand Up @@ -252,12 +253,13 @@ void CalibrationManager::ProcessCompletion(uint32_t now_ms) {
if (imu_calib_.GetMode() != CalibMode::GyroOnly) {
const auto& d = imu_calib_.GetData();
madgwick_.SetVehicleFrame(d.gravity_vec, d.accel_forward_vec, true);
frame_changed_ = true; // см. ConsumeFrameChanged()
pending_effects_.reference_frame_changed = true;
}

// Сбросить EKF, чтобы скорость обнулилась после калибровки
if (ekf_) {
ekf_->Reset();
pending_effects_.ekf_reset = true;
platform_.Log(LogLevel::Info, "EKF state reset after calibration");
}
if (event_log_) {
Expand Down Expand Up @@ -303,4 +305,4 @@ void CalibrationManager::StartAutoCalibration() {
"IMU auto-calibration started (Full, 1000 samples)");
}

} // namespace rc_vehicle
} // namespace rc_vehicle
24 changes: 16 additions & 8 deletions projects/rc_vehicle/firmware/common/calibration_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace rc_vehicle {
// Forward declaration
class VehicleEkf;

/** Side effects produced while processing pending calibration work. */
struct CalibrationEffects {
bool reference_frame_changed{false};
bool ekf_reset{false};
};

/**
* @brief Менеджер калибровки IMU
*
Expand Down Expand Up @@ -146,7 +152,8 @@ class CalibrationManager {
* При каждом старте/завершении/ошибке калибровки записывается событие.
* Передайте nullptr чтобы отключить запись.
*
* @param log Указатель на TelemetryEventLog (время жизни ≥ CalibrationManager)
* @param log Указатель на TelemetryEventLog (время жизни ≥
* CalibrationManager)
*/
void SetEventLog(TelemetryEventLog* log) { event_log_ = log; }

Expand All @@ -173,10 +180,11 @@ class CalibrationManager {
* они интерпретируют старые (сошедшиеся под ПРЕЖНИМ базисом) значения
* тангажа/крена в НОВОЙ СК (код-ревью PR #290, 5-й/6-й раунды).
*/
[[nodiscard]] bool ConsumeFrameChanged() {
const bool v = frame_changed_;
frame_changed_ = false;
return v;
/** Return and clear all calibration side effects for this control tick. */
[[nodiscard]] CalibrationEffects ConsumeEffects() {
const CalibrationEffects effects = pending_effects_;
pending_effects_ = {};
return effects;
}

private:
Expand All @@ -202,10 +210,10 @@ class CalibrationManager {
// Предыдущий статус калибровки (для логирования только при переходах)
CalibStatus prev_calib_status_{CalibStatus::Idle};

// См. ConsumeFrameChanged(). Пишется только из ProcessCompletion()/
// См. ConsumeEffects(). Пишется только из ProcessCompletion()/
// ProcessForwardDirectionRequest() — обе вызываются исключительно с
// потока control loop, обычный bool безопасен.
bool frame_changed_{false};
CalibrationEffects pending_effects_{};

// Опциональный лог событий (не владеет объектом)
TelemetryEventLog* event_log_{nullptr};
Expand All @@ -215,4 +223,4 @@ class CalibrationManager {
static constexpr float kCruiseDurationSec = 1.0f;
};

} // namespace rc_vehicle
} // namespace rc_vehicle
Loading
Loading