APM:Libraries
AP_BattMonitor_Analog.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AP_ADC/AP_ADC.h> // ArduPilot Mega Analog to Digital Converter Library
4 #include "AP_BattMonitor.h"
6 
7 // default pins and dividers
8 #if defined(HAL_BATT_VOLT_PIN)
9  // pins defined in board config (hwdef.dat on ChibiOS)
10  # define AP_BATT_VOLT_PIN HAL_BATT_VOLT_PIN
11  # define AP_BATT_CURR_PIN HAL_BATT_CURR_PIN
12  # define AP_BATT_VOLTDIVIDER_DEFAULT HAL_BATT_VOLT_SCALE
13  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT HAL_BATT_CURR_SCALE
14 #elif CONFIG_HAL_BOARD == HAL_BOARD_PX4 && defined(CONFIG_ARCH_BOARD_PX4FMU_V1)
15  // px4
16  # define AP_BATT_VOLT_PIN 100
17  # define AP_BATT_CURR_PIN 101
18  # define AP_BATT_VOLTDIVIDER_DEFAULT 1.1f
19  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
20 #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))
21  // pixhawk
22  # define AP_BATT_VOLT_PIN 2
23  # define AP_BATT_CURR_PIN 3
24  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
25  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
26 #elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
27  # define AP_BATT_VOLT_PIN 4
28  # define AP_BATT_CURR_PIN 3
29  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
30  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
31 #elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
32  # define AP_BATT_VOLT_PIN 13
33  # define AP_BATT_CURR_PIN 12
34  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
35  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
36 
37 #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))
38  # define AP_BATT_VOLT_PIN 10
39  # define AP_BATT_CURR_PIN 11
40  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
41  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
42 #elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN && defined(CONFIG_ARCH_BOARD_VRUBRAIN_V51)
43  # define AP_BATT_VOLT_PIN 10
44  # define AP_BATT_CURR_PIN -1
45  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
46  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
47 #elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN && defined(CONFIG_ARCH_BOARD_VRUBRAIN_V52)
48  # define AP_BATT_VOLT_PIN 10
49  # define AP_BATT_CURR_PIN 1
50  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
51  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
52  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
53 
54 #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)
55  # define AP_BATT_VOLT_PIN 5
56  # define AP_BATT_CURR_PIN 6
57  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
58  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
59 
60 #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
61  # define AP_BATT_VOLT_PIN 0
62  # define AP_BATT_CURR_PIN 1
63  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
64  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
65 
66 #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
67  # define AP_BATT_VOLT_PIN 0
68  # define AP_BATT_CURR_PIN 1
69  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
70  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
71 
72 #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
73  # define AP_BATT_VOLT_PIN 1
74  # define AP_BATT_CURR_PIN 0
75  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
76  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
77 
78 #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
79  # define AP_BATT_VOLT_PIN 2
80  # define AP_BATT_CURR_PIN 3
81  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
82  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
83 
84 #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)
85  # define AP_BATT_VOLT_PIN 2
86  # define AP_BATT_CURR_PIN 3
87  # define AP_BATT_VOLTDIVIDER_DEFAULT 11.3f
88  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
89 
90 #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE)
91  # define AP_BATT_VOLT_PIN 3
92  # define AP_BATT_CURR_PIN 2
93  # define AP_BATT_VOLTDIVIDER_DEFAULT 18.62
94  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 62.98f
95 
96  # define AP_BATT2_VOLT_PIN 5
97  # define AP_BATT2_CURR_PIN 4
98  # define AP_BATT2_VOLTDIVIDER_DEFAULT 18.62
99  # define AP_BATT2_CURR_AMP_PERVOLT_DEFAULT 62.98f
100 
101 #else
102  # define AP_BATT_VOLT_PIN -1
103  # define AP_BATT_CURR_PIN -1
104  # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
105  # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
106 #endif
107 
108 // Other values normally set directly by mission planner
109 // # define AP_BATT_VOLTDIVIDER_DEFAULT 15.70 // Volt divider for AttoPilot 50V/90A sensor
110 // # define AP_BATT_VOLTDIVIDER_DEFAULT 4.127 // Volt divider for AttoPilot 13.6V/45A sensor
111 // # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 27.32 // Amp/Volt for AttoPilot 50V/90A sensor
112 // # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 13.66 // Amp/Volt for AttoPilot 13.6V/45A sensor
113 
115 {
116 public:
117 
120 
122  void read();
123 
125  bool has_consumed_energy() const override { return has_current(); }
126 
128  bool has_current() const override;
129 
130  void init(void) override {}
131 
132 protected:
133 
136 };
bool has_current() const override
returns true if battery monitor provides current info
void init(void) override
bool has_consumed_energy() const override
returns true if battery monitor provides consumed energy info
AP_BattMonitor_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params &params)
Constructor.
AP_HAL::AnalogSource * _volt_pin_analog_source
void read()
Read the battery voltage and current. Should be called at 10hz.
AP_HAL::AnalogSource * _curr_pin_analog_source