Compare commits

...

8 Commits

Author SHA1 Message Date
Balduin 8e1285a770 fix(battery_simulator): reword short param description
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
2026-04-10 09:08:43 +02:00
Balduin f744dba2bc fix(battery_simulator): reword long param description
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
2026-04-10 09:08:36 +02:00
Balduin 1813141308 fix(battery_simulator): remove arbitrary param max 2026-04-10 08:54:05 +02:00
Balduin ab7e7b59bb fix(battery_simulator): constrain param to min of 1
to avoid division by zero.

This reverts commit 6380c4fdee.
2026-04-10 08:51:40 +02:00
Balduin 6380c4fdee fix(battery_simulator): remove constraining again
now that SIM_BAT_DRAIN=0 means the module is not started we are safe
from division by zero again (param compare has a tolerance of 1e-7)
2026-04-09 09:05:24 +02:00
Balduin da9d8342db fix(battery_simulator): disable if 0, adjust limit to 0 2026-04-08 08:56:20 +02:00
Balduin e29e69f36b fix(battery_simulator): disable battery sim only if SIM_BAT_DRAIN strictly < 0 2026-04-07 09:53:42 +02:00
Balduin b73d5ff7f6 refactor(battery_simulator): remove SIM_BAT_ENABLE
disable instead with SIM_BAT_DRAIN <= 0
2026-03-20 09:01:49 +01:00
4 changed files with 8 additions and 15 deletions
+1 -1
View File
@@ -249,7 +249,7 @@ fi
load_mon start
if param compare SIM_BAT_ENABLE 1
if param greater SIM_BAT_DRAIN 0
then
battery_simulator start
fi
+1 -1
View File
@@ -47,7 +47,7 @@ To control how fast the battery depletes to the minimal value use the parameter
By changing [SIM_BAT_MIN_PCT](../advanced_config/parameter_reference.md#SIM_BAT_MIN_PCT) in flight, you can also test regaining capacity to simulate inaccurate battery state estimation or in-air charging technology.
:::
It is also possible to disable the simulated battery using [SIM_BAT_ENABLE](../advanced_config/parameter_reference.md#SIM_BAT_ENABLE) in order to, for example, provide an external battery simulation via MAVLink.
The simulated battery can be completely disabled by setting [SIM_BAT_DRAIN](../advanced_config/parameter_reference.md#SIM_BAT_DRAIN) to 0. This is useful, for example, if you provide an external battery simulation via MAVLink.
## Sensor/System Failure
@@ -85,7 +85,8 @@ void BatterySimulator::Run()
const hrt_abstime now_us = hrt_absolute_time();
const float discharge_interval_us = _param_sim_bat_drain.get() * 1000 * 1000;
// Limit to +1.0 s to guard against division by 0
const float discharge_interval_us = math::max(_param_sim_bat_drain.get(), 1.0f) * 1000 * 1000;
if (_armed) {
if (_last_integration_us != 0) {
@@ -2,22 +2,14 @@ module_name: battery_simulator
parameters:
- group: SITL
definitions:
SIM_BAT_ENABLE:
description:
short: Simulator Battery enabled
long: |-
Enable or disable the internal battery simulation. This is useful
when the battery is simulated externally and interfaced with PX4
through MAVLink for example.
type: boolean
default: 1
SIM_BAT_DRAIN:
description:
short: Simulator Battery drain interval
short: Simulated battery full-discharge time
long: |-
Time in seconds for the simulated battery to drain from 100% to 0% while armed. Set to 0 to disable the battery simulator entirely (useful when battery state is provided externally, e.g. via MAVLink).
type: float
default: 60
min: 1
max: 86400
min: 0
increment: 1
unit: s
SIM_BAT_MIN_PCT: