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

Updates to batt_smbus driver to add functionality and work with TI BQ40Z50-R1/R2 fuel gauge #8854

Closed
wants to merge 107 commits into from

Conversation

AlexKlimaj
Copy link
Member

I have updated the batt_smbus driver to work with the TI BQ40Z50-R1/R2 fuel gauges.

Voltage and current are working correctly and using updateBatteryStatus to update uORB.

There are many more values I want to gather from the fuel gauge and get into a mavlink message. Would it be best to add them to battery_status.msg?

updateBatteryStatus in the battery driver is very geared towards battery measurements coming from the on board ADC's. I think it would be worth updating the battery_status.msg through the batt_smbus driver instead.

BATT_SOURCE also needs to be set to 1 to bypass reading the battery ADC's in the sensors.cpp driver.

@AlexKlimaj AlexKlimaj mentioned this pull request Feb 8, 2018
@dagar dagar self-requested a review February 9, 2018 00:06
}
}
battery_status_s battery_status;
_battery.updateBatteryStatus(now, new_report.voltage_v, new_report.current_a,
Copy link
Member

Choose a reason for hiding this comment

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

I see why you did this, but I really think we need to find a better overall solution than having a low level battery driver subscribing to controller output like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, the sensors.cpp battery update process also relies on it.

@@ -1014,60 +773,47 @@ batt_smbus_main(int argc, char *argv[])
if (g_batt_smbus == nullptr) {
PX4_INFO("not started");
batt_smbus_usage();
return 1;
exit(1);
Copy link
Member

Choose a reason for hiding this comment

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

Please return an error instead of exiting. On Linux these modules are threads within a single progress, so exiting from a single module/driver kills all of px4.

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops, I was working off of the older one and not your new commit today.

@dagar
Copy link
Member

dagar commented Feb 9, 2018

@AlexKlimaj check the CI failures.

@dagar
Copy link
Member

dagar commented Feb 9, 2018

@davids5 @ChristophTobler @bkueng it might be time to think about the system_power/battery_status architecture again.

Copy link
Member

@LorenzMeier LorenzMeier left a comment

Choose a reason for hiding this comment

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

Based on the code changes it looks like this actually removes the ability to calculate and check the bus checksum and might make this driver incompatible with other fuel gauges. Can you explain the rationale behind this?

@AlexKlimaj
Copy link
Member Author

PEC is not enabled on the TI BQ40Z50-R1/R2 by default. So I left it out. I will add it back in as a check.

@AlexKlimaj AlexKlimaj closed this Feb 9, 2018
@AlexKlimaj AlexKlimaj reopened this Feb 13, 2018
@AlexKlimaj
Copy link
Member Author

AlexKlimaj commented Feb 13, 2018

I added PEC back in. Removed the call to update battery status which enabled me to remove the vehicle control mode and actuator controls dependency.

I also added battery capacity to the battery uorb message. The total discharged is calculated based on the remaining capacity when the driver starts minus the current remaining capacity.

NuttShell (NSH)
nsh>
nsh>
nsh> batt_smbus start
batt_smbus on I2C bus 1 at 0x0b (bus: 100 KHz, max: 100 KHz)
INFO [batt_smbus] battery found at 0xb
INFO [batt_smbus] smart battery connected
nsh>
nsh>
nsh>
nsh> batt_smbus test
INFO [batt_smbus] V=15.17 C=0.25 DismAh=1 Cap:2495 Remaining:0.37
INFO [batt_smbus] V=15.16 C=0.25 DismAh=1 Cap:2495 Remaining:0.37
INFO [batt_smbus] V=15.16 C=0.25 DismAh=1 Cap:2495 Remaining:0.37

QGC Battery Status

@AlexKlimaj
Copy link
Member Author

@LorenzMeier @dagar

Added more functionality today.

nsh>
nsh> batt_smbus start
batt_smbus on I2C bus 1 at 0x0b (bus: 100 KHz, max: 100 KHz)
INFO [batt_smbus] battery found at 0xb
INFO [batt_smbus] smart battery connected
nsh>
nsh>
nsh>
nsh>
nsh> batt_smbus test
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:478 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:478 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.30 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.31 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.39 C=0.31 DismAh=1 Cap:2623 TempC:26.35 Remaining:0.92 RunTimeToEmpty:477 CycleCount:35 SerialNum:0001
nsh>
nsh>
nsh>
nsh> batt_smbus test
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:455 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.65 Remaining:0.88 RunTimeToEmpty:455 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.65 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.65 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
INFO [batt_smbus] V=16.26 C=0.31 DismAh=98 Cap:2623 TempC:29.55 Remaining:0.88 RunTimeToEmpty:453 CycleCount:35 SerialNum:0001
nsh>
nsh>

@AlexKlimaj AlexKlimaj closed this Feb 14, 2018
@AlexKlimaj AlexKlimaj reopened this Feb 14, 2018
acfloria and others added 5 commits February 13, 2018 20:45
- simulated tailsitter needs a virtual elevator since we cannot simulate
elevons yet (liftDrag plugin does not model longitudinal moment Cm)

Signed-off-by: Roman <[email protected]>
@AlexKlimaj AlexKlimaj changed the title Updates to batt_smbus.cpp to work with TI BQ40Z50-R1/R2 Updates to batt_smbus driver to add functionality and work with TI BQ40Z50-R1/R2 fuel gauge Feb 14, 2018
julianoes and others added 28 commits February 23, 2018 16:14
This prevents the autopilot from sending an invalid unix timestamp.
Usually, if no time is set yet by a GPS, the date is somehow set
to 2000-01-01, therefore we can ignore anything earlier than 2001.
On the Intel Aero and probably also other specific platforms
the first measured voltage values despite connected battery are unuasable.
The solution here is to start filtering and determining warning
only after a measurement above 2.1V was received.
This gets rid of a printf.
When the timer callback is called at a higher rate than the logger can
execute the main loop (which is never the case under normal conditions),
the semaphore counter will increase unbounded, and eventually lead to
an assertion failure in NuttX.
The maximum semaphore counter is 0x7FFF, and when the logger runs at
default rate (3.5ms), the logger task must be blocked for 0x7FFF*3.5/1000
= 114 seconds continuously for an overflow to happen.

I see 2 cases where that could happen:
- the logger execution blocks somehow, or busy-loops in an inner loop
- a higher-prio task runs busy and hogs the CPU over a long period of time
@AlexKlimaj AlexKlimaj closed this Mar 1, 2018
@AlexKlimaj AlexKlimaj mentioned this pull request Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.