Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
eff_scheduling_falcon.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Florian Sansou <florian.sansou@enac.fr>
3  * Copyright (C) 2023 Gautier Hattenberger <gautier.hattenberger.fr>
4  *
5  * This file is part of paparazzi
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
29 #include "state.h"
30 
32 
33 // Airspeed at which only with motor
34 #ifndef EFF_SCHEDULING_FALCON_LOW_AIRSPEED
35 #define EFF_SCHEDULING_FALCON_LOW_AIRSPEED 8.0f
36 #endif
37 
38 #ifdef STABILIZATION_INDI_G1
39 static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT] = STABILIZATION_INDI_G1;
40 #else
41 static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT] = {
42  STABILIZATION_INDI_G1_ROLL,
43  STABILIZATION_INDI_G1_PITCH,
44  STABILIZATION_INDI_G1_YAW,
45  STABILIZATION_INDI_G1_THRUST
46 };
47 #endif
48 
50 {
51  for (int8_t i = 0; i < INDI_OUTPUTS; i++) {
52  for (int8_t j = 0; j < INDI_NUM_ACT; j++) {
53  g1g2[i][j] = g1g2_hover[i][j] / INDI_G_SCALING;
54  }
55  }
56 }
57 
59 {
60  // calculate squared airspeed
61  float airspeed = stateGetAirspeed_f();
62 
63  if (airspeed > EFF_SCHEDULING_FALCON_LOW_AIRSPEED) {
64  airspeed -= EFF_SCHEDULING_FALCON_LOW_AIRSPEED; //offset for start eff at zero!
65  struct FloatEulers eulers_zxy;
67 
68  float pitch_ratio = 0.0f;
69  if (eulers_zxy.theta > -M_PI_4) {
70  pitch_ratio = 0.0f;
71  }
72  else {
73  pitch_ratio = fabsf(1.0f - eulers_zxy.theta/(float)(-M_PI_4));
74  }
75  Bound(pitch_ratio, 0.0f, 1.0f);
76 
77 
78  Bound(airspeed, 0.0f, 30.0f);
79  float airspeed2 = airspeed*airspeed;
80 
81  // not effect of elevon on body roll axis
82  g1g2[0][4] = 0;
83  g1g2[0][5] = 0;
84 
85  float pitch_eff = pitch_ratio * EFF_PITCH_A * airspeed2;
86  g1g2[1][4] = pitch_eff / 1000; // elevon_right
87  g1g2[1][5] = -pitch_eff / 1000; // elevon_left
88 
89  float yaw_eff = pitch_ratio * EFF_YAW_A * airspeed2;
90  g1g2[2][4] = -yaw_eff / 1000; // elevon_right
91  g1g2[2][5] = -yaw_eff / 1000; // elevon_left
92 
93  // No thrust generated by elevon, maybe take drag in accout for the future ?
94  g1g2[3][4] = 0;
95  g1g2[3][5] = 0;
96  }
97  else {
98  //Come back to motor control
99  g1g2[0][4] = 0; // elevon_left
100  g1g2[0][5] = 0; // elevon_right
101 
102  g1g2[1][4] = 0; // elevon_left
103  g1g2[1][5] = 0; // elevon_right
104 
105  g1g2[2][4] = 0; // elevon_left
106  g1g2[2][5] = 0; // elevon_right
107 
108  g1g2[3][4] = 0; // elevon_left
109  g1g2[3][5] = 0; // elevon_right
110  }
111 }
112 
114 {
115  float f[6] = {
116  g1g2[1][4], g1g2[1][5],
117  g1g2[2][4], g1g2[2][5],
118  g1g2[1][0], g1g2[2][0]
119  };
120  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, 6, f);
121 }
122 
#define EFF_SCHEDULING_FALCON_LOW_AIRSPEED
void eff_scheduling_falcon_periodic(void)
void eff_scheduling_falcon_report(void)
static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT]
void eff_scheduling_falcon_init(void)
Interpolation of control effectivenss matrix of the Falcon hybrid plane.
float theta
in radians
void float_eulers_of_quat_zxy(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
euler angles
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
Definition: state.h:1131
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
struct FloatEulers eulers_zxy
state eulers in zxy order
Horizontal guidance for rotorcrafts.
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
#define INDI_G_SCALING
API to get/set the generic vehicle states.
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
Definition: wedgebug.c:204