-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Fix reporting of connected battery #24800
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
Conversation
Jake made a build for me and I tested and verified this fixes the problem. |
Yeah that logic looks backwards. I see the code was last changed by @MaEtUgR in 2023 |
It appears that this solves the issue, but only for power modules talking over I2C. 6xrt: https://www.loom.com/share/f12ecc374f88477c95596b1fb814830a?sid=a829a799-9c19-4bdf-a27c-398adbf7c391 |
FYI: I was running on a 6x with a Holybro can bus power module. |
@DonLakeFlyer Thanks for narrowing down the issue! If the change in this pr works at least on some setups then the power module/battery drivers handle battery connection status inconsistently. My original assumption was:
In the change of this pr I'm interpreting the assumption to be:
Both approaches only work with a subset of drivers. The proper fix is to define and document consistent behavior, align all drivers, and test them thoroughly, including ESC calibration. On that note since you already see the pain @DonLakeFlyer how hard would it be to adjust the ESC calibration procedure slightly as in making it a step by step assistant that the user can manually click through instead of being dependent on an automatic battery detection that e.g. doesn't work if the flight control board cannot be powered through USB and hence without the power module? I'd assume the implementation would be simpler, harder to break and the user experience very predictable and easy to understand. It might not look as "slick" if it doesn't progress automatically but then work all the time. I would gladly do the autopilot side and test if you could adjust the ground station. |
I'm fine with that. All of this setup/calibration stuff which depends on text messages from the vehicles side is just major nastiness anyway. There should be a real protocol created for this. |
This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there: https://discuss.px4.io/t/px4-team-sync-and-community-q-a-may-7-2025/45433/1 |
Built (linux), tested with Pixhawk 6x, allows me to perform ESC calibration (wasn't able to before). |
@MaEtUgR I know we spoke on the call, but if you could point me to where in the code the analog battery data emits a battery_status message (or how we should go modifying it) I would appreciate it |
There's a common interface via the Battery class |
@dakejahl ... probably should have been able to find that on my own. I put in some logic to not publish battery_status when voltage is below 0.1 (was detecting 0.01V when battery was unplugged). I was able to test on Pixhawk4 and worked. Will test Monday when back in the office on 6xrt (NXP). |
@dakejahl @DonLakeFlyer |
This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there: https://discuss.px4.io/t/px4-dev-call-may-14-2025-team-sync-and-community-q-a/45516/1 |
…ed if there's no message timeout and the connected flag is set
@afwilkin I'm so sorry for not following up timely 🙈 and thanks for your persistence. PX4-Autopilot/src/lib/battery/battery.cpp Lines 116 to 119 in 47cb113
So what I suggest is to simplify the battery detection high-level logic in that function which is only used to gate the start of the ESC calibration. My suggestion is to consider the battery connected if it regularly reports the status and the flag connected in it is true. So if it times out (case that @DonLakeFlyer fixed) or it reports the status but the connected flag is false (case that @afwilkin fixed) the battery is disconnected and I think that should cover both ways battery drivers act when the battery/power module is not there (anymore). @afwilkin Could you give this another try on both types of power modules Analog and ADS1115 (or UAVCAN seems to behave the same)? If somehow possible please also try to break it (without propellers!) to e.g. start calibration with power which is potentially a safety threat would spin up the ESCs. |
@MaEtUgR now i have to apologize for not doing this in a timely manner. This new code looks great. Everything seems to have passed Pixhawk 6c
NXP
Seems good to merge in my opinion |
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.
@afwilkin Thanks a lot for your testing. I see it was successfull so let's bring this in and I'll also port to the 1.16 release 👍
This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there: https://discuss.px4.io/t/px4-dev-call-june-4-2025-team-sync-and-community-q-a/45866/1 |
Fixes #24401
Fixes #24645
Fixes #24639
I haven't been able to verify this since I can't seem to build a firmware on Mac arm. But I believe this fixes the problem. Hopefully someone else can verify. And then this needs to get into v1.16 as well however that happens.