Skip to content
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

Fix BATTERY_STATUS voltage reporting #22009

Merged
merged 3 commits into from
Aug 29, 2023
Merged

Fix BATTERY_STATUS voltage reporting #22009

merged 3 commits into from
Aug 29, 2023

Conversation

julianoes
Copy link
Contributor

@julianoes julianoes commented Aug 26, 2023

This fixes two issues with voltage reporting in BATTERY_STATUS:

  1. The extension fields need to be 0 by default according to the MAVLink spec. This is because extensions are 0 by default and need to be 0 when unknown/unused for backwards compatibility.

  2. If the measured voltage is more than 65v we need to split the voltage over multiple cells in order to avoid overflowing the uint16. This is according to the MAVLink spec.

Needs backporting to v1.14.

Probably best reviewed commit by commit.

Tested using a Pixhawk 6C with power module and playing with the voltage divider.

This was found by @reedev after mavlink/MAVSDK#2114.

The extension fields need to be 0 by default according to the MAVLink
spec. This is because extensions are 0 by default and need to be 0 when
unknown/unused for backwards compatibility.

The patch also simplifies the flow slightly in that it doesn't create a
temporary array but just fills in the cell voltages directly.

Signed-off-by: Julian Oes <[email protected]>
If the measured voltage is more than 65v we need to split the voltage
over multiple cells in order to avoid overflowing the uint16. This is
according to the MAVLink spec.

Signed-off-by: Julian Oes <[email protected]>
bkueng
bkueng previously approved these changes Aug 28, 2023
Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side

MaEtUgR
MaEtUgR previously approved these changes Aug 28, 2023
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.

You thought about every case I went through 👍
It's good that you brought up the requirement for the zero-filled extension for compatibility. The original extension implementation did not follow this https://github.com/PX4/PX4-Autopilot/pull/17704/files#diff-a2164adeb58db340808a3233f23393127401db63695e200f4e0ba3beaada7d17R135 and I never changed that when reworking the logic. Also, the "distributed single cell" voltage support to work around MAVLink not defining a total voltage field makes sense.

src/modules/mavlink/streams/BATTERY_STATUS.hpp Outdated Show resolved Hide resolved
@julianoes julianoes dismissed stale reviews from MaEtUgR and bkueng via b11859f August 28, 2023 22:56
Co-authored-by: Matthias Grob <[email protected]>
@julianoes
Copy link
Contributor Author

Thanks for the reviews @bkueng and @MaEtUgR, appreciated!

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.

Thanks

@MaEtUgR MaEtUgR merged commit cde47e8 into main Aug 29, 2023
83 of 84 checks passed
@MaEtUgR MaEtUgR deleted the pr-fix-voltage_ext branch August 29, 2023 11:23
@reedev
Copy link

reedev commented Aug 30, 2023

Nice, it's working ok for me now. Just tested using the combination of PX4 master on a Cube Orange with MAVSDK main works ok. Thanks a lot.

How about back porting to release/1.13 and release/1.14? Is that still required or am I missing something? The whole issue started with release/1.13 and MAVSDK main for me.

@julianoes
Copy link
Contributor Author

Backport into v1.14 yes, v1.13 probably not.

@reedev
Copy link

reedev commented Aug 30, 2023

Ok, clear.

Fwiw, I tried out your recent change for MAVSDK main in combination with 1.13 and reported voltage is ok. Same for 1.14 btw but indeed better to backport.

@pedorich-n
Copy link

pedorich-n commented Sep 9, 2023

My PR with almost the same changes was open since July and unreviewed: #21827 😕

Thanks for fixing that problem anyway! I'm glad it's in the main now.

@julianoes
Copy link
Contributor Author

Oh, I'm sorry @pedorich-n. PX4 maintenance, issue triaging and PR reviewing is a big job, and there are only so many helping with that day by day.

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

Successfully merging this pull request may close these issues.

5 participants