-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Battery Estimation Corrections #8153
Conversation
src/modules/systemlib/battery.cpp
Outdated
|
||
// remaining charge estimate based on voltage and internal resistance (drop under load) | ||
float bat_v_empty_dynamic = _param_v_empty.get(); | ||
|
||
if (bat_r >= 0.0f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well use _param_r_internal.get() and _param_v_empty.get() directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_param_v_empty.get()
already gets used directly now.
bat_r
made it more readable in my opinion but you're right I should rename the block param to be more readable, that's better.
Thanks for already looking at it 👍
2128d23
to
f1c60c4
Compare
Looks like a good improvement. In my experience steady state payload and avionics power draw can be highly significant on some platforms. I’ve worked on several fixed wing systems where it was 1/3rd of the total power draw (average propulsion being 2/3rds). Do you think a new param to account for this might be worth while? Also, temperature is always the Achilles heel for these types of battery models.... very tough to model though since there are so many different chemistry types and battery temperature measurement isn’t common with hobby grade batteries. |
@Antiheavy Thanks for your kind words and additional ideas. You should probaly know that while I'm interested in the topic my goal here is to first fix the obvious things. When I tried with the current implementation and default configuration in simulation with a deep discharge voltage input I still had >10% left. We don't need advanced considerations to fix that. To your questions:
|
3e6f114
to
e1df47e
Compare
sorry for the delayed response. I should have looked at the code more carefully, I see that adding a steady state avionics draw wont really help here since it isn't doing a "time remaining" estimate. I was more lamenting the fact that temperature effects are complicated and without decent temp measurement and a complicated battery math model that is chemistry specific it is hard to get super accurate with just current and voltage measurement. That is okay, what you have here is still a nice improvement. |
The most severe but still basic problems are fixed and hence I suggest to merge this as the first take. I think there's still potential:
Note for the user: After merging this pr battery percentages have a new (maybe very old) correct meaning. When configuring the battery parameters as their description states 0% means the battery is completely empty. |
6205fff
to
3c58b9c
Compare
3c58b9c
to
071ad3a
Compare
I rebased, added my latest enhancement and wrote a description with examples in the original post. I don't know why CI fails which is why I currently assume it's not my mistake. I would personally not merge this before the 1.7 release. |
071ad3a
to
9818602
Compare
I rebased and adjusted the weight for the voltage estimate just a little bit such that it really results like shown in the plot with the simulated faulty battery that suddenly drops the voltage, now it's according to my tests on the safe side. Can someone else please test? Otherwise I would say it's ready to merge (still assuming CI is globally broken). |
… exactly empty it's a lot more readable and battery draining stops exactly at the empty battery voltage which makes debuging easier because it's directly predicatable
…eal world voltage drop under load
…er to verify estimation
…ro floats to make code more readable
…remaining capacity if capacity is configured
…nd doubled the time constant
…e to a useful value for reasonable lipo usage
…ling preflight checks to take off again also added comments and removed throttle compensation because there is no real battery emulation with load drop
9818602
to
0ad73ea
Compare
I rebased again to make it compatible with the changes here: 202c291#diff-23c67e906b712051714dd61b12fce367 I added the last commit to make sure SITL users can fly as musch as they want and ar not restricted from taking off again after one virtual battery is empty. |
After updating to master today I am having problems with battery estimation on a PixRacer. It keeps reporting critically low battery after seconds of flight and I had to enable the power circuit breaker to be able to take off more than once per boot. Could this PR be the cause of this @MaEtUgR ? I have not changed any parameters after updating. The parameters for number of cells, full and empty voltage, voltage divider and load drop are configured. All other values are untouched. I also failed to find PX4 specific battery estimator configuration documentation. All I found was the QGC doc page, which doesn't state much more than QGC itself. |
@ndepal Thanks for your report, sorry to hear that. The cause is likely this PR. That said I'm pretty sure it depends on the used parameters because we have a lot of multicopter flight hours on the pr. The only thing that's supposed to change is the scaling of the parameters in a way that the parameters really do exactly as their description says. I'll double check the default parameters and come up with some documentation, that's pretty important. Can you send me a log of the case in which you wasn't satisfied? Then I could track it down and help you more easily. |
@PX4/testflights Could you please comment on wether you found issues in today's master test flights? |
We are seeing a drop in voltage after taking off from 100% to 80% and to 70% after 1:30 minutes of flight, this didn't happen before. Here is a video of that behavior. |
@MaEtUgR Could you look into this? If we can't fix this quickly we need to roll back the changes. |
@r0gelion The video shows the problem very directly, do you have the log of this or a similar flight? It would help me to identify the problem without having to try all combination of parameters in hope to be able to reproduce. |
Here is a similar flight with the problem. The autopilot used is a Pixhawk 3 Pro, but also happens with Pixhawk 1 and Pixhawk mini |
|
@MaEtUgR |
Did this get added? Can you minimally please create a doc issue and link here. |
@hamishwillee It's linked above because I cross referenced, you found it: PX4/PX4-user_guide#131 |
Cheers! I did this one much earlier :-) |
The voltage correction (battery.cpp, L175) is wrong: the |
@pietrodn The original implementation from this pr was wrong because I overlooked the internal resistance parameter to be defined per cell and not per battery. See the fix here: https://github.com/PX4/Firmware/pull/8868/files After that I currently don't see how it should be still wrong. Deviding the current by the number of cells does theoretically not make sense because the full current has to flow through every cell. If that's not what you mean could you please explain in more detail? |
Moments after posting the previous comment, I realized I was just plain wrong. |
The battery percentage like it is right now is unpredictable jumping around and far from accurate.
also this is not really tunable because parameters do not meet invariants
low pass filter for battery state in there does not have time abstraction nor is it tunableit's dependent on execution frequency and unpredicatable
min(estimate_v, estimate_a)
but in reality this relation is not linear but rather quadratic in my experience.
generally known the voltage to remaining capacity function for li-po batteries is non-linearEDIT: While I was testing I found out that a big part of that nonlinearity comes from the load and can be corrected with the internal resisatnce model for the battery and total current measurements. So still non-linear but less severe.
EDIT: Crossed out points are moved to the next improvement step.
Let's change it, that's my take on the problem.
I noticed this pr is lacking a clear description for what it does:
BAT_V_CHARGED
andBAT_V_EMPTY
set the voltages where the estimate using the voltage shows 100% or 0% respectively. This is achieved by correcting the voltage measurement only internally for the estimation to correct for voltage sag caused by the battery load.Description: On bootup it initially takes the estimate calculated from voltage. While consuming energy it directly reduces the estimate with the integrated current. The voltage estimate gets encorporated with a very strong low pass filter. The lower (emptier) the estimate produced from voltage is, the stronger it gets encorporated to avoid deep discharging in case of wrong parameters or faulty battery.
Here's an example for how it should usually work:
Here's a theoretical reaction to a battery that would suddenly have a very low voltage (because it's faulty or the initial estimation was wrong or the parameters are not correct):
green: capacity based estimation
red: voltage based estimation
blue: resulting estimation from the fusion