mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 02:00:35 +08:00
Simulator: virtual battery drain stops by default at 50% to avoid failing preflight checks to take off again
also added comments and removed throttle compensation because there is no real battery emulation with load drop
This commit is contained in:
committed by
ChristophTobler
parent
8c998c1309
commit
385212f2c1
@@ -368,14 +368,16 @@ void Simulator::handle_message(mavlink_message_t *msg, bool publish)
|
||||
batt_sim_start = now;
|
||||
}
|
||||
|
||||
float ibatt = -1.0f;
|
||||
float ibatt = -1.0f; // no current sensor in simulation
|
||||
const float minimum_percentage = 0.5f; // change this value if you want to simulate low battery reaction
|
||||
|
||||
const float battery_time = (now - batt_sim_start) / discharge_interval_us;
|
||||
float vbatt = math::gradual(battery_time, 0.f, 1.f, _battery.full_cell_voltage(), _battery.empty_cell_voltage());
|
||||
/* Simulate the voltage of a linearly draining battery but stop at the minimum percentage */
|
||||
float battery_percentage = (now - batt_sim_start) / discharge_interval_us;
|
||||
battery_percentage = math::min(battery_percentage, minimum_percentage);
|
||||
float vbatt = math::gradual(battery_percentage, 0.f, 1.f, _battery.full_cell_voltage(), _battery.empty_cell_voltage());
|
||||
vbatt *= _battery.cell_count();
|
||||
|
||||
// TODO: don't hard-code throttle.
|
||||
const float throttle = 0.5f;
|
||||
const float throttle = 0.0f; // simulate no throttle compensation to make the estimate predictable
|
||||
_battery.updateBatteryStatus(now, vbatt, ibatt, true, true, 0, throttle, armed, &_battery_status);
|
||||
|
||||
// publish the battery voltage
|
||||
|
||||
Reference in New Issue
Block a user