Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 
28 bool benchm_go;
29 
30 //uint8_t numOfCount;
31 
33 {
37  ToleranceAispeed = BENCHMARK_TOLERANCE_AIRSPEED;
38  ToleranceAltitude = BENCHMARK_TOLERANCE_ALTITUDE;
39  TolerancePosition = BENCHMARK_TOLERANCE_POSITION;
40  benchm_reset = 0;
41  benchm_go = 0;
42 }
43 
45 {
46  float Err_airspeed = 0;
47  float Err_altitude = 0;
48  float Err_position = 0;
49 
50  if (benchm_reset) {
52  benchm_reset = 0;
53  }
54 
55  if (benchm_go) {
56 #if USE_AIRSPEED && defined(BENCHMARK_AIRSPEED)
57  Err_airspeed = fabs(stateGetAirspeed_f() - v_ctl_auto_airspeed_setpoint);
58  if (Err_airspeed > ToleranceAispeed) {
59  Err_airspeed = Err_airspeed - ToleranceAispeed;
60  SquareSumErr_airspeed += (Err_airspeed * Err_airspeed);
61  }
62 #endif
63 
64 #ifdef BENCHMARK_ALTITUDE
65  Err_altitude = fabs(stateGetPositionUtm_f()->alt - v_ctl_altitude_setpoint);
66  if (Err_altitude > ToleranceAltitude) {
67  Err_altitude = Err_altitude - ToleranceAltitude;
68  SquareSumErr_altitude += (Err_altitude * Err_altitude);
69  }
70 #endif
71 
72 #ifdef BENCHMARK_POSITION
73 
74  //---------------This part is a waste of memory and calculation power - but it works - feel free to optimize it ;-) -----------------
75 
76  // err_temp = waypoints[target].x - stateGetPositionEnu_f()->x;
77  float deltaPlaneX = 0;
78  float deltaPlaneY = 0;
79  float Err_position_segment = 0;
80  float Err_position_circle = 0;
81 
82 // if (nav_in_segment){
83  float deltaX = nav_segment_x_2 - nav_segment_x_1;
84  float deltaY = nav_segment_y_2 - nav_segment_y_1;
85  float anglePath = atan2(deltaX, deltaY);
86  deltaPlaneX = nav_segment_x_2 - stateGetPositionEnu_f()->x;
87  deltaPlaneY = nav_segment_y_2 - stateGetPositionEnu_f()->y;
88  float anglePlane = atan2(deltaPlaneX, deltaPlaneY);
89  float angleDiff = fabs(anglePlane - anglePath);
90  Err_position_segment = fabs(sin(angleDiff) * sqrt(deltaPlaneX * deltaPlaneX + deltaPlaneY * deltaPlaneY));
91 // }
92 
93 // if (nav_in_circle){
94  deltaPlaneX = nav_circle_x - stateGetPositionEnu_f()->x;
95  deltaPlaneY = nav_circle_y - stateGetPositionEnu_f()->y;
96  Err_position_circle = fabs(sqrt(deltaPlaneX * deltaPlaneX + deltaPlaneY * deltaPlaneY) - nav_circle_radius);
97 // }
98  if (Err_position_circle < Err_position_segment) {
99  Err_position = Err_position_circle;
100  } else {
101  Err_position = Err_position_segment;
102  }
103 
104  if (Err_position > TolerancePosition) {
105  SquareSumErr_position += (Err_position * Err_position);
106  }
107 #endif
108  }
109 
110  DOWNLINK_SEND_FLIGHT_BENCHMARK(DefaultChannel, DefaultDevice, &SquareSumErr_airspeed, &SquareSumErr_altitude,
111  &SquareSumErr_position, &Err_airspeed, &Err_altitude, &Err_position);
112 
113 }
114 
116 {
120 }
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
SquareSumErr_airspeed
float SquareSumErr_airspeed
Definition: flight_benchmark.c:21
nav_circle_x
float nav_circle_x
Definition: nav.c:69
nav_circle_y
float nav_circle_y
Definition: nav.c:69
flight_benchmark_periodic
void flight_benchmark_periodic(void)
Definition: flight_benchmark.c:44
stateGetPositionEnu_f
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:719
SquareSumErr_altitude
float SquareSumErr_altitude
Definition: flight_benchmark.c:22
flight_benchmark_init
void flight_benchmark_init(void)
Definition: flight_benchmark.c:32
stateGetPositionUtm_f
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:692
EnuCoor_f::y
float y
in meters
Definition: pprz_geodetic_float.h:74
nav_circle_radius
float nav_circle_radius
Definition: nav.c:69
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
stateGetAirspeed_f
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
nav_segment_x_2
float nav_segment_x_2
Definition: nav.c:70
ToleranceAispeed
float ToleranceAispeed
Definition: flight_benchmark.c:24
benchm_go
bool benchm_go
Definition: flight_benchmark.c:28
SquareSumErr_position
float SquareSumErr_position
Definition: flight_benchmark.c:23
flight_benchmark_reset
void flight_benchmark_reset(void)
Definition: flight_benchmark.c:115
nav.h
benchm_reset
bool benchm_reset
Definition: flight_benchmark.c:27
v_ctl_altitude_setpoint
float v_ctl_altitude_setpoint
in meters above MSL
Definition: energy_ctrl.c:88
ToleranceAltitude
float ToleranceAltitude
Definition: flight_benchmark.c:25
nav_segment_y_1
float nav_segment_y_1
Definition: nav.c:70
TolerancePosition
float TolerancePosition
Definition: flight_benchmark.c:26
nav_segment_x_1
float nav_segment_x_1
Definition: nav.c:70
v_ctl_auto_airspeed_setpoint
float v_ctl_auto_airspeed_setpoint
in meters per second
Definition: energy_ctrl.c:121
EnuCoor_f::x
float x
in meters
Definition: pprz_geodetic_float.h:73
state.h
nav_segment_y_2
float nav_segment_y_2
Definition: nav.c:70
guidance_v.h