Skip to content

Commit

Permalink
Refactored to work with new battery_status module
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Scott authored and julianoes committed Dec 5, 2019
1 parent d7bb5d4 commit 993fa5b
Show file tree
Hide file tree
Showing 35 changed files with 1,097 additions and 1,833 deletions.
2 changes: 1 addition & 1 deletion boards/bitcraze/crazyflie/syslink/syslink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ 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 {
Expand Down
2 changes: 1 addition & 1 deletion boards/bitcraze/crazyflie/syslink/syslink_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Syslink

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

Battery1 _battery;
Battery _battery;

int32_t _rssi;
battery_state _bstate;
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 @@ -101,7 +101,7 @@ class DfBebopBusWrapper : public BebopBus
orb_advert_t _battery_topic;
orb_advert_t _esc_topic;

Battery1 _battery;
Battery _battery;
bool _armed;
float _last_throttle;

Expand Down Expand Up @@ -203,6 +203,10 @@ int DfBebopBusWrapper::_publish(struct bebop_state_data &data)

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, false);

esc_status_s esc_status = {};

uint16_t esc_speed_setpoint_rpm[4] = {};
Expand All @@ -218,9 +222,7 @@ int DfBebopBusWrapper::_publish(struct bebop_state_data &data)
// TODO: when is this ever blocked?
if (!(m_pub_blocked)) {

// 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, true);
_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 @@ -69,7 +69,7 @@ class DfLtc2946Wrapper : public LTC2946
private:
int _publish(const struct ltc2946_sensor_data &data);

Battery1 _battery{};
Battery _battery{};

int _actuator_ctrl_0_sub{-1};
int _vcontrol_mode_sub{-1};
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
7 changes: 5 additions & 2 deletions 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 @@ -31,4 +31,7 @@
#
############################################################################

px4_add_library(battery battery_base.cpp battery.cpp)
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

0 comments on commit 993fa5b

Please sign in to comment.