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

Updated batt_smbus. Expanded battery_status.msg. Fixed mavlink_messages.cpp temperature. #8991

Merged
merged 4 commits into from
Mar 6, 2018

Conversation

AlexKlimaj
Copy link
Member

Updated and expanded batt_smbus to work with bq40z50-R2. Expanded battery_status.msg. Fixed mavlink_messages.cpp temperature, added commented out expanded battery_status.msg parameters for future mavlink expansion.

I've been flying this code with our smart battery for a couple of weeks now without issue.

Planning future enhancements to fall back on ADC battery driver if communication with the smart battery fails for some reason.

Batt_source needs to be set to 1 to bypass battery.cpp ADC driver.

QGC Mavlink Inspector

QGC Battery Status

Nut Shell Output:

nsh> batt_smbus stop
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> batt_smbus test
INFO [batt_smbus] V=16.53 C=0.34 AveC=0.35 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:437 AveTimeToEmpty:427 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.35 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:437 AveTimeToEmpty:427 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.35 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:437 AveTimeToEmpty:427 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.35 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:437 AveTimeToEmpty:427 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.35 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:437 AveTimeToEmpty:427 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.32 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:457 AveTimeToEmpty:428 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.32 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:457 AveTimeToEmpty:428 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.32 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:457 AveTimeToEmpty:428 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.32 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:457 AveTimeToEmpty:428 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.32 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:457 AveTimeToEmpty:428 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:452 AveTimeToEmpty:429 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.33 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:452 AveTimeToEmpty:429 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.34 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:452 AveTimeToEmpty:429 CycleCount:1 SerialNum:7078
INFO [batt_smbus] V=16.53 C=0.34 AveC=0.34 DismAh=0 Cap:2552 TempC:26.45 Remaining:0.96
RunTimeToEmpty:452 AveTimeToEmpty:429 CycleCount:1 SerialNum:7078
nsh>
nsh> listener battery_status
TOPIC: battery_status instance 0 #1
timestamp: 640048256
voltage_v: 16.5170
voltage_filtered_v: 16.5170
current_a: 0.3220
current_filtered_a: 0.3220
average_current_a: 0.3440
discharged_mah: 10.0000
remaining: 0.9581
scale: 0.0000
temperature: 26.8500
cell_count: 0
connected: True
system_source: False
priority: 0
capacity: 2552
cycle_count: 1
run_time_to_empty: 454
average_time_to_empty: 426
serial_number: 28792
is_powering_off: False
warning: 0
nsh>

…tery_status.msg. Fixed mavlink_messages.cpp temperature, added commented out expanded battery_status.msg parameters for future mavlink expansion.
}

const char *verb = argv[optind];

if (!strcmp(verb, "start")) {
if (g_batt_smbus != nullptr) {
PX4_ERR("already started");
return 1;
errx(1, "already started");
Copy link
Member

@dagar dagar Mar 2, 2018

Choose a reason for hiding this comment

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

Can you remove anything that actually exits? For example replace errx with PX4_ERR and a return. Then this driver will be usable out of the box on linux where an exit actually kills the px4 process.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -573,7 +573,13 @@ class MavlinkStreamSysStatus : public MavlinkStream
bat_msg.energy_consumed = -1;
bat_msg.current_battery = (battery_status.connected) ? battery_status.current_filtered_a * 100 : -1;
bat_msg.battery_remaining = (battery_status.connected) ? ceilf(battery_status.remaining * 100.0f) : -1;
bat_msg.temperature = INT16_MAX;
bat_msg.temperature = (battery_status.connected) ? (int16_t)battery_status.temperature : INT16_MAX;
//bat_msg.average_current_battery = (battery_status.connected) ? battery_status.average_current_a * 100.0f : -1;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this commented?

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs an updated version of Mavlink with these messages to build correctly. I put them there for the future.

@dagar
Copy link
Member

dagar commented Mar 2, 2018

@LorenzMeier do you have anything else we could test this with? Should we make sure it fully works on a Solo?

@LorenzMeier
Copy link
Member

Same question as in the last PR: Why did you remove functionality to read some values from SMBus? This PR is not an update, it is a change to one particular power management part and I'd like to understand the rationale.

@AlexKlimaj
Copy link
Member Author

@LorenzMeier

I removed functions that don't make much sense for a smart battery. The values being read also weren't being used or passed anywhere.

Also, the code didn't build as of a few weeks ago, so it's safe to say nobody has been using it recently.

uint8_t device_name(uint8_t *dev_name, uint8_t max_length); - Why do you need to get the name of the battery?

uint8_t device_chemistry(uint8_t *dev_chem, uint8_t max_length); - This is hardcoded to MAV_BATTERY_TYPE_LIPO in mavlink_messages.cpp.

bool is_solo_battery(); - Why is this needed?

_button_press_counts(0) - Fuel gauges I've seen don't report button presses natively. Why would you need this?

@mcsauder
Copy link
Contributor

mcsauder commented Mar 6, 2018

Hi,

I've reviewed this work with Alex and we've tried diligently to generalize the (heavily Solo biased) nature of the driver to serve a broader audience. Although the Solo certainly has a history, it doesn't seem to have much of a future... This work is primarily disposed towards a general (more broad) usage of smart battery fuel gauges that we hope to be more of the norm as time progresses.

Although this PR might fit the Solo battery less well, we hope that it will fit other smart batteries better. Perhaps this is the best rationale to move ahead with this (type) of work?

Thanks for your review and consideration. We hope to broaden and generalize this driver for future systems with this work.

-Mark

@LorenzMeier
Copy link
Member

That makes sense. I just wanted to be sure the code matches the considerations and intentions, which it does.

@LorenzMeier LorenzMeier merged commit 83d01a7 into PX4:master Mar 6, 2018
@mcsauder
Copy link
Contributor

mcsauder commented Mar 7, 2018

Thanks @LorenzMeier and @dagar for your review (and also acceptance) of this code!

We've put another ~1.5hrs / 8 flight packs through flight testing today as well as the full day of bench evaluation on ~10 fuel gauge equipped packs with today's Firmware/master branch... flawless results so far. It is very fun to breathe new life into the smbus code!

Thanks again for your careful consideration.

-Mark

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.

4 participants