2016-02-17 21:25:15 -04:00
|
|
|
#pragma once
|
2014-12-04 01:35:31 -04:00
|
|
|
|
|
|
|
#include "AP_BattMonitor.h"
|
|
|
|
#include "AP_BattMonitor_Backend.h"
|
|
|
|
|
|
|
|
// default pins and dividers
|
2018-02-04 00:04:36 -04:00
|
|
|
#if defined(HAL_BATT_VOLT_PIN)
|
|
|
|
// pins defined in board config (hwdef.dat on ChibiOS)
|
|
|
|
# define AP_BATT_VOLT_PIN HAL_BATT_VOLT_PIN
|
|
|
|
# define AP_BATT_CURR_PIN HAL_BATT_CURR_PIN
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT HAL_BATT_VOLT_SCALE
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT HAL_BATT_CURR_SCALE
|
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4 && defined(CONFIG_ARCH_BOARD_PX4FMU_V1)
|
2014-12-04 01:35:31 -04:00
|
|
|
// px4
|
|
|
|
# define AP_BATT_VOLT_PIN 100
|
|
|
|
# define AP_BATT_CURR_PIN 101
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 1.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2017-07-15 02:12:39 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4 && (defined(CONFIG_ARCH_BOARD_PX4FMU_V2) || defined(CONFIG_ARCH_BOARD_PX4FMU_V4) || defined(CONFIG_ARCH_BOARD_PX4FMU_V4PRO))
|
2014-12-04 01:35:31 -04:00
|
|
|
// pixhawk
|
|
|
|
# define AP_BATT_VOLT_PIN 2
|
|
|
|
# define AP_BATT_CURR_PIN 3
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2018-01-05 03:02:30 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
|
|
# define AP_BATT_VOLT_PIN 4
|
|
|
|
# define AP_BATT_CURR_PIN 3
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2015-05-04 03:16:12 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2014-12-04 01:35:31 -04:00
|
|
|
# define AP_BATT_VOLT_PIN 13
|
|
|
|
# define AP_BATT_CURR_PIN 12
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2015-01-05 04:26:09 -04:00
|
|
|
|
2018-02-03 10:18:56 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN && (defined(CONFIG_ARCH_BOARD_VRBRAIN_V45) || defined(CONFIG_ARCH_BOARD_VRBRAIN_V51) || defined(CONFIG_ARCH_BOARD_VRBRAIN_V52) || defined(CONFIG_ARCH_BOARD_VRBRAIN_V52E) || defined(CONFIG_ARCH_BOARD_VRCORE_V10) || defined(CONFIG_ARCH_BOARD_VRBRAIN_V54))
|
2014-12-04 01:35:31 -04:00
|
|
|
# define AP_BATT_VOLT_PIN 10
|
|
|
|
# define AP_BATT_CURR_PIN 11
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2016-07-05 12:02:24 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN && defined(CONFIG_ARCH_BOARD_VRUBRAIN_V51)
|
2014-12-04 01:35:31 -04:00
|
|
|
# define AP_BATT_VOLT_PIN 10
|
2015-01-05 04:26:09 -04:00
|
|
|
# define AP_BATT_CURR_PIN -1
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2016-07-05 12:02:24 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN && defined(CONFIG_ARCH_BOARD_VRUBRAIN_V52)
|
2014-12-04 01:35:31 -04:00
|
|
|
# define AP_BATT_VOLT_PIN 10
|
2015-01-05 04:26:09 -04:00
|
|
|
# define AP_BATT_CURR_PIN 1
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2015-08-20 09:38:48 -03:00
|
|
|
|
2016-02-18 00:11:12 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF)
|
2015-08-20 09:38:48 -03:00
|
|
|
# define AP_BATT_VOLT_PIN 5
|
|
|
|
# define AP_BATT_CURR_PIN 6
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2016-01-26 15:31:22 -04:00
|
|
|
|
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
|
|
|
# define AP_BATT_VOLT_PIN 0
|
|
|
|
# define AP_BATT_CURR_PIN 1
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
|
|
|
|
2018-01-29 17:13:09 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
|
|
|
|
# define AP_BATT_VOLT_PIN 0
|
|
|
|
# define AP_BATT_CURR_PIN 1
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
|
|
|
|
2017-12-13 15:37:16 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
2018-05-11 13:12:10 -03:00
|
|
|
# define AP_BATT_VOLT_PIN 1
|
|
|
|
# define AP_BATT_CURR_PIN 0
|
2017-12-13 15:37:16 -04:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
|
|
|
|
2016-12-01 08:32:11 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2)
|
|
|
|
# define AP_BATT_VOLT_PIN 2
|
|
|
|
# define AP_BATT_CURR_PIN 3
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 11.3f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
|
|
|
|
2017-10-18 14:01:14 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE)
|
|
|
|
# define AP_BATT_VOLT_PIN 3
|
|
|
|
# define AP_BATT_CURR_PIN 2
|
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 18.62
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 62.98f
|
|
|
|
|
|
|
|
# define AP_BATT2_VOLT_PIN 5
|
|
|
|
# define AP_BATT2_CURR_PIN 4
|
|
|
|
# define AP_BATT2_VOLTDIVIDER_DEFAULT 18.62
|
|
|
|
# define AP_BATT2_CURR_AMP_PERVOLT_DEFAULT 62.98f
|
|
|
|
|
2014-12-04 01:35:31 -04:00
|
|
|
#else
|
|
|
|
# define AP_BATT_VOLT_PIN -1
|
|
|
|
# define AP_BATT_CURR_PIN -1
|
2015-04-24 00:27:19 -03:00
|
|
|
# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
|
|
|
|
# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
|
2014-12-04 01:35:31 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Other values normally set directly by mission planner
|
|
|
|
// # define AP_BATT_VOLTDIVIDER_DEFAULT 15.70 // Volt divider for AttoPilot 50V/90A sensor
|
|
|
|
// # define AP_BATT_VOLTDIVIDER_DEFAULT 4.127 // Volt divider for AttoPilot 13.6V/45A sensor
|
|
|
|
// # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 27.32 // Amp/Volt for AttoPilot 50V/90A sensor
|
|
|
|
// # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 13.66 // Amp/Volt for AttoPilot 13.6V/45A sensor
|
|
|
|
|
|
|
|
class AP_BattMonitor_Analog : public AP_BattMonitor_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
2017-10-27 02:36:49 -03:00
|
|
|
AP_BattMonitor_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params ¶ms);
|
2014-12-04 01:35:31 -04:00
|
|
|
|
|
|
|
/// Read the battery voltage and current. Should be called at 10hz
|
2018-11-07 06:57:38 -04:00
|
|
|
void read() override;
|
2014-12-04 01:35:31 -04:00
|
|
|
|
2016-08-25 09:53:33 -03:00
|
|
|
/// returns true if battery monitor provides consumed energy info
|
|
|
|
bool has_consumed_energy() const override { return has_current(); }
|
|
|
|
|
2017-05-24 04:43:10 -03:00
|
|
|
/// returns true if battery monitor provides current info
|
|
|
|
bool has_current() const override;
|
|
|
|
|
2017-10-26 00:58:56 -03:00
|
|
|
void init(void) override {}
|
|
|
|
|
2014-12-04 01:35:31 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
AP_HAL::AnalogSource *_volt_pin_analog_source;
|
|
|
|
AP_HAL::AnalogSource *_curr_pin_analog_source;
|
|
|
|
};
|