Lua Script battery:reset_remaining() mess up with consumed mah

I’ve made a simple Lua script in order to make a percentage estimation based on voltage reading of Li-Po batteries (I know it’s not the best way to estimate percentage), after calculating the percentage, I set this value to the battery monitor using battery:reset_remaining(). Doing so will set this new percentage and will be shown in Mission Planner. The problem is, doing a test with my drone, when reading the parameters, the Bat used EST (mah) is not saving the accumulated current used from the battery, the current being used is shown normally, but the accumulative value is not.

My guess is that somehow, forcing the battery percentage to a certain value is messing up with the accumulative current value, even when the function is called only once.

Tried also this example from the repo: ardupilot/libraries/AP_Scripting/applets/BattEstimate.lua at master · ArduPilot/ardupilot · GitHub
It has the same problem with the accumulated current.

Since there is no much information about how the function works on the docs.lua file I think there might be an error in how this function is being implemented.

Any thoughts?

I’m almost certain you are overwriting the value of the estimated capacity remaining when you call that method, so the behavior you’re experiencing is quite likely expected.

Don’t use the battery:reset_remaining() binding if you wish to retain the mAh consumed estimate.

Could you clarify that?

Source code shows clearly why that binding has an effect on mAh remaining - it manipulates the values directly:

Sorry, it’s the “Use Don’t use” that has me confused.

Edited. D* you autocorrect!

1 Like