Simulation for Low Battery

Is there any way to simulate the fail safe logic with jMavSim or Gazebo?
I tried to search how to set the battery level on jMavSim or Gazebo, but I got nothing.

Please let me know the proper way :slight_smile:
Thank you!

As of October 2022, I am also looking for an answer. Only failure experiences can be shared.
In QGC, only values between 12% and 50% can be set in Failsafe setup, but in Gazebo simulator, PX4 does not lower the battery to 66% or less.

< Figure 1. QGC Battery Failsefe setup >

< Figure 2. Battery does not go down below 66% with Gazebo >

< Figure 3. MAVLink communication between example code and QGC >
I can lower the battery remaninig value by modifying the example code. However, this example code simply has the function of exchanging data with QGC with MAVLink(it is not a Firmware and dose not connected to QGC), so I cannot do BatteryFailsefe setup on QGC.

I would guess you have to go in and modify the parameter SIM_BAT_MIN_PCT which is supposed to be the lowest battery level in simulation. I have never done it myself, so don’t know if it actually works. Second options is similar to what you did in figure 1. and just Force save it. This is a bit of a hack around.

Thank you Mr Madsen.
Set the Battery Warn Level value to 50% (15% default) in QGC > Vehicle Setup > Safety > Low Battery Failsafe Trigger
(This value can also be changed by finding the BAT_LOW_THR value in Vehicle Setup > Parameters > Battery Calibration.)
After modifying the SIM_BAT_MIN_PCT value of Vehicle Setup > Parameters > SILT to 30% (default 50%), I was able to simulate the low battery situation.
The reason why the SIM_BAT_MIN_PCT value is set 20%point lower than the BAT_LOW_THR value is because
This is because in simulation, the lowest value of the battery seems to be always 16%point higher than the value of SIM_BAT_MIN_PCT.
So, the lowest battery remaining value shown in the QGC during simulation is (30+16)%
I don’t know why there is a 16% point difference.

Weird that is seems like it is 16% higher, I don’t know why that happens for you. But good that you are able to simulate the failsafe