Paparazzi UAS  v4.0.4_stable-3-gf39211a Paparazzi is a free software Unmanned Aircraft System.
electrical.c
Go to the documentation of this file.
2
4 #include "commands.h"
5
6 #include "generated/airframe.h"
7 #include BOARD_CONFIG
8
9 #ifdef MILLIAMP_PER_PERCENT
10 #warning "deprecated MILLIAMP_PER_PERCENT --> Please use MILLIAMP_AT_FULL_THROTTLE"
11 #endif
12 #if defined BATTERY_SENS || defined BATTERY_OFFSET
13 #warning "BATTERY_SENS and BATTERY_OFFSET are deprecated, please remove them --> if you want to change the default use VoltageOfAdc"
14 #endif
15
17
18 static struct {
22 #endif
23 #ifdef MILLIAMP_AT_FULL_THROTTLE
24  float nonlin_factor;
25 #endif
27
30 #endif
33 #endif
34
35 #ifndef CURRENT_ESTIMATION_NONLINEARITY
36 #define CURRENT_ESTIMATION_NONLINEARITY 1.2
37 #endif
38
39 void electrical_init(void) {
40  electrical.vsupply = 0;
41  electrical.current = 0;
42
46 #endif
47
48 #ifdef MILLIAMP_AT_FULL_THROTTLE
50 #endif
51 }
52
53 void electrical_periodic(void) {
54 #ifndef SITL
56 #endif
57
59 #ifndef SITL
61 #endif
62 #else
63 #if defined MILLIAMP_AT_FULL_THROTTLE && defined COMMAND_THROTTLE
64  /*
65  * Superellipse: abs(x/a)^n + abs(y/b)^n = 1
66  * with a = 1
67  * b = mA at full throttle
68  * n = 1.2 This defines nonlinearity (1 = linear)
69  * x = throttle
70  * y = current
71  *
72  * define CURRENT_ESTIMATION_NONLINEARITY in your airframe file to change the default nonlinearity factor of 1.2
73  */
74  float b = (float)MILLIAMP_AT_FULL_THROTTLE;
75  float x = ((float)commands[COMMAND_THROTTLE]) / ((float)MAX_PPRZ);
76  /* electrical.current y = ( b^n - (b* x/a)^n )^1/n
77  * a=1, n = electrical_priv.nonlin_factor
78  */
79  electrical.current = b - pow((pow(b,electrical_priv.nonlin_factor)-pow((b*x),electrical_priv.nonlin_factor)), (1./electrical_priv.nonlin_factor));
80 #endif
82
83 }
Definition: booz_1.0.h:114
Definition: electrical.c:19
Definition: electrical.c:29
arch independent ADC (Analog to Digital Converter) API
Definition: electrical.c:32
void electrical_init(void)
Definition: electrical.c:39
uint8_t vsupply
Definition: electrical.h:8
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
void electrical_periodic(void)
Definition: electrical.c:53
int32_t current
Definition: electrical.h:9