Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
oneloop_nB.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_NB_H
27#define ONELOOP_NB_H
28//====================================================================================================================================
29// Include the header files needed
34#include "generated/airframe.h"
37//====================================================================================================================================
38// Define macros used in the C file
39#ifndef ANDI_NUM_ACT
40#define ANDI_NUM_ACT COMMANDS_NB_REAL
41#endif
42
43#ifndef COMMANDS_NB_VIRTUAL
44#define COMMANDS_NB_VIRTUAL 0
45#endif
46
47#ifndef ANDI_NUM_VIRTUAL_ACT
48#define ANDI_NUM_VIRTUAL_ACT COMMANDS_NB_VIRTUAL
49#endif
50
51#define ANDI_NUM_ACT_TOT (ANDI_NUM_ACT + ANDI_NUM_VIRTUAL_ACT)
52
53#ifndef ANDI_OUTPUTS
54#error "You must specify the number of controlled axis (outputs)"
55#define ANDI_OUTPUTS 6
56#endif
57#define ANDI_G_SCALING 1000.0f
58
60#define CTRL_ANDI 0
61#define CTRL_INDI 1
62#define CTRL_NB_ANDI 2
63#define CTRL_NB_INDI 3
64
65//====================================================================================================================================
66// Declaration of global variables
67extern bool auto_fault_cmd;
68extern bool use_safety_killer;
69extern bool safety_killer_trigger;
70extern float safety_killer_cutoff;
71extern float delta_fault;
72extern float oneloop_nB_filt_cutoff;
73extern bool vel_ctrl_in_manual;
74extern bool oneloop_nB_Z_hold;
75extern bool use_push_Position;
76extern bool use_push_PID;
77extern float max_bank;
78extern float max_phi;
79extern float max_theta;
80extern int8_t TestMotorIDX;
81extern float max_pusher_cmd;
82extern float max_fault_mot;
83extern float spin_prot_max_rate;
84extern float spin_prot_start_rate;
85extern float spin_prot_max_cmd;
86extern bool spin_trim_on;
87extern float spin_trim_rate;
88extern float spin_trim_bleed_rate;
89extern float spin_trim_release_rate;
90extern float spin_trim;
91extern float spin_prot_min_gap;
92extern float ec_k3;
93extern float pid_a_max;
94extern float pid_v_max_manual;
95extern float pid_v_max_nav;
96extern bool spin_man_up;
97extern bool spin_man_down;
99extern float spin_man_pitch_dir;
100extern float spin_man_ramp_rate;
101extern float spin_man_blend_time;
102extern float spin_man_trim_rate;
103extern float spin_man_done_rate;
105extern float spin_man_r_ref;
106extern float SpinQuadRate;
107extern bool SpinQuad;
108extern bool fault_pitch_motors;
109extern bool fault_roll_motors;
110extern bool fault_ailerons;
111extern float k_K;
112extern float k_P;
113extern float k_I;
114extern float k_D;
115extern float k1_NE_tune;
116extern float k2_NE_tune;
117extern bool ctrl_off; // Turn off stabilization control with the quad motors
118extern float act_state_filt_vect_1l[ANDI_NUM_ACT]; // Filtered actuator state vector to synch with the feedback signals
119extern float actuator_state_1l[ANDI_NUM_ACT_TOT]; // Actuator state vector (including virtual actuators)
120extern float nu[ANDI_OUTPUTS]; // Virtual control vector
121extern float g1g2_1l[ANDI_OUTPUTS][ANDI_NUM_ACT_TOT]; // Control effectiveness matrix
122extern float andi_u[ANDI_NUM_ACT_TOT]; // Control command vector
123extern float andi_du[ANDI_NUM_ACT_TOT]; // Control command increment vector
124extern float psi_des_deg; // Desired heading [deg]
125extern bool heading_manual; // Specify the heading with a slider
126extern bool yaw_stick_in_auto; // Adjust the heading in auto mode with the yaw stick
127extern float fwd_sideslip_gain; // Forward sideslip gain
128extern struct FloatEulers eulers_zxy_des; // Desired ZXY Euler angles
129extern float psi_des_rad; // Desired heading [rad]
130extern float max_as; // Maximum airspeed [m/s]
131extern float gi_unbounded_airspeed_sp; // Unbounded airspeed setpoint [m/s] (mimics guidance_indi_hybrid)
132extern bool drop_yaw; // Drop yaw control
133extern bool state_compensation_on; // Rotational Dynamics State Compensation
134//====================================================================================================================================
135// Delete once hybrid nav is fixed
137 float pos_gain;
138 float pos_gainz;
139 float speed_gain;
140 float speed_gainz;
141 float heading_bank_gain;
142 float liftd_asq;
143 float liftd_p80;
144 float liftd_p50;
145};
147//====================================================================================================================================
148// Declaration of the oneloop struct
149struct OneloopGuidanceRef {
150 float pos[3];
151 float vel[3];
152 float acc[3];
153 float jer[3];
154};
156 float pos[3];
157 float vel[3];
158 float acc[3];
159};
161 float att[3];
162 float att_d[3];
163 float att_2d[3];
164 float att_3d[3];
165};
167 float att[3];
168 float att_d[3];
169 float att_2d[3];
170};
184 float pN_d;
185 float pE_d;
186 float pN;
187 float pE;
188 float vN_d;
189 float vE_d;
190 float vN;
191 float vE;
194 float vN_filt;
195 float vE_filt;
196 float xi;
197 float xi_0;
198 float push_cmd;
200 float max_v_d;
202 int n;
203};
204struct OneloopGeneral {
205 bool half_loop;
206 int ctrl_type;
207 struct OneloopGuidanceRef gui_ref; // Guidance References
208 struct OneloopGuidanceState gui_state; // Guidance State
209 struct OneloopStabilizationRef sta_ref; // Stabilization References
210 struct OneloopStabilizationState sta_state; // Stabilization State
211 struct OneloopStabilizationnBState sta_nB_state; // nB Stabilization State
212 struct OneloopPushnB push_nB; // Pusher controller struct
213};
214extern struct OneloopGeneral oneloop_nB;
215//====================================================================================================================================
216// Declaration of the Controller gains/poles structs
217struct PolePlacement{
218 float omega_n;
219 float zeta;
220 float p3;
221};
222struct Gains3rdOrder{
223 float k1[3];
224 float k2[3];
225 float k3[3];
226};
227struct Gains2ndOrder{
228 float k2;
229 float k3;
230};
231/*Declaration of Reference Model and Error Controller Gains*/
232extern struct PolePlacement p_att_e;
233extern struct PolePlacement p_att_rm;
234/*Position Loop*/
235extern struct PolePlacement p_pos_e;
236extern struct PolePlacement p_pos_rm;
237/*Altitude Loop*/
238extern struct PolePlacement p_alt_e;
239extern struct PolePlacement p_alt_rm;
240/*Heading Loop*/
241extern struct PolePlacement p_head_e;
242extern struct PolePlacement p_head_rm;
243/*Gains of EC and RM*/
244extern struct Gains3rdOrder k_att_e;
245extern struct Gains3rdOrder k_att_rm;
246extern struct Gains2ndOrder k_head_e;
247extern struct Gains2ndOrder k_head_rm;
248extern struct Gains3rdOrder k_pos_e;
249extern struct Gains3rdOrder k_pos_rm;
250//====================================================================================================================================
251// Declaration of filtering structs
252enum FilterType { // enumeration of filter types
253 LOWPASS_1, // First order low pass
254 BUTTERWORTH_2, // Second order Butterworth
255 BUTTERWORTH_4, // Fourth order Butterworth
256 NOTCH // Notch filter
258struct LP_t { // Low pass filter structure
259 float tau; // Time constant [s]
260 float freq; // Cut-off frequency (currently used) [Hz]
261 float freq_set; // Desired cut-off frequency (to be set) [Hz]
262 float bandwidth; // Bandwidth of notch [Hz]
263 float meas; // Current measurement
264 float meas_prev; // Previous measurement
265 float out; // Filter output
266 enum FilterType filter_type; // Type of filter used for the structural modes
267 union {
268 struct FirstOrderLowPass lp1; // First order low pass filter struct
269 Butterworth2LowPass bw2; // Second order Butterworth filter struct
270 Butterworth4LowPass bw4; // Fourth order Butterworth filter struct
271 struct SecondOrderNotchFilter notch; // Second order notch filter struct
272 } meas_filt; // Union of different filter types
273};
274struct Oneloop_LP_t { // Struct containing all feedback low pass filters
275 struct LP_t p; // Roll rate filter
276 struct LP_t q; // Pitch rate filter
277 struct LP_t r; // Yaw rate filter
278 struct LP_t p_dot; // Roll acceleration filter
279 struct LP_t q_dot; // Pitch acceleration filter
280 struct LP_t r_dot; // Yaw acceleration filter
281 struct LP_t p_ddot; // Roll jerk filter
282 struct LP_t q_ddot; // Pitch jerk filter
283 struct LP_t r_ddot; // Yaw jerk filter
284 struct LP_t ax; // X acceleration filter
285 struct LP_t ay; // Y acceleration filter
286 struct LP_t az; // Z acceleration filter
287};
288struct Oneloop_DynFilt_t { // Dynamics Cancelling filter
289 float fs; // Sampling frequency [Hz]
290 float sigma; // Bandwidth of new dynamics [rad/s]
291 float varepsilon; // Bandwidth of the original dynamics [rad/s]
292 float u_c; // Current command input
293 float u_c_0; // Previous command input
294 float mu_c_0; // Previous filtered command output
295 float mu_c; // Current filtered command output
296};
297extern struct Oneloop_LP_t LP; // Instance of the struct containing all feedback low pass filters
298//====================================================================================================================================
299// Declaration of functions
300extern void oneloop_nB_init(void);
301extern void oneloop_nB_enter(bool half_loop_sp, int ctrl_type);
303extern void oneloop_nB_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des);
304extern void oneloop_nB_RM(bool half_loop, struct FloatVect3 PSA_des, bool in_flight_oneloop);
305extern void oneloop_nB_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn);
306extern void oneloop_from_nav(bool in_flight);
307extern void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed);
308extern void guidance_set_max_bank_angle(float max_bank);
311
312#endif // ONELOOP_NB_H
euler angles
int32_t max_airspeed
Simple first order low pass filter with bilinear transform.
Fourth order Butterworth low pass filter.
First order low pass filter structure.
Second order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58
FilterType
bool fault_ailerons
Definition oneloop_nB.c:501
float oneloop_nB_filt_cutoff
Definition oneloop_nB.c:130
struct PolePlacement p_pos_e
float spin_prot_min_gap
Definition oneloop_nB.c:567
struct OneloopGuidanceState gui_state
float k2_NE_tune
float k_D
struct OneloopStabilizationState sta_state
float spin_man_blend_time
Definition oneloop_nB.c:656
struct PolePlacement p_head_rm
struct FloatVect3 nI_3d
Definition oneloop_nB.h:180
struct Gains3rdOrder k_att_rm
struct guidance_indi_hybrid_params gih_params
float k_I
bool SpinQuad
Definition oneloop_nB.c:495
float delta_fault
Definition oneloop_nB.c:524
struct FloatEulers eulers_zxy_des
float max_push_cmd
Definition oneloop_nB.h:199
bool use_safety_killer
Definition oneloop_nB.c:512
struct PolePlacement p_att_rm
float g1g2_1l[ANDI_OUTPUTS][ANDI_NUM_ACT_TOT]
uint8_t spin_man_pair
Definition oneloop_nB.c:653
bool safety_killer_trigger
Definition oneloop_nB.c:513
struct FloatVect3 mu_B
Definition oneloop_nB.h:181
void guidance_set_max_bank_angle(float max_bank)
Guidance limit setters called by rotwing_state (also implemented by guidance_indi_hybrid).
float max_as
struct Gains3rdOrder k_att_e
float psi_des_rad
union LP_t::@275 meas_filt
bool vel_ctrl_in_manual
Definition oneloop_nB.c:511
void guidance_set_max_climb_speed(float max_climb_speed_quad, float max_climb_speed_fwd)
bool ctrl_off
struct Gains3rdOrder k_pos_e
bool use_push_Position
Definition oneloop_nB.c:508
float spin_prot_max_cmd
Definition oneloop_nB.c:541
float nu[ANDI_OUTPUTS]
struct FloatVect3 nB_2d
Definition oneloop_nB.h:174
struct Gains2ndOrder k_head_rm
float meas
struct FloatVect3 nB_3d
Definition oneloop_nB.h:175
float bandwidth
bool drop_yaw
float k_P
struct LP_t q_ddot
Definition oneloop_nB.h:282
#define ANDI_NUM_ACT
Definition oneloop_nB.h:40
float spin_trim_release_rate
Definition oneloop_nB.c:562
float meas_prev
void oneloop_from_nav(bool in_flight)
Function that maps navigation inputs to the oneloop controller for the generated autopilot.
float spin_trim_rate
Definition oneloop_nB.c:560
float tau
struct PolePlacement p_alt_rm
struct OneloopGuidanceRef gui_ref
struct FloatVect3 nI_des
Definition oneloop_nB.h:176
struct Gains2ndOrder k_head_e
struct LP_t ax
float safety_killer_cutoff
Definition oneloop_nB.c:516
struct OneloopStabilizationRef sta_ref
bool fault_roll_motors
Definition oneloop_nB.c:497
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
float andi_u[ANDI_NUM_ACT_TOT]
@ BUTTERWORTH_2
Definition oneloop_nB.h:254
@ BUTTERWORTH_4
Definition oneloop_nB.h:255
@ LOWPASS_1
Definition oneloop_nB.h:253
@ NOTCH
Definition oneloop_nB.h:256
bool oneloop_nB_Z_hold
Definition oneloop_nB.c:510
float fwd_sideslip_gain
struct PolePlacement p_att_e
struct PolePlacement p_alt_e
float max_bank
Definition oneloop_nB.c:264
float spin_man_r_ref
Definition oneloop_nB.c:660
float max_pusher_cmd
Definition oneloop_nB.c:518
struct OneloopStabilizationnBState sta_nB_state
Definition oneloop_nB.h:211
struct FloatVect3 nB_d
Definition oneloop_nB.h:173
float pid_v_max_nav
Definition oneloop_nB.c:641
struct PolePlacement p_head_e
float freq
bool use_push_PID
Definition oneloop_nB.c:507
struct LP_t r_dot
struct LP_t p_dot
float ec_k3
Definition oneloop_nB.c:622
#define ANDI_NUM_ACT_TOT
Definition oneloop_nB.h:51
float freq_set
float andi_du[ANDI_NUM_ACT_TOT]
bool heading_manual
struct LP_t p
float spin_trim_bleed_rate
Definition oneloop_nB.c:561
struct OneloopGeneral oneloop_nB
Definition oneloop_nB.c:114
float spin_man_pitch_dir
Definition oneloop_nB.c:654
float k_K
Definition oneloop_nB.c:700
uint8_t spin_man_state
Definition oneloop_nB.c:659
float pid_a_max
Definition oneloop_nB.c:639
float SpinQuadRate
Definition oneloop_nB.c:494
bool spin_man_up
Definition oneloop_nB.c:651
float k1_NE_tune
bool spin_man_down
Definition oneloop_nB.c:652
float out
struct FloatVect3 nI_d
Definition oneloop_nB.h:178
float spin_trim
Definition oneloop_nB.c:563
struct Gains3rdOrder k_pos_rm
void guidance_set_max_descend_speed(float max_descend_speed_quad, float max_descend_speed_fwd)
struct LP_t az
bool state_compensation_on
Definition oneloop_nB.c:506
struct LP_t q
float pid_v_max_manual
Definition oneloop_nB.c:640
void oneloop_nB_enter(bool half_loop_sp, int ctrl_type)
Function that resets important values upon engaging Oneloop ANDI.
float spin_man_done_rate
Definition oneloop_nB.c:658
float spin_man_ramp_rate
Definition oneloop_nB.c:655
float max_theta
Definition oneloop_nB.c:276
bool auto_fault_cmd
Definition oneloop_nB.c:514
enum FilterType filter_type
float psi_des_deg
struct LP_t p_ddot
Definition oneloop_nB.h:281
int8_t TestMotorIDX
Definition oneloop_nB.c:113
struct OneloopPushnB push_nB
Definition oneloop_nB.h:212
float gi_unbounded_airspeed_sp
void oneloop_nB_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
#define ANDI_OUTPUTS
Definition oneloop_nB.h:55
struct PolePlacement p_pos_rm
void oneloop_nB_set_failsafe_setpoint(void)
void oneloop_nB_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des)
Main function that runs the controller and performs control allocation.
bool yaw_stick_in_auto
float actuator_state_1l[ANDI_NUM_ACT_TOT]
float spin_man_trim_rate
Definition oneloop_nB.c:657
float act_state_filt_vect_1l[ANDI_NUM_ACT]
struct LP_t ay
struct Oneloop_LP_t LP
void oneloop_nB_RM(bool half_loop, struct FloatVect3 PSA_des, bool in_flight_oneloop)
Function to generate the reference signals for the oneloop controller.
float max_fault_mot
Definition oneloop_nB.c:314
struct LP_t q_dot
bool spin_trim_on
Definition oneloop_nB.c:559
float max_phi
Definition oneloop_nB.c:270
struct LP_t r
struct FloatVect3 nI_2d
Definition oneloop_nB.h:179
float spin_prot_max_rate
Definition oneloop_nB.c:539
float spin_prot_start_rate
Definition oneloop_nB.c:540
void oneloop_nB_init(void)
Init function of Oneloop ANDI controller
bool fault_pitch_motors
Definition oneloop_nB.c:496
struct LP_t r_ddot
Definition oneloop_nB.h:283
Paparazzi floating point algebra.
General stabilization interface for rotorcrafts.
Common data structures shared by euler and quaternion int implementations.
Rotorcraft attitude reference generation.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.