-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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 Parameter Migration #15616
Conversation
It loads the battery parameters but then overwrites them with hardcoded values and it breaks the ModuleParams parent/child hierarchy. Both is undesired.
src/lib/battery/battery.cpp
Outdated
@@ -186,7 +186,8 @@ Battery::updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float curre | |||
void | |||
Battery::publish() | |||
{ | |||
orb_publish_auto(ORB_ID(battery_status), &_orb_advert, &_battery_status, &_orb_instance); | |||
int dummy; // We're not interested in the instance ID we get | |||
orb_publish_auto(ORB_ID(battery_status), &_battery_status_pub, &_battery_status, &dummy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to change this how about replacing it with a uORB::PublicationMulti<battery_status_s>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but don't know what's the equivalent of this auto publication. Don't you have to specify the ID in advance? Would you just use the const int _index;
of the battery for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add it. Works with one battery (SITL). Is that the correct use?
Does it automatically choose the next free instance?
Nice work @MaEtUgR. The battery param migration was a real mess that I'm looking forward to purging once the QGC side is in place. |
@@ -119,7 +119,7 @@ if [ $AUTOCNF = yes ] | |||
then | |||
param set SYS_AUTOSTART $REQUESTED_AUTOSTART | |||
|
|||
param set BAT_N_CELLS 3 | |||
param set BAT_N_CELLS 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
BatterySimulator
is hardcoding this value now so it's what we're already using in SITL atm: https://github.com/PX4/Firmware/blob/4088c2581f38333a306d3cd55aa66b617a51eb93/src/modules/simulator/battery_simulator/BatterySimulator.hpp#L88 - IMHO 4S is far more common than 3S these days which was not the case when this was originally set up.
- It doesn't matter, the simulated battery generates a voltage that considers the cell count so voltages "just look more familiar" 🤷♂️
src/lib/battery/battery.h
Outdated
@@ -230,6 +214,5 @@ class Battery : public ModuleParams | |||
uint8_t _warning; | |||
hrt_abstime _last_timestamp; | |||
|
|||
orb_advert_t _orb_advert{nullptr}; | |||
int _orb_instance; | |||
orb_advert_t _battery_status_pub{nullptr}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orb_advert_t _battery_status_pub{nullptr}; | |
uORB::PublicationMulti<battery_status_s> _battery_status_pub{ORB_ID(battery_status)}; |
e7c302c
to
9770e67
Compare
@dagar Thanks for the quick review!!
|
12bdef1
to
dc1870d
Compare
I added a commit to switch to |
a153aa5
to
233c2c9
Compare
The subscription to parameter updates has to get copied otherwise the change detection will not get reset for next time.
This was not a problem before because battery.h included the adc driver and implicitly snprintf was defined through there.
233c2c9
to
6cb5644
Compare
@julianoes Thanks for the review! I hope I addressed the comments to your liking. If you want to discuss migration cases I'm happy to do so. |
Looks good to me. Let's do an extra round of manual testing here because I'm going to cherry-pick this as the last change for v1.11. |
Describe problem solved by this pull request
@cmic0 tried to change
BAT1_V_EMPTY
. Parameter was changed, it differed fromBAT_V_EMPTY
and after a reboot (starting simulation again) it was back to the old value.Battery parameter migration from
BAT_*
toBAT1_*
had the following issues:SimulatorBattery
broke the chain of ModuleParams parent/child tree which the logic is relying on. Additionally it overwrote the parameters with hardcoded values internally._first_parameter_update
was initialized false and hence always false. This didn't have an effect most of the time because theprevious_old_val
is zero on initialization and if the new parameter isn't zero it went the right path.parameter_update
subscription once they checked it's updated.Describe your solution
SimulatorBattery
, it only did harm._first_parameter_update
with true.Test data / coverage
SITL testing.