Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
eff_scheduling_cyfoam.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Ewoud Smeur <ewoud_smeur@msn.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include "generated/airframe.h"
29 #include "state.h"
31 
32 #if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
33 #error "You need to use WLS control allocation for this module"
34 #endif
35 
36 #ifndef INDI_FUNCTIONS_RC_CHANNEL
37 #error "You need to define an RC channel to switch between simple and advanced scheduling"
38 #endif
39 
40 #ifdef FWD_G1
41 static float g1g2_forward[INDI_OUTPUTS][INDI_NUM_ACT] = FWD_G1;
42 #else
43 static float g1g2_forward[INDI_OUTPUTS][INDI_NUM_ACT] = {
44  FWD_G1_ROLL,
45  FWD_G1_PITCH,
46  FWD_G1_YAW,
47  FWD_G1_THRUST
48 };
49 #endif
50 
51 #ifdef STABILIZATION_INDI_G1
52 static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT] = STABILIZATION_INDI_G1;
53 #else
54 static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT] = {
55  STABILIZATION_INDI_G1_ROLL,
56  STABILIZATION_INDI_G1_PITCH,
57  STABILIZATION_INDI_G1_YAW,
58  STABILIZATION_INDI_G1_THRUST
59 };
60 #endif
61 
62 static float g2_both[INDI_NUM_ACT] = STABILIZATION_INDI_G2; //scaled by INDI_G_SCALING
63 
65 {
66  //sum of G1 and G2
67  int8_t i;
68  int8_t j;
69  for (i = 0; i < INDI_OUTPUTS; i++) {
70  for (j = 0; j < INDI_NUM_ACT; j++) {
71  if (i != 2) {
72  g1g2_hover[i][j] = g1g2_hover[i][j] / INDI_G_SCALING;
74  } else {
75  g1g2_forward[i][j] = (g1g2_forward[i][j] + g2_both[j]) / INDI_G_SCALING;
76  g1g2_hover[i][j] = (g1g2_hover[i][j] + g2_both[j]) / INDI_G_SCALING;
77  }
78  }
79  }
80 }
81 
82 static void eff_scheduling_periodic_a(void)
83 {
84  int8_t i;
85  int8_t j;
86  const float ratio = stabilization.transition_ratio;
87  for (i = 0; i < INDI_OUTPUTS; i++) {
88  for (j = 0; j < INDI_NUM_ACT; j++) {
89  g1g2[i][j] = g1g2_hover[i][j] * (1.0 - ratio) + g1g2_forward[i][j] * ratio;
90  }
91  }
92 }
93 
94 static void eff_scheduling_periodic_b(void)
95 {
96  float airspeed = stateGetAirspeed_f();
97  struct FloatEulers eulers_zxy;
98  if(airspeed < 6.0) {
100  float pitch_interp = DegOfRad(eulers_zxy.theta);
101  Bound(pitch_interp, -60.0, -30.0);
102  float ratio = (pitch_interp + 30.0)/(-30.);
103 
104  /*pitch*/
105  g1g2[1][0] = g1g2_hover[1][0]*(1-ratio) + -PITCH_EFF_AT_60/1000*ratio;
106  g1g2[1][1] = g1g2_hover[1][1]*(1-ratio) + PITCH_EFF_AT_60/1000*ratio;
107  /*yaw*/
108  g1g2[2][0] = g1g2_hover[2][0]*(1-ratio) + -YAW_EFF_AT_60/1000*ratio;
109  g1g2[2][1] = g1g2_hover[2][1]*(1-ratio) + -YAW_EFF_AT_60/1000*ratio;
110  } else {
111  // calculate squared airspeed
112  Bound(airspeed, 0.0, 30.0);
113  float airspeed2 = airspeed*airspeed;
114 
115  float pitch_eff = CE_PITCH_A + CE_PITCH_B*airspeed2;
116  g1g2[1][0] = -pitch_eff/1000;
117  g1g2[1][1] = pitch_eff/1000;
118 
119  float yaw_eff = CE_YAW_A + CE_YAW_B*airspeed2;
120  g1g2[2][0] = -yaw_eff/1000;
121  g1g2[2][1] = -yaw_eff/1000;
122  }
123 
124  g1g2[0][2] = -actuator_state_filt_vect[2]/1000*SQUARED_ROLL_EFF;
125  g1g2[0][3] = actuator_state_filt_vect[3]/1000*SQUARED_ROLL_EFF;
126  Bound(g1g2[0][2], -30.0/1000, -2.0/1000);
127  Bound(g1g2[0][3], 2.0/1000, 30.0/1000);
128 
129  /*Make pitch gain equal to roll gain for turns forward flight*/
130  if(airspeed > 12.0) {
131  indi_gains.att.q = 107.0;
132  } else {
133  indi_gains.att.q = 200.0;
134  }
135 
136 }
137 
139 {
140  if (radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0) {
142  } else {
144  }
145 
146 #ifdef INDI_THRUST_ON_PITCH_EFF
147  //State prioritization {W Roll, W pitch, W yaw, TOTAL THRUST}
148  if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] < -7000) && (actuator_state_filt_vect[1] > 7000)) {
149  Bwls[1][2] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
150  Bwls[1][3] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
151  } else if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] > 7000) && (actuator_state_filt_vect[1] < -7000)) {
152  Bwls[1][2] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
153  Bwls[1][3] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
154  } else {
155  Bwls[1][2] = 0.0;
156  Bwls[1][3] = 0.0;
157  }
158 #endif
159 }
160 
static void eff_scheduling_periodic_a(void)
static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT]
static float g2_both[INDI_NUM_ACT]
void eff_scheduling_cyfoam_periodic(void)
Periodic function that interpolates between gain sets depending on the scheduling variable.
void eff_scheduling_cyfoam_init(void)
Initialises periodic loop;.
static float g1g2_forward[INDI_OUTPUTS][INDI_NUM_ACT]
static void eff_scheduling_periodic_b(void)
float yaw_eff
float q
in rad/s
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:1294
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1590
struct FloatEulers eulers_zxy
state eulers in zxy order
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67
Horizontal guidance for rotorcrafts.
struct Stabilization stabilization
Definition: stabilization.c:41
float transition_ratio
transition percentage for hybrids (0.: hover; 1.: forward)
float * Bwls[INDI_OUTPUTS]
struct Indi_gains indi_gains
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
float actuator_state_filt_vect[INDI_NUM_ACT]
#define INDI_G_SCALING
struct FloatRates att
API to get/set the generic vehicle states.
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103