simulator_mavlink: take care of battery percentage rounding errors

In 5bb9babc20 I made MAVLink send a
rounded up integer instead of rounded down. This makes sense in practice
because the low battery reactions happen exactly when the reported number
switches in the UI. But here we want to provoke an exact 50% in the UI so
we stop counting at 49.9%, it get's rounded up and we see the expected
result.
This commit is contained in:
Matthias Grob
2019-01-14 19:30:36 +01:00
parent a89e550f3c
commit 1e14b10dee
+1 -1
View File
@@ -327,7 +327,7 @@ void Simulator::handle_message(mavlink_message_t *msg, bool publish)
}
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 minimum_percentage = 0.499f; // change this value if you want to simulate low battery reaction
/* Simulate the voltage of a linearly draining battery but stop at the minimum percentage */
float battery_percentage = 1.0f - (now_us - batt_sim_start) / discharge_interval_us;