feat(battery_simulator): single 0V sample failure injection

Use `failure battery intermittent` to trigger.
This commit is contained in:
Balduin
2026-03-19 10:15:34 +01:00
parent 547eb77a55
commit f8d9a3e68f
2 changed files with 18 additions and 0 deletions
@@ -109,6 +109,12 @@ void BatterySimulator::Run()
vbatt = _battery.empty_cell_voltage();
}
if (_zero_volt_spike) {
// Zero volt but only one sample. Replicates some I2C comm failures
vbatt = 0.0f;
_zero_volt_spike = false;
}
vbatt *= _battery.cell_count();
_battery.setConnected(true);
@@ -157,6 +163,17 @@ void BatterySimulator::updateCommands()
supported = true;
_force_empty_battery = true;
}
} else if (failure_type == vehicle_command_s::FAILURE_TYPE_INTERMITTENT) {
handled = true;
PX4_WARN("CMD_INJECT_FAILURE, battery intermittent (single 0V sample)");
supported = true;
if (instance == 0) {
supported = true;
_zero_volt_spike = true;
}
}
}
@@ -89,6 +89,7 @@ private:
bool _armed{false};
bool _force_empty_battery{false};
bool _zero_volt_spike{false};
perf_counter_t _loop_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")};