35 #include "generated/airframe.h"
38 #ifdef MILLIAMP_PER_PERCENT
39 #warning "deprecated MILLIAMP_PER_PERCENT --> Please use MILLIAMP_AT_FULL_THROTTLE"
41 #if defined BATTERY_SENS || defined BATTERY_OFFSET
42 #warning "BATTERY_SENS and BATTERY_OFFSET are deprecated, please remove them --> if you want to change the default use VoltageOfAdc"
45 #if defined COMMAND_THROTTLE
46 #define COMMAND_CURRENT_ESTIMATION COMMAND_THROTTLE
47 #elif defined COMMAND_THRUST
48 #define COMMAND_CURRENT_ESTIMATION COMMAND_THRUST
51 #ifndef BAT_CHECKER_DELAY
52 #define BAT_CHECKER_DELAY 5
55 #define ELECTRICAL_PERIODIC_FREQ 10
59 #define MIN_BAT_LEVEL 3
68 #if defined ADC_CHANNEL_VSUPPLY || (defined ADC_CHANNEL_CURRENT && !defined SITL) || defined MILLIAMP_AT_FULL_THROTTLE
70 #ifdef ADC_CHANNEL_VSUPPLY
73 #if defined ADC_CHANNEL_CURRENT && !defined SITL
76 #ifdef MILLIAMP_AT_FULL_THROTTLE
83 #define VoltageOfAdc(adc) DefaultVoltageOfAdc(adc)
85 #ifndef MilliAmpereOfAdc
86 #define MilliAmpereOfAdc(adc) DefaultMilliAmpereOfAdc(adc)
89 #ifndef CURRENT_ESTIMATION_NONLINEARITY
90 #define CURRENT_ESTIMATION_NONLINEARITY 1.2
93 #if defined MILLIAMP_AT_FULL_THROTTLE && !defined MILLIAMP_AT_IDLE_THROTTLE
95 #define MILLIAMP_AT_IDLE_THROTTLE 0
98 PRINT_CONFIG_VAR(MILLIAMP_AT_IDLE_THROTTLE)
110 #if defined ADC_CHANNEL_VSUPPLY
115 #if defined ADC_CHANNEL_CURRENT && !defined SITL
117 #elif defined MILLIAMP_AT_FULL_THROTTLE
125 static uint32_t bat_low_counter = 0;
126 static uint32_t bat_critical_counter = 0;
127 static bool vsupply_check_started =
false;
129 #if defined(ADC_CHANNEL_VSUPPLY) && !defined(SITL) && !USE_BATTERY_MONITOR
131 electrical_priv.vsupply_adc_buf.av_nb_sample));
134 #ifdef ADC_CHANNEL_CURRENT
136 int32_t current_adc = electrical_priv.current_adc_buf.sum / electrical_priv.current_adc_buf.av_nb_sample;
139 #elif defined MILLIAMP_AT_FULL_THROTTLE && defined COMMAND_CURRENT_ESTIMATION
150 static float full_current = (float)MILLIAMP_AT_FULL_THROTTLE / 1000.f;
151 static float idle_current = (float)MILLIAMP_AT_IDLE_THROTTLE / 1000.f;
153 float x = ((float)
commands[COMMAND_CURRENT_ESTIMATION]) / ((float)
MAX_PPRZ);
168 electrical.
current = full_current -
169 powf((powf(full_current - idle_current, electrical_priv.nonlin_factor) -
170 powf(((full_current - idle_current) * x), electrical_priv.nonlin_factor)),
171 (1.f / electrical_priv.nonlin_factor));
179 electrical.
charge += consumed_since_last;
180 electrical.
energy += consumed_since_last * electrical.
vsupply;
184 vsupply_check_started =
true;
187 if (vsupply_check_started) {
189 if (bat_low_counter > 0) {
192 if (bat_low_counter == 0) {
202 if (bat_critical_counter > 0) {
203 bat_critical_counter--;
205 if (bat_critical_counter == 0) {
#define ADC_CHANNEL_CURRENT
bool autopilot_throttle_killed(void)
get kill status
#define LOW_BAT_LEVEL
low battery level in Volts (for 3S LiPo)
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
float vsupply
supply voltage in V
#define VoltageOfAdc(adc)
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
#define MilliAmpereOfAdc(adc)
void electrical_init(void)
bool bat_critical
battery critical status
Interface for electrical status: supply voltage, current, battery status, etc.
#define BAT_CHECKER_DELAY
#define ELECTRICAL_PERIODIC_FREQ
float charge
consumed electric charge in Ah
static float period_to_hour
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
Hardware independent code for commands handling.
bool bat_low
battery low status
void electrical_periodic(void)
Core autopilot interface common to all firmwares.
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
#define CURRENT_ESTIMATION_NONLINEARITY
#define DEFAULT_AV_NB_SAMPLE
float energy
consumed energy in Wh
struct Electrical electrical
#define CRITIC_BAT_LEVEL
critical battery level in Volts (for 3S LiPo)
float current
current in A
#define ADC_CHANNEL_VSUPPLY