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

Fixed reporting of battery voltages in uORB #14151

Closed

Conversation

AmeliaEScott
Copy link
Contributor

Describe problem solved by this pull request
The Battery library does not populate the field voltage_cell_v of battery_status uORB message, because the analog power monitor and INA226 power monitor cannot measure individual cells. To get around this, the mavlink module populated the BATTERY_STATUS MAVLink message by dividing the total voltage by the number of cells. This was fixed in #13936, so the mavlink module now uses the voltage_cell_v field of the battery_status uORB message.

The issue now is that the MAVLink BATTERY_STATUS message does not have a field for total voltage, only for individual cell voltages. However, SYS_STATUS only has one field for battery voltage. So, to report the voltage of multiple batteries to the ground station, multiple instances of BATTERY_STATUS are sent. Therefore, to properly report the status of multiple batteries, one of two things must happen:

  • The cell voltages in the BATTERY_STATUS message must be populated
  • A MAVLink message must be changed: Possibly adding a total_voltage field to BATTERY_STATUS

Describe your solution
This PR replicates the old behavior, of dividing the total voltage by the number of cells. However, this is now done in the Battery library rather than in the mavlink module, so it only affects power monitors that were not measuring individual cell voltage anyway.

As discussed in #13936, this is not ideal, because it can give the impression that every cell is fine, even if one is dying. There should be a discussion about the best way to solve this issue. This PR just gives one possible solution.

Describe possible alternatives
The BATTERY_STATUS MAVLink message could be changed to add a total_voltage field, so that any power monitor can reliably report only the information that it actually measures.

Test data / coverage
This was tested on both a v5x with INA226 power monitors and a Pixhawk 4 with analog power monitors. In both cases, two different batteries with 2 different cell counts were used. The uORB battery_status message, and MAVLink BATTERY_STATUS message, and the voltage reported in the AGS UI were all verified.

@dakejahl
Copy link
Contributor

FYI @AlexKlimaj

@AlexKlimaj
Copy link
Member

One issue I see with this is that uavcan does not transmit the number of cells. So the uavcan battery driver would need the N cells param set by the user.
#14198

@julianoes
Copy link
Contributor

@MaEtUgR do you agree with this change? Or is this actually against what you did in #13936?

@MaEtUgR
Copy link
Member

MaEtUgR commented Mar 26, 2020

@julianoes Thanks for asking, like @ItsTimmy describes nicely the difference is that before my fix it wasn't possible to report the real cell voltages via MAVLink and with this pr it's just populating them with fake divided by cell count values for the main power module ADC source that does not allow cell voltage measurement. I think the real solution is to

MAVLink message must be changed: Possibly adding a total_voltage field to BATTERY_STATUS

because if I get a cell voltage report I presume it's a cell voltage and not a calculated value and check for if all cell voltages "by accident" have exactly the same value to know it's not real cell voltages.

Nevertheless, I think we should merge this pr as an in between solution to fix multi battery reporting. Can I quickly put some finishing touches and you review them?

@MaEtUgR
Copy link
Member

MaEtUgR commented Mar 26, 2020

@ItsTimmy What about reporting one cell voltage the whole battery if cell voltage measurement is not supported? Would that work?

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.

I would do it this way: https://github.com/PX4/Firmware/compare/pr-battery-cell-voltages The rest of the fields is already zeroed in the reset.

@julianoes
Copy link
Contributor

@MaEtUgR I guess I don't really understand it. Would you mind just doing the change that you suggest?

@MaEtUgR
Copy link
Member

MaEtUgR commented Mar 30, 2020

It's a private branch but I can open a new pr based on my branch if that's ok with @ItsTimmy

@MaEtUgR
Copy link
Member

MaEtUgR commented Mar 30, 2020

I opened one as a possible replacement: #14533

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

Successfully merging this pull request may close these issues.

5 participants