33 #include "autopilot.h"
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
58 #define MIN_BAT_LEVEL 3
67 #if defined ADC_CHANNEL_VSUPPLY || (defined ADC_CHANNEL_CURRENT && !defined SITL) || defined MILLIAMP_AT_FULL_THROTTLE
69 #ifdef ADC_CHANNEL_VSUPPLY
72 #if defined ADC_CHANNEL_CURRENT && !defined SITL
75 #ifdef MILLIAMP_AT_FULL_THROTTLE
82 #define VoltageOfAdc(adc) DefaultVoltageOfAdc(adc)
84 #ifndef MilliAmpereOfAdc
85 #define MilliAmpereOfAdc(adc) DefaultMilliAmpereOfAdc(adc)
88 #ifndef CURRENT_ESTIMATION_NONLINEARITY
89 #define CURRENT_ESTIMATION_NONLINEARITY 1.2
92 #if defined MILLIAMP_AT_FULL_THROTTLE && !defined MILLIAMP_AT_IDLE_THROTTLE
94 #define MILLIAMP_AT_IDLE_THROTTLE 0
97 PRINT_CONFIG_VAR(MILLIAMP_AT_IDLE_THROTTLE)
108 #if defined ADC_CHANNEL_VSUPPLY
113 #if defined ADC_CHANNEL_CURRENT && !defined SITL
115 #elif defined MILLIAMP_AT_FULL_THROTTLE
123 static uint32_t bat_low_counter = 0;
124 static uint32_t bat_critical_counter = 0;
125 static bool_t vsupply_check_started =
FALSE;
127 #if defined(ADC_CHANNEL_VSUPPLY) && !defined(SITL)
129 electrical_priv.vsupply_adc_buf.av_nb_sample));
132 #ifdef ADC_CHANNEL_CURRENT
134 int32_t current_adc = electrical_priv.current_adc_buf.sum / electrical_priv.current_adc_buf.av_nb_sample;
137 BoundAbs(electrical.
current, 65000);
139 #elif defined MILLIAMP_AT_FULL_THROTTLE && defined COMMAND_CURRENT_ESTIMATION
150 float full_current = (float)MILLIAMP_AT_FULL_THROTTLE;
151 float idle_current = (float)MILLIAMP_AT_IDLE_THROTTLE;
153 float x = ((float)
commands[COMMAND_CURRENT_ESTIMATION]) / ((float)
MAX_PPRZ);
159 }
else if(x < 0.0f) {
172 electrical.
current = full_current -
173 pow((pow(full_current - idle_current, electrical_priv.nonlin_factor) -
174 pow(((full_current - idle_current) * x), electrical_priv.nonlin_factor)),
175 (1. / electrical_priv.nonlin_factor));
186 vsupply_check_started =
TRUE;
189 if (vsupply_check_started) {
191 if (bat_low_counter > 0) {
194 if (bat_low_counter == 0) {
204 if (bat_critical_counter > 0) {
205 bat_critical_counter--;
207 if (bat_critical_counter == 0) {
#define ADC_CHANNEL_CURRENT
int32_t current
current in milliamps
#define LOW_BAT_LEVEL
low battery level in Volts (for 3S LiPo)
bool_t bat_low
battery low status
#define VoltageOfAdc(adc)
bool_t bat_critical
battery critical status
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)
Interface for electrical status: supply voltage, current, battery status, etc.
#define BAT_CHECKER_DELAY
#define ELECTRICAL_PERIODIC_FREQ
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
#define ADC_CHANNEL_VSUPPLY
Hardware independent code for commands handling.
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
void electrical_periodic(void)
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
#define CURRENT_ESTIMATION_NONLINEARITY
uint16_t vsupply
supply voltage in decivolts
#define DEFAULT_AV_NB_SAMPLE
float energy
consumed energy in mAh
struct Electrical electrical
#define CRITIC_BAT_LEVEL
critical battery level in Volts (for 3S LiPo)