Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
oneloop_andi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Tomaso De Ponti <tmldeponti@tudelft.nl>
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 
26 #ifndef ONELOOP_ANDI_H
27 #define ONELOOP_ANDI_H
28 
32 #include "generated/airframe.h"
35 
36 #ifndef ANDI_NUM_ACT
37 #define ANDI_NUM_ACT COMMANDS_NB_REAL
38 #endif
39 
40 #ifndef ANDI_NUM_VIRTUAL_ACT
41 #define ANDI_NUM_VIRTUAL_ACT COMMANDS_NB_VIRTUAL
42 #endif
43 
44 // Number of virtual actuators (e.g. Phi, Theta). For now 2 and only 2 are supported but in the future this can be further developed.
45 #if ANDI_NUM_VIRTUAL_ACT < 2
46 #error "You must specify the number of virtual actuators to be at least 2"
47 #define ANDI_NUM_VIRTUAL_ACT 2
48 #endif
49 
50 #define ANDI_NUM_ACT_TOT (ANDI_NUM_ACT + ANDI_NUM_VIRTUAL_ACT)
51 
52 #ifndef ANDI_OUTPUTS
53 #error "You must specify the number of controlled axis (outputs)"
54 #define ANDI_OUTPUTS 6
55 #endif
56 #define ANDI_G_SCALING 1000.0f
57 
59 #define CTRL_ANDI 0
60 #define CTRL_INDI 1
61 
62 extern bool ctrl_off;
64 extern float actuator_state_1l[ANDI_NUM_ACT];
65 extern float nu[6];
67 extern float andi_u[ANDI_NUM_ACT_TOT];
68 extern float andi_du[ANDI_NUM_ACT_TOT];
69 extern float psi_des_deg;
70 extern bool heading_manual;
71 extern bool yaw_stick_in_auto;
72 extern float fwd_sideslip_gain;
73 extern struct FloatEulers eulers_zxy_des;
74 extern float psi_des_rad;
75 extern float k_as;
76 extern float max_as;
77 extern float gi_unbounded_airspeed_sp;
78 
79 /*Chirp test Variables*/
80 extern bool chirp_on;
81 extern float f0_chirp;
82 extern float f1_chirp;
83 extern float t_chirp;
84 extern float A_chirp;
85 extern int8_t chirp_axis;
86 
87 // Delete once hybrid nav is fixed //////////////////////////////////////////////////////////////////////////////////
89  float pos_gain;
90  float pos_gainz;
91  float speed_gain;
92  float speed_gainz;
93  float heading_bank_gain;
94  float liftd_asq;
95  float liftd_p80;
96  float liftd_p50;
97 };
99 //extern bool force_forward;
102  float pos[3];
103  float vel[3];
104  float acc[3];
105  float jer[3];
106 };
107 
109  float pos[3];
110  float vel[3];
111  float acc[3];
112 };
113 
115  float att[3];
116  float att_d[3];
117  float att_2d[3];
118  float att_3d[3];
119 };
120 
122  float att[3];
123  float att_d[3];
124  float att_2d[3];
125 };
127  bool half_loop;
129  struct OneloopGuidanceRef gui_ref; // Guidance References
130  struct OneloopGuidanceState gui_state; // Guidance State
131  struct OneloopStabilizationRef sta_ref; // Stabilization References
132  struct OneloopStabilizationState sta_state; // Stabilization State
133 
134 };
135 
136 extern struct OneloopGeneral oneloop_andi;
137 
139  float omega_n;
140  float zeta;
141  float p3;
142 };
144  float k1[3];
145  float k2[3];
146  float k3[3];
147 };
149  float k2;
150  float k3;
151 };
152 
153 struct CF4_t {
154  float tau;
155  float freq;
156  float freq_set;
157  float model;
159  float feedback;
161  float out;
162 };
163 struct CF2_t {
164  float tau;
165  float freq;
166  float freq_set;
167  float model;
169  float feedback;
171  float out;
172 };
173 
174 struct Oneloop_CF_t {
175  struct CF2_t p;
176  struct CF2_t q;
177  struct CF2_t r;
178  struct CF4_t p_dot;
179  struct CF4_t q_dot;
180  struct CF2_t r_dot;
181  struct CF2_t ax;
182  struct CF2_t ay;
183  struct CF2_t az;
184 };
185 extern struct Oneloop_CF_t cf;
188  float freq;
189  float bandwidth;
190 };
192  struct notch_axis_t roll;
193  struct notch_axis_t pitch;
194  struct notch_axis_t yaw;
195 };
196 
197 extern int16_t temp_pitch;
198 /*Declaration of Reference Model and Error Controller Gains*/
199 extern struct PolePlacement p_att_e;
200 extern struct PolePlacement p_att_rm;
201 /*Position Loop*/
202 extern struct PolePlacement p_pos_e;
203 extern struct PolePlacement p_pos_rm;
204 /*Altitude Loop*/
205 extern struct PolePlacement p_alt_e;
206 extern struct PolePlacement p_alt_rm;
207 /*Heading Loop*/
208 extern struct PolePlacement p_head_e;
209 extern struct PolePlacement p_head_rm;
210 /*Gains of EC and RM*/
211 extern struct Gains3rdOrder k_att_e;
212 extern struct Gains3rdOrder k_att_rm;
213 extern struct Gains2ndOrder k_head_e;
214 extern struct Gains2ndOrder k_head_rm;
215 extern struct Gains3rdOrder k_pos_e;
216 extern struct Gains3rdOrder k_pos_rm;
217 extern void oneloop_andi_init(void);
218 extern void oneloop_andi_enter(bool half_loop_sp, int ctrl_type);
220 extern void oneloop_andi_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des, int rm_order_h, int rm_order_v);
221 extern void oneloop_andi_RM(bool half_loop, struct FloatVect3 PSA_des, int rm_order_h, int rm_order_v, bool in_flight_oneloop);
222 extern void oneloop_andi_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn);
223 extern void oneloop_from_nav(bool in_flight);
224 extern void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed);
225 #endif // ONELOOP_ANDI_H
euler angles
int32_t max_airspeed
Simple first order low pass filter with bilinear transform.
Fourth order Butterworth low pass filter.
Second order low pass filter structure.
void oneloop_andi_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
struct PolePlacement p_pos_e
Definition: oneloop_andi.c:435
struct OneloopGuidanceState gui_state
Definition: oneloop_andi.h:130
struct notch_axis_t yaw
Definition: oneloop_andi.h:194
struct OneloopStabilizationState sta_state
Definition: oneloop_andi.h:132
struct CF4_t q_dot
Definition: oneloop_andi.h:179
struct PolePlacement p_head_rm
Definition: oneloop_andi.c:442
void oneloop_andi_RM(bool half_loop, struct FloatVect3 PSA_des, int rm_order_h, int rm_order_v, bool in_flight_oneloop)
Function to generate the reference signals for the oneloop controller.
void oneloop_andi_enter(bool half_loop_sp, int ctrl_type)
Function that resets important values upon engaging Oneloop ANDI.
Butterworth2LowPass feedback_filt
Definition: oneloop_andi.h:170
float freq_set
Definition: oneloop_andi.h:166
struct Gains3rdOrder k_att_rm
Definition: oneloop_andi.c:445
struct guidance_indi_hybrid_params gih_params
float feedback
Definition: oneloop_andi.h:169
float freq_set
Definition: oneloop_andi.h:156
struct FloatEulers eulers_zxy_des
Definition: oneloop_andi.c:359
float freq
Definition: oneloop_andi.h:165
struct PolePlacement p_att_rm
Definition: oneloop_andi.c:433
float g1g2_1l[ANDI_OUTPUTS][ANDI_NUM_ACT_TOT]
float out
Definition: oneloop_andi.h:171
int16_t temp_pitch
Definition: oneloop_andi.c:342
struct CF2_t az
Definition: oneloop_andi.h:183
float max_as
Definition: oneloop_andi.c:270
struct Gains3rdOrder k_att_e
Definition: oneloop_andi.c:444
float psi_des_rad
Definition: oneloop_andi.c:362
float model
Definition: oneloop_andi.h:157
bool ctrl_off
Definition: oneloop_andi.c:376
struct Gains3rdOrder k_pos_e
Definition: oneloop_andi.c:446
struct Gains2ndOrder k_head_rm
float t_chirp
Definition: oneloop_andi.c:426
float tau
Definition: oneloop_andi.h:154
float nu[6]
Definition: oneloop_andi.c:349
#define ANDI_NUM_ACT
Definition: oneloop_andi.h:37
Butterworth4LowPass feedback_filt
Definition: oneloop_andi.h:160
Butterworth4LowPass model_filt
Definition: oneloop_andi.h:158
float f0_chirp
Definition: oneloop_andi.c:424
void oneloop_from_nav(bool in_flight)
Function that maps navigation inputs to the oneloop controller for the generated autopilot.
struct PolePlacement p_alt_rm
Definition: oneloop_andi.c:439
struct OneloopGuidanceRef gui_ref
Definition: oneloop_andi.h:129
struct CF2_t p
Definition: oneloop_andi.h:175
struct Gains2ndOrder k_head_e
bool chirp_on
Definition: oneloop_andi.c:420
void oneloop_andi_set_failsafe_setpoint(void)
struct OneloopStabilizationRef sta_ref
Definition: oneloop_andi.h:131
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
float andi_u[ANDI_NUM_ACT_TOT]
Definition: oneloop_andi.c:346
struct Oneloop_CF_t cf
Definition: oneloop_andi.c:416
float fwd_sideslip_gain
Definition: oneloop_andi.c:280
float f1_chirp
Definition: oneloop_andi.c:425
void oneloop_andi_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des, int rm_order_h, int rm_order_v)
Main function that runs the controller and performs control allocation.
struct PolePlacement p_att_e
Definition: oneloop_andi.c:432
float freq
Definition: oneloop_andi.h:155
struct PolePlacement p_alt_e
Definition: oneloop_andi.c:438
float A_chirp
Definition: oneloop_andi.c:427
struct PolePlacement p_head_e
Definition: oneloop_andi.c:441
struct notch_axis_t pitch
Definition: oneloop_andi.h:193
int8_t chirp_axis
Definition: oneloop_andi.c:428
#define ANDI_NUM_ACT_TOT
Definition: oneloop_andi.h:50
float andi_du[ANDI_NUM_ACT_TOT]
Definition: oneloop_andi.c:347
bool heading_manual
Definition: oneloop_andi.c:369
struct OneloopGeneral oneloop_andi
Definition: oneloop_andi.c:333
struct Gains3rdOrder k_pos_rm
Definition: oneloop_andi.c:447
struct CF2_t ay
Definition: oneloop_andi.h:182
float feedback
Definition: oneloop_andi.h:159
struct notch_axis_t roll
Definition: oneloop_andi.h:192
struct CF2_t q
Definition: oneloop_andi.h:176
struct CF2_t r
Definition: oneloop_andi.h:177
float psi_des_deg
Definition: oneloop_andi.c:363
void oneloop_andi_init(void)
Init function of Oneloop ANDI controller
float model
Definition: oneloop_andi.h:167
float gi_unbounded_airspeed_sp
struct SecondOrderNotchFilter filter
Definition: oneloop_andi.h:187
#define ANDI_OUTPUTS
Definition: oneloop_andi.h:54
float k_as
Definition: oneloop_andi.c:341
struct CF2_t r_dot
Definition: oneloop_andi.h:180
struct PolePlacement p_pos_rm
Definition: oneloop_andi.c:436
bool yaw_stick_in_auto
Definition: oneloop_andi.c:374
float act_state_filt_vect_1l[ANDI_NUM_ACT]
struct CF2_t ax
Definition: oneloop_andi.h:181
struct CF4_t p_dot
Definition: oneloop_andi.h:178
float actuator_state_1l[ANDI_NUM_ACT]
Definition: oneloop_andi.c:352
float tau
Definition: oneloop_andi.h:164
float out
Definition: oneloop_andi.h:161
Butterworth2LowPass model_filt
Definition: oneloop_andi.h:168
General stabilization interface for rotorcrafts.
Common data structures shared by euler and quaternion int implementations.
Rotorcraft attitude reference generation.
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103