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

Add calibration parameters for multiple batteries #12551

Merged
merged 3 commits into from
Dec 5, 2019

Conversation

AmeliaEScott
Copy link
Contributor

Describe problem solved by the proposed pull request
Support for multiple batteries was improved in #12034 , but there is still the issue that different batteries all use the same calibration parameters.

Test data / coverage
On Pixhawk 4, multiple batteries with different levels of charge and numbers of cells were tested.

This PR makes changes that affect all different boards, so more testing should be done on different hardware.

Describe your preferred solution
Improved the Battery library by adding the ability to instantiate different batteries with different sets of parameters. Split power reading in sensors module into a separate class for readability.

Additional context
In the near future, support for digital power meters will be expanded, continuing the work done in #11755. This refactoring should make supporting this new source of battery data, as well as any future new sources, easier.

@AmeliaEScott
Copy link
Contributor Author

@feemi Follow-up from our discussion in #12034: This PR will hopefully address the issues you were having before. Would you mind testing it with your setup?

@hamishwillee
Copy link
Contributor

@ItsTimmy This will have a docs impact and possibly quite a complex QGC UI change. Please ping me when you think it is time to engage re docs. The main doc to change would be : http://docs.px4.io/master/en/config/battery.html

And presumably we may need to change the failsafe behaviour too: http://docs.px4.io/master/en/config/safety.html#low-battery-failsafe

@AmeliaEScott AmeliaEScott force-pushed the pr-digital-battery branch 12 times, most recently from 66b4f3d to ed137a4 Compare July 26, 2019 13:48
@dagar dagar requested review from davids5 and dagar July 29, 2019 17:22
@dagar
Copy link
Member

dagar commented Jul 29, 2019

This is looking good, but I think we should briefly take a step back and try to sketch out a rough overall design that factors in all the current requirements.

  • different battery types (analog bricks, digital bricks, smart batteries)
    • battery_status message
  • multiple instances
    • parameter instances?
  • overall system estimate (reporting, failsafe handling, etc)
  • system power architecture
    • if you have multiple batteries what's the overall percentage?
  • refactoring to cleanup the mess scattered across each platform adc and the sensors module

@ItsTimmy @davids5 let's schedule a call.

@dagar
Copy link
Member

dagar commented Jul 29, 2019

Related #12033

@AmeliaEScott AmeliaEScott force-pushed the pr-digital-battery branch 3 times, most recently from db2b8ff to 48034ca Compare August 2, 2019 09:48
@AmeliaEScott AmeliaEScott force-pushed the pr-digital-battery branch 2 times, most recently from 89f127b to 06d774f Compare August 9, 2019 08:12
@AmeliaEScott AmeliaEScott marked this pull request as ready for review August 9, 2019 12:40
@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Aug 9, 2019

Even though we don't have the multi-battery requirements worked out completely, I think this PR is still ready for review and merge. It does not affect the safety-critical decisions like low-battery failsafe behavior and reporting of overall system battery percentage. These are still open issues, but they can be addressed in a separate PR.

The only outstanding issue is that this PR is failing CI because it is overflowing the flash on px4_fmu-v5x_stackcheck. I welcome suggestions to fix this.

@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Nov 28, 2019

I have updated this with 3 important differences:

  • Parameters are now instanced with YAML files
  • Refactored to decrease code size
  • Parameter migration has been improved: Old and new parameters are now kept in sync in both directions. If either parameter is changed, the other is immediately updated to reflect this. If the deprecated parameter was changed, then a warning is displayed.

I still have some cleanup and testing to do on this. There are still some relics of the old way this was written.

@hamishwillee I don't know if this is the final behavior of this parameter migration (@dagar will have to weigh in), but once we have it nailed down, where should it be documented? Is it sufficient to only document it in the parameter descriptions?

_warning(battery_status_s::BATTERY_WARNING_NONE),
_last_timestamp(0)
{
if (index > 9 || index < 1) {
PX4_ERR("Battery index must be between 1 and 9 (inclusive). Received %d. Defaulting to 1.", index);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the alternative would just be an assert.

src/lib/battery/battery_params_deprecated.c Show resolved Hide resolved
src/lib/battery/CMakeLists.txt Show resolved Hide resolved
src/lib/battery/battery.h Outdated Show resolved Hide resolved
src/lib/battery/battery.h Outdated Show resolved Hide resolved
@AmeliaEScott AmeliaEScott force-pushed the pr-digital-battery branch 3 times, most recently from e78b8c7 to bfdc9fd Compare December 5, 2019 13:19
@AmeliaEScott
Copy link
Contributor Author

@dagar @julianoes @bkueng This is ready for review.

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Reviewed again, I would say this is good to go in.

@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Dec 5, 2019

I did some more testing on this latest version. The following tests all worked as intended:

  • Plugged in 2 batteries (with different cell counts) to Pixhawk 4 with analog power module
  • Calibrated battery 1 with QGC
  • Calibrated battery 2 manually (using param set)
  • Set values of each BAT_* parameter and BAT1_* parameter (using param set) to check that migration worked correctly
  • Tested with only 1 battery, plugged into each power port on the Pixhawk
    • When plugged into POWER1, it is calibrated with BAT1_* parameters
    • In POWER2, it is calibrated with BAT2_* parameters

@julianoes julianoes merged commit 993fa5b into PX4:master Dec 5, 2019
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.

Nice work.

How do you want to handle updating QGC to the new params?

src/lib/battery/battery.h Show resolved Hide resolved
src/modules/battery_status/analog_battery.cpp Show resolved Hide resolved
src/modules/simulator/simulator.h Show resolved Hide resolved
class Battery : public ModuleParams
{
public:
Battery();
Battery(int index = 1, ModuleParams *parent = nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

I would not default to NULL for the parent, to ensure it's set.

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.

6 participants