Skip to content

Conversation

DonLakeFlyer
Copy link
Contributor

@DonLakeFlyer DonLakeFlyer commented May 4, 2025

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.

@DonLakeFlyer
Copy link
Contributor Author

Jake made a build for me and I tested and verified this fixes the problem.

@dakejahl
Copy link
Contributor

dakejahl commented May 5, 2025

@afwilkin can you test this out and verify it resolves #24645?

@dakejahl
Copy link
Contributor

dakejahl commented May 5, 2025

Yeah that logic looks backwards. I see the code was last changed by @MaEtUgR in 2023

@afwilkin
Copy link
Contributor

afwilkin commented May 5, 2025

@afwilkin can you test this out and verify it resolves #24645?

Yes.

@afwilkin
Copy link
Contributor

afwilkin commented May 5, 2025

@DonLakeFlyer @dakejahl

It appears that this solves the issue, but only for power modules talking over I2C.
So it now works for FC that abide by 6X, but not 6C or pixhawk 4

6xrt: https://www.loom.com/share/f12ecc374f88477c95596b1fb814830a?sid=a829a799-9c19-4bdf-a27c-398adbf7c391
Pixhawk 4: https://www.loom.com/share/24e3210fae6f4bd490fb28e5c35fd735?sid=404b4b99-fccf-43fe-8bad-6eba87c7567f

@afwilkin
Copy link
Contributor

afwilkin commented May 5, 2025

this is with the battery unplugged (and not plugged in from bootup)
image

and after plugging in
image

So something is starting the driver that then emits a starting battery status message

_battery.setConnected(false);

@DonLakeFlyer
Copy link
Contributor Author

FYI: I was running on a 6x with a Holybro can bus power module.

@MaEtUgR
Copy link
Member

MaEtUgR commented May 6, 2025

@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:

  1. If a power module is present, battery_status is published regularly, allowing detection of battery presence for ESC calibration.
  2. The regularly published battery_status message accurately reflects connection status via the connected field.
    I validated this in Fix PWM/Oneshot calibration #21711 on a Holybro Pixhawk 4 Mini with its default power module, but incorrectly assumed all power module drivers behaved consistently.

In the change of this pr I'm interpreting the assumption to be:

  1. The battery is connected if battery_status is published regularly, regardless of the connected field.
  2. The battery is disconnected if battery_status stops publishing and the last message had connected == false.

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.

@DonLakeFlyer
Copy link
Contributor Author

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

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.

@DronecodeBot
Copy link

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

@brettkoonce
Copy link

Built (linux), tested with Pixhawk 6x, allows me to perform ESC calibration (wasn't able to before).

@afwilkin
Copy link
Contributor

afwilkin commented May 9, 2025

@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

@dakejahl
Copy link
Contributor

dakejahl commented May 9, 2025

@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
https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/battery_status/analog_battery.cpp#L111-L114

@afwilkin
Copy link
Contributor

@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).

@afwilkin
Copy link
Contributor

@dakejahl @DonLakeFlyer
worked on 6XRT and Pixhawk 4, so... good on my end. If anyone else wants to checkout my single line of code I added

@DronecodeBot
Copy link

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

@MaEtUgR
Copy link
Member

MaEtUgR commented May 14, 2025

@afwilkin I'm so sorry for not following up timely 🙈 and thanks for your persistence.
I studied your change in the Analog battery driver and even though it might solve the apparent issue I think how things currently work it duplicates the battery class level check that uses voltage to determine if a battery is there:

// Require minimum voltage otherwise override connected status
if (_voltage_v < LITHIUM_BATTERY_RECOGNITION_VOLTAGE) {
_connected = false;
}

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.

@mrpollo mrpollo moved this from Todo to Blockers in PX4 v1.16 Release May 21, 2025
@afwilkin
Copy link
Contributor

afwilkin commented Jun 2, 2025

@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

  • calibrate esc: pass
  • calibrate multiple times in row without complete power cycle: pass
  • calibrate without battery connected: pass (still went through the calibration, but threw no errors which is expected)
  • attempt to initiate calibration with battery connected: pass (threw warning)

NXP

  • calibrate esc: passed
  • calibrate multiple times in row without complete power cycle: pass
  • calibrate without battery connected: pass (still went through the calibration, but threw no errors which is expected)
  • attempt to initiate calibration with battery connected: pass (threw warning)
  • start calibration and plug in AFTER the request to plug in DURING the message that states we are performing calibration: pass (the ESCs did not actually calibrate but the motors didnt spin up or have anything dangerous happen)

Seems good to merge in my opinion

Copy link
Member

@MaEtUgR MaEtUgR left a 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 👍

@MaEtUgR MaEtUgR merged commit 84cb748 into main Jun 4, 2025
66 checks passed
@MaEtUgR MaEtUgR deleted the ESCCal branch June 4, 2025 15:11
@github-project-automation github-project-automation bot moved this from In Progress to Done in Flight Testing ✈️ Jun 4, 2025
@github-project-automation github-project-automation bot moved this from Blockers to Done in PX4 v1.16 Release Jun 4, 2025
@DronecodeBot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Done

7 participants