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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions boards/bitcraze/crazyflie/syslink/syslink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Syslink::task_main()
_memory = new SyslinkMemory(this);
_memory->init();

_battery.reset(&_battery_status);
_battery.reset();


// int ret;
Expand Down Expand Up @@ -411,7 +411,7 @@ Syslink::handle_message(syslink_message_t *msg)
memcpy(&vbat, &msg->data[1], sizeof(float));
//memcpy(&iset, &msg->data[5], sizeof(float));

_battery.updateBatteryStatus(t, vbat, -1, true, true, 0, 0, false, &_battery_status);
_battery.updateBatteryStatus(t, vbat, -1, true, true, 0, 0, false, true);


// Update battery charge state
Expand All @@ -420,16 +420,13 @@ Syslink::handle_message(syslink_message_t *msg)
}

/* With the usb plugged in and battery disconnected, it appears to be charged. The voltage check ensures that a battery is connected */
else if (powered && !charging && _battery_status.voltage_filtered_v > 3.7f) {
else if (powered && !charging && vbat > 3.7f) {
_bstate = BAT_CHARGED;

} else {
_bstate = BAT_DISCHARGING;
}

// announce the battery status if needed, just publish else
_battery_pub.publish(_battery_status);

} else if (msg->type == SYSLINK_RADIO_RSSI) {
uint8_t rssi = msg->data[0]; // Between 40 and 100 meaning -40 dBm to -100 dBm
_rssi = 140 - rssi * 100 / (100 - 40);
Expand Down
3 changes: 0 additions & 3 deletions boards/bitcraze/crazyflie/syslink/syslink_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,8 @@ class Syslink
hrt_abstime _params_update[3]; // Time at which the parameters were updated
hrt_abstime _params_ack[3]; // Time at which the parameters were acknowledged by the nrf module

uORB::PublicationMulti<battery_status_s> _battery_pub{ORB_ID(battery_status)};
uORB::PublicationMulti<input_rc_s> _rc_pub{ORB_ID(input_rc)};

struct battery_status_s _battery_status;

Battery _battery;

int32_t _rssi;
Expand Down
4 changes: 2 additions & 2 deletions boards/intel/aerofc-v1/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ px4_add_board(
#uavcan
MODULES
#airspeed_selector
attitude_estimator_q
#attitude_estimator_q
battery_status
#camera_feedback
commander
Expand All @@ -44,7 +44,7 @@ px4_add_board(
land_detector
landing_target_estimator
load_mon
local_position_estimator
#local_position_estimator
logger
mavlink
mc_att_control
Expand Down
1 change: 1 addition & 0 deletions msg/battery_status.msg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ uint16 cycle_count # number of discharge cycles the battery has experien
uint16 run_time_to_empty # predicted remaining battery capacity based on the present rate of discharge in min
uint16 average_time_to_empty # predicted remaining battery capacity based on the average rate of discharge in min
uint16 serial_number # serial number of the battery pack
uint8 id # ID number of a battery. Should be unique and consistent for the lifetime of a vehicle. 1-indexed.

float32[4] voltage_cell_v # Battery individual cell voltages
float32 max_cell_voltage_delta # Max difference between individual cell voltages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,11 @@ int DfBebopBusWrapper::set_esc_speeds(const float speed_scaled[4])
int DfBebopBusWrapper::_publish(struct bebop_state_data &data)
{

battery_status_s battery_report;
const hrt_abstime timestamp = hrt_absolute_time();

// TODO Check if this is the right way for the Bebop
// We don't have current measurements
_battery.updateBatteryStatus(timestamp, data.battery_voltage_v, 0.0, true, true, 0, _last_throttle, _armed,
&battery_report);
_battery.updateBatteryStatus(timestamp, data.battery_voltage_v, 0.0, true, true, 0, _last_throttle, _armed, false);

esc_status_s esc_status = {};

Expand All @@ -224,13 +222,7 @@ int DfBebopBusWrapper::_publish(struct bebop_state_data &data)
// TODO: when is this ever blocked?
if (!(m_pub_blocked)) {

if (_battery_topic == nullptr) {
_battery_topic = orb_advertise_multi(ORB_ID(battery_status), &battery_report,
&_battery_orb_class_instance, ORB_PRIO_LOW);

} else {
orb_publish(ORB_ID(battery_status), _battery_topic, &battery_report);
}
_battery.publish();

if (_esc_topic == nullptr) {
_esc_topic = orb_advertise(ORB_ID(esc_status), &esc_status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <ltc2946/LTC2946.hpp>

#include <uORB/uORB.h>
#include <uORB/topics/battery_status.h>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/vehicle_control_mode.h>

Expand All @@ -70,8 +69,6 @@ class DfLtc2946Wrapper : public LTC2946
private:
int _publish(const struct ltc2946_sensor_data &data);

orb_advert_t _battery_pub{nullptr};
battery_status_s _battery_status{};
Battery _battery{};

int _actuator_ctrl_0_sub{-1};
Expand All @@ -82,7 +79,7 @@ class DfLtc2946Wrapper : public LTC2946
DfLtc2946Wrapper::DfLtc2946Wrapper() :
LTC2946(LTC2946_DEVICE_PATH)
{
_battery.reset(&_battery_status);
_battery.reset();

// subscriptions
_actuator_ctrl_0_sub = orb_subscribe(ORB_ID(actuator_controls_0));
Expand Down Expand Up @@ -144,11 +141,7 @@ int DfLtc2946Wrapper::_publish(const struct ltc2946_sensor_data &data)
_battery.updateBatteryStatus(t, data.battery_voltage_V, data.battery_current_A,
connected, true, 1,
ctrl.control[actuator_controls_s::INDEX_THROTTLE],
vcontrol_mode.flag_armed, &_battery_status);

int instance;
orb_publish_auto(ORB_ID(battery_status), &_battery_pub, &_battery_status, &instance, ORB_PRIO_DEFAULT);

vcontrol_mode.flag_armed, true);
return 0;
}

Expand Down
10 changes: 3 additions & 7 deletions src/drivers/power_monitor/voxlpm/voxlpm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ VOXLPM::init()
write_reg(DEFAULT_CTRLA_REG_VAL, VOXLPM_LTC2946_CTRLA_REG);
write_reg(DEFAULT_CTRLB_REG_VAL, VOXLPM_LTC2946_CTRLB_REG);

_battery.reset(&_bat_status);
_battery.reset();

start();

Expand Down Expand Up @@ -153,9 +153,7 @@ VOXLPM::measure()

switch (_ch_type) {
case VOXLPM_CH_TYPE_VBATT: {
_battery.updateBatteryStatus(tnow, _voltage, _amperage, true, true, 0, 0, false, &_bat_status);

_bat_pub_topic.publish(_bat_status);
_battery.updateBatteryStatus(tnow, _voltage, _amperage, true, true, 0, 0, false, true);
}

// fallthrough
Expand All @@ -176,9 +174,7 @@ VOXLPM::measure()
} else {
switch (_ch_type) {
case VOXLPM_CH_TYPE_VBATT: {
_battery.updateBatteryStatus(tnow, 0.0, 0.0, true, true, 0, 0, false, &_bat_status);

_bat_pub_topic.publish(_bat_status);
_battery.updateBatteryStatus(tnow, 0.0, 0.0, true, true, 0, 0, false, true);
}
break;

Expand Down
2 changes: 0 additions & 2 deletions src/drivers/power_monitor/voxlpm/voxlpm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ class VOXLPM : public device::I2C, public px4::ScheduledWorkItem

perf_counter_t _sample_perf;

uORB::PublicationMulti<battery_status_s> _bat_pub_topic{ORB_ID(battery_status)};
uORB::PublicationMulti<power_monitor_s> _pm_pub_topic{ORB_ID(power_monitor)};

battery_status_s _bat_status{};
power_monitor_s _pm_status{};

VOXLPM_CH_TYPE _ch_type;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/battery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2018 PX4 Development Team. All rights reserved.
# Copyright (c) 2019 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -32,3 +32,6 @@
############################################################################

px4_add_library(battery battery.cpp)

# TODO: Add an option in px4_add_library function to add module config file
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/module.yaml)
Loading