Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
flight_benchmark.c
Go to the documentation of this file.
1 //Author: Bruzzlee
2 
3 //This module allows a quantitative assessment of the flight.
4 //It calculates the sum of squared error of the two-dimensional course (x / y), the altitude and true airspeed.
5 //The sum of squared error of the course and altitude were separated, because they are regulated separately, and so they dependent on various parameters.
6 //The module was written to optimize the control parameters and has already been used successfully.
7 
8 
10 #include "state.h"
11 #include "pprzlink/messages.h"
13 #include "mcu_periph/uart.h"
14 #include "generated/airframe.h"
16 // #include "math/pprz_algebra_int.h"
17 // #include "math/pprz_algebra_float.h"
18 
19 // For Downlink
20 
21 
22 
30 bool benchm_go;
31 
32 
33 //uint8_t numOfCount;
34 
35 
36 
38 {
42  ToleranceAispeed = BENCHMARK_TOLERANCE_AIRSPEED;
43  ToleranceAltitude = BENCHMARK_TOLERANCE_ALTITUDE;
44  TolerancePosition = BENCHMARK_TOLERANCE_POSITION;
45  benchm_reset = 0;
46  benchm_go = 0;
47 }
48 
50 {
51  float Err_airspeed = 0;
52  float Err_altitude = 0;
53  float Err_position = 0;
54 
55  if (benchm_reset) {
57  benchm_reset = 0;
58  }
59 
60  if (benchm_go) {
61 #if USE_AIRSPEED && defined(BENCHMARK_AIRSPEED)
62  Err_airspeed = fabs(stateGetAirspeed_f() - v_ctl_auto_airspeed_setpoint);
63  if (Err_airspeed > ToleranceAispeed) {
64  Err_airspeed = Err_airspeed - ToleranceAispeed;
65  SquareSumErr_airspeed += (Err_airspeed * Err_airspeed);
66  }
67 #endif
68 
69 #ifdef BENCHMARK_ALTITUDE
70  Err_altitude = fabs(stateGetPositionUtm_f()->alt - v_ctl_altitude_setpoint);
71  if (Err_altitude > ToleranceAltitude) {
72  Err_altitude = Err_altitude - ToleranceAltitude;
73  SquareSumErr_altitude += (Err_altitude * Err_altitude);
74  }
75 #endif
76 
77 #ifdef BENCHMARK_POSITION
78 
79  //---------------This part is a waste of memory and calculation power - but it works - feel free to optimize it ;-) -----------------
80 
81  // err_temp = waypoints[target].x - stateGetPositionEnu_f()->x;
82  float deltaPlaneX = 0;
83  float deltaPlaneY = 0;
84  float Err_position_segment = 0;
85  float Err_position_circle = 0;
86 
87 // if (nav_in_segment){
88  float deltaX = nav_segment_x_2 - nav_segment_x_1;
89  float deltaY = nav_segment_y_2 - nav_segment_y_1;
90  float anglePath = atan2(deltaX, deltaY);
91  deltaPlaneX = nav_segment_x_2 - stateGetPositionEnu_f()->x;
92  deltaPlaneY = nav_segment_y_2 - stateGetPositionEnu_f()->y;
93  float anglePlane = atan2(deltaPlaneX, deltaPlaneY);
94  float angleDiff = fabs(anglePlane - anglePath);
95  Err_position_segment = fabs(sin(angleDiff) * sqrt(deltaPlaneX * deltaPlaneX + deltaPlaneY * deltaPlaneY));
96 // }
97 
98 // if (nav_in_circle){
99  deltaPlaneX = nav_circle_x - stateGetPositionEnu_f()->x;
100  deltaPlaneY = nav_circle_y - stateGetPositionEnu_f()->y;
101  Err_position_circle = fabs(sqrt(deltaPlaneX * deltaPlaneX + deltaPlaneY * deltaPlaneY) - nav_circle_radius);
102 // }
103  if (Err_position_circle < Err_position_segment) {
104  Err_position = Err_position_circle;
105  } else {
106  Err_position = Err_position_segment;
107  }
108 
109  if (Err_position > TolerancePosition) {
110  SquareSumErr_position += (Err_position * Err_position);
111  }
112 #endif
113  }
114 
115  DOWNLINK_SEND_FLIGHT_BENCHMARK(DefaultChannel, DefaultDevice, &SquareSumErr_airspeed, &SquareSumErr_altitude,
116  &SquareSumErr_position, &Err_airspeed, &Err_altitude, &Err_position)
117 
118 }
119 
121 {
125 }
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
bool benchm_reset
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
float v_ctl_altitude_setpoint
in meters above MSL
Definition: energy_ctrl.c:88
bool benchm_go
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1389
float ToleranceAispeed
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:713
void flight_benchmark_periodic(void)
float v_ctl_auto_airspeed_setpoint
in meters per second
Definition: energy_ctrl.c:121
float x
in meters
Vertical control for fixed wing vehicles.
void flight_benchmark_init(void)
void flight_benchmark_reset(void)
float SquareSumErr_altitude
float SquareSumErr_position
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:686
API to get/set the generic vehicle states.
float SquareSumErr_airspeed
float ToleranceAltitude
float TolerancePosition
float y
in meters