AP_Periph: Use battery SOC only when available#32105
Open
lgarciaos wants to merge 1 commit intoArduPilot:masterfrom
Open
AP_Periph: Use battery SOC only when available#32105lgarciaos wants to merge 1 commit intoArduPilot:masterfrom
lgarciaos wants to merge 1 commit intoArduPilot:masterfrom
Conversation
1a5d019 to
0fa25c8
Compare
Contributor
Author
|
Fixed typo |
IamPete1
requested changes
Feb 5, 2026
Comment on lines
+129
to
+130
| _interim_state.state_of_charge_pct = msg.state_of_charge_pct; | ||
| _interim_state.has_state_of_charge_pct = true; |
Contributor
Author
There was a problem hiding this comment.
Thank you @IamPete1, I removed those lines and now I think it makes sense to me. SoC is already handled as it should.
0fa25c8 to
2d54029
Compare
magicrub
reviewed
Feb 6, 2026
| pkt.state_of_health_pct = state_of_health_pct; | ||
| } | ||
|
|
||
| pkt.state_of_charge_pct = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; |
Contributor
There was a problem hiding this comment.
Why not just do this?
Suggested change
| pkt.state_of_charge_pct = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; | |
| uint8_t percentage = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; | |
| if (battery_lib.capacity_remaining_pct(percentage, i)) { | |
| pkt.state_of_charge_pct = percentage; | |
| } |
Contributor
There was a problem hiding this comment.
Oh geez, I didn't mean that. No one look at that embarrassing suggestion! LOL. I meant this.. I SWEAR
Suggested change
| pkt.state_of_charge_pct = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; | |
| uint8_t percentage = 0; | |
| if (battery_lib.capacity_remaining_pct(percentage, i)) { | |
| pkt.state_of_charge_pct = percentage; | |
| } else { | |
| pkt.state_of_charge_pct = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; | |
| } |
or even a one-liner:
Suggested change
| pkt.state_of_charge_pct = UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; | |
| pkt.state_of_charge_pct = battery_lib.capacity_remaining_pct(percentage, i) ? percentage : UAVCAN_EQUIPMENT_POWER_BATTERYINFO_STATE_OF_CHARGE_UNKNOWN; |
Just trying to avoid the unnecessary double assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needs dronecan/DSDL#76