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  // Go from transition percentage to ratio
86 
87  int8_t i;
88  int8_t j;
89  for (i = 0; i < INDI_OUTPUTS; i++) {
90  for (j = 0; j < INDI_NUM_ACT; j++) {
91  g1g2[i][j] = g1g2_hover[i][j] * (1.0 - ratio) + g1g2_forward[i][j] * ratio;
92  }
93  }
94 }
95 
96 static void eff_scheduling_periodic_b(void)
97 {
98  float airspeed = stateGetAirspeed_f();
99  struct FloatEulers eulers_zxy;
100  if(airspeed < 6.0) {
102  float pitch_interp = DegOfRad(eulers_zxy.theta);
103  Bound(pitch_interp, -60.0, -30.0);
104  float ratio = (pitch_interp + 30.0)/(-30.);
105 
106  /*pitch*/
107  g1g2[1][0] = g1g2_hover[1][0]*(1-ratio) + -PITCH_EFF_AT_60/1000*ratio;
108  g1g2[1][1] = g1g2_hover[1][1]*(1-ratio) + PITCH_EFF_AT_60/1000*ratio;
109  /*yaw*/
110  g1g2[2][0] = g1g2_hover[2][0]*(1-ratio) + -YAW_EFF_AT_60/1000*ratio;
111  g1g2[2][1] = g1g2_hover[2][1]*(1-ratio) + -YAW_EFF_AT_60/1000*ratio;
112  } else {
113  // calculate squared airspeed
114  Bound(airspeed, 0.0, 30.0);
115  float airspeed2 = airspeed*airspeed;
116 
117  float pitch_eff = CE_PITCH_A + CE_PITCH_B*airspeed2;
118  g1g2[1][0] = -pitch_eff/1000;
119  g1g2[1][1] = pitch_eff/1000;
120 
121  float yaw_eff = CE_YAW_A + CE_YAW_B*airspeed2;
122  g1g2[2][0] = -yaw_eff/1000;
123  g1g2[2][1] = -yaw_eff/1000;
124  }
125 
126  g1g2[0][2] = -actuator_state_filt_vect[2]/1000*SQUARED_ROLL_EFF;
127  g1g2[0][3] = actuator_state_filt_vect[3]/1000*SQUARED_ROLL_EFF;
128  Bound(g1g2[0][2], -30.0/1000, -2.0/1000);
129  Bound(g1g2[0][3], 2.0/1000, 30.0/1000);
130 
131  /*Make pitch gain equal to roll gain for turns forward flight*/
132  if(airspeed > 12.0) {
133  indi_gains.att.q = 107.0;
134  } else {
135  indi_gains.att.q = 200.0;
136  }
137 
138 }
139 
141 {
142  if (radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0) {
144  } else {
146  }
147 
148 #ifdef INDI_THRUST_ON_PITCH_EFF
149  //State prioritization {W Roll, W pitch, W yaw, TOTAL THRUST}
150  if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] < -7000) && (actuator_state_filt_vect[1] > 7000)) {
151  Bwls[1][2] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
152  Bwls[1][3] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
153  } else if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] > 7000) && (actuator_state_filt_vect[1] < -7000)) {
154  Bwls[1][2] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
155  Bwls[1][3] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
156  } else {
157  Bwls[1][2] = 0.0;
158  Bwls[1][3] = 0.0;
159  }
160 #endif
161 }
162 
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 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
#define INT32_PERCENTAGE_FRAC
#define FLOAT_OF_BFP(_vbfp, _frac)
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
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
int32_t transition_percentage
Definition: guidance_h.c:52
Horizontal guidance for rotorcrafts.
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