Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_BattMonitor/AP_BattMonitor_Analog.h
Views: 1798
#pragma once12#include "AP_BattMonitor_Backend.h"34#if AP_BATTERY_ANALOG_ENABLED56#include "AP_BattMonitor.h"78// default pins and dividers9#if defined(HAL_BATT_VOLT_PIN)10// pins defined in board config (hwdef.dat on ChibiOS)11# define AP_BATT_VOLT_PIN HAL_BATT_VOLT_PIN12# define AP_BATT_CURR_PIN HAL_BATT_CURR_PIN13# define AP_BATT_VOLTDIVIDER_DEFAULT HAL_BATT_VOLT_SCALE14# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT HAL_BATT_CURR_SCALE15#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS16# define AP_BATT_VOLT_PIN 417# define AP_BATT_CURR_PIN 318# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f19# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f20#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL21# define AP_BATT_VOLT_PIN 1322# define AP_BATT_CURR_PIN 1223# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f24# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f2526#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)27# define AP_BATT_VOLT_PIN 528# define AP_BATT_CURR_PIN 629# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f30# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f3132#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI33# define AP_BATT_VOLT_PIN 034# define AP_BATT_CURR_PIN 135# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f36# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f3738#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE39# define AP_BATT_VOLT_PIN 040# define AP_BATT_CURR_PIN 141# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f42# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f4344#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET45# define AP_BATT_VOLT_PIN 146# define AP_BATT_CURR_PIN 047# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f48# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f4950#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)51# define AP_BATT_VOLT_PIN 252# define AP_BATT_CURR_PIN 353# define AP_BATT_VOLTDIVIDER_DEFAULT 11.3f54# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f5556#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR)57# define AP_BATT_VOLT_PIN 558# define AP_BATT_CURR_PIN 459# define AP_BATT_VOLTDIVIDER_DEFAULT 11.0f60# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 37.8788f61# define AP_BATT_CURR_AMP_OFFSET_DEFAULT 0.330f6263#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE)64# define AP_BATT_VOLT_PIN 365# define AP_BATT_CURR_PIN 266# define AP_BATT_VOLTDIVIDER_DEFAULT 18.6267# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 62.98f6869# define AP_BATT2_VOLT_PIN 570# define AP_BATT2_CURR_PIN 471# define AP_BATT2_VOLTDIVIDER_DEFAULT 18.6272# define AP_BATT2_CURR_AMP_PERVOLT_DEFAULT 62.98f7374#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1)75# define AP_BATT_VOLT_PIN 076# define AP_BATT_CURR_PIN 177# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f78# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f7980#else81# define AP_BATT_VOLT_PIN -182# define AP_BATT_CURR_PIN -183# define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f84# define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f85#endif8687// This is 0 for the majority of the power modules.88#ifndef AP_BATT_CURR_AMP_OFFSET_DEFAULT89#define AP_BATT_CURR_AMP_OFFSET_DEFAULT 0.0f90#endif9192// Other values normally set directly by mission planner93// # define AP_BATT_VOLTDIVIDER_DEFAULT 15.70 // Volt divider for AttoPilot 50V/90A sensor94// # define AP_BATT_VOLTDIVIDER_DEFAULT 4.127 // Volt divider for AttoPilot 13.6V/45A sensor95// # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 27.32 // Amp/Volt for AttoPilot 50V/90A sensor96// # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 13.66 // Amp/Volt for AttoPilot 13.6V/45A sensor9798class AP_BattMonitor_Analog : public AP_BattMonitor_Backend99{100public:101102/// Constructor103AP_BattMonitor_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params ¶ms);104105/// Read the battery voltage and current. Should be called at 10hz106virtual void read() override;107108/// returns true if battery monitor provides consumed energy info109virtual bool has_consumed_energy() const override { return has_current(); }110111/// returns true if battery monitor provides current info112virtual bool has_current() const override;113114virtual void init(void) override {}115116static const struct AP_Param::GroupInfo var_info[];117118protected:119120AP_HAL::AnalogSource *_volt_pin_analog_source;121AP_HAL::AnalogSource *_curr_pin_analog_source;122123// Parameters124AP_Float _volt_multiplier; /// voltage on volt pin multiplied by this to calculate battery voltage125AP_Float _curr_amp_per_volt; /// voltage on current pin multiplied by this to calculate current in amps126AP_Float _curr_amp_offset; /// offset voltage that is subtracted from current pin before conversion to amps127AP_Float _volt_offset; /// offset voltage that is subtracted from voltage pin before conversion128AP_Int8 _volt_pin; /// board pin used to measure battery voltage129AP_Int8 _curr_pin; /// board pin used to measure battery current130};131132#endif // AP_BATTERY_ANALOG_ENABLED133134135