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

AP_BattMonitor: Do not report remaining battery percentage if battery capacity is set to 0 #13712

Merged
merged 11 commits into from
Sep 8, 2021

Conversation

Williangalvani
Copy link
Contributor

Sub had a regression from 3.5.4 where QGC now periodically complains about low battery.

According to the Mavlink specs this should be a int8_t and return -1 if there is no percentage counting:
https://mavlink.io/en/messages/common.html#BATTERY_STATUS
https://mavlink.io/en/messages/common.html#SYS_STATUS

@WickedShell
Copy link
Contributor

You need to go address the associated spots that access this to cope with a return value of -1. A lot of them use it as a uint8_t and the previous behaviour was okay for them, but showing 255 will be worse/breaking for them. (Mostly it's AP_Notify/OSD and Lua bindings that need to be updated).

@Williangalvani
Copy link
Contributor Author

@WickedShell updated.
I'm not sure I got the right formatting strings for AP_OSD and AP_Notify.

@WickedShell
Copy link
Contributor

Sorry I didn't make the comment when I made my earlier one. The best change here would be to make capacity_remaining_pct return a boolean, and fill in the percentage by reference. This would remove the special case on -1 in a lot of places (although some external places like MAVLink/FrSky would still need to just send out a -1 in that case).

If you don't want to take that on here we can open an issue for it, and tag it as a good first issue.

@Williangalvani
Copy link
Contributor Author

@WickedShell is this what you had in mind?

I have no idea of how to fix the Lua part doing it like this

@Williangalvani Williangalvani force-pushed the fix_percentage branch 2 times, most recently from f8ef898 to ea75836 Compare April 27, 2020 18:21
@Williangalvani
Copy link
Contributor Author

@WickedShell can you take a look now?

@Williangalvani
Copy link
Contributor Author

@WickedShell rebased

@rmackay9
Copy link
Contributor

@Williangalvani,

By the way, if you're having troubles getting this in you can also add the DevCallTopic tag or the DevCallEU label and then attend one of the two weekly PR meetings. The EU one is new, there's a blog post with the timing on ardupilot.org.

libraries/AP_BattMonitor/AP_BattMonitor.h Outdated Show resolved Hide resolved
libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp Outdated Show resolved Hide resolved
libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp Outdated Show resolved Hide resolved
libraries/GCS_MAVLink/GCS_Common.cpp Show resolved Hide resolved
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

Pretty sure we should change that parameter to be unsigned now. There are several cases in here where bad things are going to happen if it is negative, and making it unsigned in all the corners gives them assurances they don't need to worry about that case.

Apologies for flip-flopping on this.

libraries/AP_Frsky_Telem/AP_Frsky_SPort.cpp Show resolved Hide resolved
libraries/AP_OSD/AP_OSD_Screen.cpp Show resolved Hide resolved
Comment on lines +10 to +11
uint8_t percent = -1;
IGNORE_RETURN(capacity_remaining_pct(percent));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a change in behaviour - we're now going to log 255 rather than zero here.

I'm actually OK with that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think there's more information in 255 than a zero that could be mistaked by an empty battery.

send_uint16(DATA_ID_FUEL, (uint16_t)roundf(_battery.capacity_remaining_pct())); // send battery remaining
uint8_t percentage = 0;
IGNORE_RETURN(_battery.capacity_remaining_pct(percentage));
send_uint16(DATA_ID_FUEL, (uint16_t)roundf(percentage)); // send battery remaining
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this strike you as a bit weird?

We convert an integer to a float, round it, then cast it back into a uint16_t.

Similarly elsewhere.

Pre-existing, so not your problem to fix.

libraries/GCS_MAVLink/GCS_Common.cpp Outdated Show resolved Hide resolved
libraries/GCS_MAVLink/GCS_Common.cpp Outdated Show resolved Hide resolved
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.

None yet

10 participants