Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
eff_scheduling_rotwing.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Dennis van Wijngaarden <D.C.vanWijngaarden@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
27
28#include "generated/airframe.h"
29#include "state.h"
30
34#include "autopilot.h"
35
37#include "modules/core/abi.h"
38
39#ifndef SERVO_ROTATION_MECH_IDX
40#error ctrl_eff_sched_rotwing requires a servo named ROTATION_MECH_IDX
41#endif
42
43#ifndef ROTWING_EFF_SCHED_IXX_BODY
44#error "NO ROTWING_EFF_SCHED_IXX_BODY defined"
45#endif
46
47#ifndef ROTWING_EFF_SCHED_IYY_BODY
48#error "NO ROTWING_EFF_SCHED_IYY_BODY defined"
49#endif
50
51#ifndef ROTWING_EFF_SCHED_IZZ
52#error "NO ROTWING_EFF_SCHED_IZZ defined"
53#endif
54
55#ifndef ROTWING_EFF_SCHED_IXX_WING
56#error "NO ROTWING_EFF_SCHED_IXX_WING defined"
57#endif
58
59#ifndef ROTWING_EFF_SCHED_IYY_WING
60#error "NO ROTWING_EFF_SCHED_IYY_WING defined"
61#endif
62
63#ifndef ROTWING_EFF_SCHED_M
64#error "NO ROTWING_EFF_SCHED_M defined"
65#endif
66
67#ifndef ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_PITCH
68#error "NO ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_PITCH defined"
69#endif
70
71#ifndef ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_ROLL
72#error "NO ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_ROLL defined"
73#endif
74
75#ifndef ROTWING_EFF_SCHED_HOVER_ROLL_PITCH_COEF
76#error "NO ROTWING_EFF_SCHED_HOVER_ROLL_PITCH_COEF defined"
77#endif
78
79#ifndef ROTWING_EFF_SCHED_HOVER_ROLL_ROLL_COEF
80#error "NO ROTWING_EFF_SCHED_HOVER_ROLL_ROLL_COEF defined"
81#endif
82
83#ifndef ROTWING_EFF_SCHED_K_ELEVATOR
84#error "NO ROTWING_EFF_SCHED_K_ELEVATOR defined"
85#endif
86
87#ifndef ROTWING_EFF_SCHED_K_RUDDER
88#error "NO ROTWING_EFF_SCHED_K_RUDDER defined"
89#endif
90
91#ifndef ROTWING_EFF_SCHED_K_AILERON
92#error "NO ROTWING_EFF_SCHED_K_AILERON defined"
93#endif
94
95#ifndef ROTWING_EFF_SCHED_K_FLAPERON
96#error "NO ROTWING_EFF_SCHED_K_FLAPERON defined"
97#endif
98
99#ifndef ROTWING_EFF_SCHED_K_PUSHER
100#error "NO ROTWING_EFF_SCHED_K_PUSHER defined"
101#endif
102
103#ifndef ROTWING_EFF_SCHED_K_ELEVATOR_DEFLECTION
104#error "NO ROTWING_EFF_SCHED_K_ELEVATOR_DEFLECTION defined"
105#endif
106
107#ifndef ROTWING_EFF_SCHED_D_RUDDER_D_PPRZ
108#error "NO ROTWING_EFF_SCHED_D_RUDDER_D_PPRZ defined"
109#endif
110
111#ifndef ROTWING_EFF_SCHED_K_RPM_PPRZ_PUSHER
112#error "NO ROTWING_EFF_SCHED_K_RPM_PPRZ_PUSHER defined"
113#endif
114
115#ifndef ROTWING_EFF_SCHED_K_LIFT_WING
116#error "NO ROTWING_EFF_SCHED_K_LIFT_WING defined"
117#endif
118
119#ifndef ROTWING_EFF_SCHED_K_LIFT_FUSELAGE
120#error "NO ROTWING_EFF_SCHED_K_LIFT_FUSELAGE defined"
121#endif
122
123#ifndef ROTWING_EFF_SCHED_K_LIFT_TAIL
124#error "NO ROTWING_EFF_SCHED_K_LIFT_TAIL defined"
125#endif
126
129 .Iyy_body = ROTWING_EFF_SCHED_IYY_BODY,
131 .Ixx_wing = ROTWING_EFF_SCHED_IXX_WING,
132 .Iyy_wing = ROTWING_EFF_SCHED_IYY_WING,
134 .DMdpprz_hover_pitch = ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_PITCH,
135 .DMdpprz_hover_roll = ROTWING_EFF_SCHED_DM_DPPRZ_HOVER_ROLL,
136 .hover_roll_pitch_coef = ROTWING_EFF_SCHED_HOVER_ROLL_PITCH_COEF,
137 .hover_roll_roll_coef = ROTWING_EFF_SCHED_HOVER_ROLL_ROLL_COEF,
138 .k_elevator = ROTWING_EFF_SCHED_K_ELEVATOR,
139 .k_rudder = ROTWING_EFF_SCHED_K_RUDDER,
140 .k_aileron = ROTWING_EFF_SCHED_K_AILERON,
141 .k_flaperon = ROTWING_EFF_SCHED_K_FLAPERON,
142 .k_pusher = ROTWING_EFF_SCHED_K_PUSHER,
143 .k_elevator_deflection = ROTWING_EFF_SCHED_K_ELEVATOR_DEFLECTION,
144 .d_rudder_d_pprz = ROTWING_EFF_SCHED_D_RUDDER_D_PPRZ,
145 .k_rpm_pprz_pusher = ROTWING_EFF_SCHED_K_RPM_PPRZ_PUSHER,
146 .k_lift_wing = ROTWING_EFF_SCHED_K_LIFT_WING,
147 .k_lift_fuselage = ROTWING_EFF_SCHED_K_LIFT_FUSELAGE,
148 .k_lift_tail = ROTWING_EFF_SCHED_K_LIFT_TAIL
149};
150
152
153// for negative values, still should be low_lim < up_lim
154inline float bound_or_zero(float value, float low_lim, float up_lim) {
155 float output = value;
156 if (low_lim > 0.f) {
157 if (value < low_lim) {
158 output = 0.f;
159 } else if (value > up_lim) {
160 output = up_lim;
161 }
162 } else {
163 if (value > up_lim) {
164 output = 0.f;
165 } else if (value < low_lim) {
166 output = low_lim;
167 }
168 }
169 return output;
170}
171
173float roll_eff_slider = 12.f;
174
176
178
180inline void eff_scheduling_rotwing_update_MMOI(void);
181inline void eff_scheduling_rotwing_update_cmd(void);
190
191inline float guidance_indi_get_liftd(float pitch UNUSED, float theta UNUSED);
193inline void guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_angle, float pitch_angle);
194
195
198#ifndef WING_ROTATION_CAN_ROTWING_ID
199#define WING_ROTATION_CAN_ROTWING_ID ABI_BROADCAST
200#endif
203
205{
206 for (int i=0; i<num_act; i++){
207 if (pos_msg[i].set.position && (pos_msg[i].idx == SERVO_ROTATION_MECH_IDX))
208 {
209 // Get wing rotation angle from sensor
210 eff_sched_var.wing_rotation_rad = 0.5 * M_PI - pos_msg[i].position;
211
212 // Bound wing rotation angle
214 }
215 }
216}
217
219{
220 // Initialize variables to quad values
223 eff_sched_var.wing_rotation_rad = 0; // ABI input
230
231 // Set moment derivative variables
232 float hover_thrust = 6000;
233 eff_sched_var.pitch_motor_dMdpprz = (eff_sched_p.DMdpprz_hover_pitch[0] + 2*hover_thrust * eff_sched_p.DMdpprz_hover_pitch[1]) / 10000.; // Dmdpprz hover pitch for hover thrust
234 eff_sched_var.roll_motor_dMdpprz = (eff_sched_p.DMdpprz_hover_roll[0] + 2*hover_thrust * eff_sched_p.DMdpprz_hover_roll[1]) / 10000.; // Dmdpprz hover roll for hover thrust
235
240
243
244 // Get wing angle
246}
247
266
281
291
293{
294 // These indexes depend on the INDI sequence, not the actuator IDX
297 eff_sched_var.cmd_pusher_scaled = actuator_state_filt_vect[8] * 0.000853229; // Scaled with 8181 / 9600 / 1000
298 eff_sched_var.cmd_T_mean_scaled = (actuator_state_filt_vect[0] + actuator_state_filt_vect[1] + actuator_state_filt_vect[2] + actuator_state_filt_vect[3]) / 4. * 0.000853229; // Scaled with 8181 / 9600 / 1000
299}
300
308
310{
311 float cmd_quat[4];
312 float dM_dpprz[4];
313 // Quadratic thrust (and therefore moment) model of the hover propellers
314 for (uint8_t i = 0; i < 4; i++) {
316 Bound(cmd_quat[i], 2500, MAX_PPRZ);
317
318 if(i==0 || i==2) { // pitch motors
320 // Bound dM_dpprz to half and 2 times the hover effectiveness
322 } else { // roll motors
325 }
326 }
327
328 // Roll motor effectiveness
329 float dM_dpprz_right = dM_dpprz[1];
330 float dM_dpprz_left = dM_dpprz[3];;
331
334
336 if(autopilot.in_flight) {
339 }
341
343 Bound(roll_motor_q_eff, 0, 1);
344
345 // Update front pitch motor q effectiveness
346 g1g2[1][0] = dM_dpprz[0] / eff_sched_var.Iyy; // pitch effectiveness front motor
347
348 // Update back motor q effectiveness
349 g1g2[1][2] = -dM_dpprz[2] / eff_sched_var.Iyy; // pitch effectiveness back motor
350
351 g1g2[0][1] = roll_motor_p_eff_right; // roll effectiveness right motor (no airspeed compensation)
352 g1g2[1][1] = roll_motor_q_eff; // pitch effectiveness right motor
353
354 // Update left motor p and q effectiveness
355 g1g2[0][3] = roll_motor_p_eff_left; // roll effectiveness left motor
356 g1g2[1][3] = -roll_motor_q_eff; // pitch effectiveness left motor
357}
358
360{
362
366
367 // scale the effectiveness of the elevator down if it has a large deflection to encourage it to become flat quickly (pragmatic, not physically inpsired)
368 float elevator_ineffectiveness_scaling = (50-de)/40;
370
372
373 // Convert moment to effectiveness
375
376 Bound(eff_y_elev, 0.00001, 0.1);
377
378 g1g2[1][5] = eff_y_elev;
379}
380
382{
386
387 // Convert moment to effectiveness
388
390
391 // Convert moment to effectiveness
393
394 Bound(eff_z_rudder, 0.000001, 0.1);
395
396 g1g2[2][4] = eff_z_rudder;
397}
398
411
419
432
434
448
449// Override standard LIFT_D function
450float guidance_indi_get_liftd(float pitch UNUSED, float theta UNUSED) {
452}
453
455{
456 // Calculate the min and max increments
457 for (uint8_t i = 0; i < INDI_NUM_ACT; i++) {
460 wls_stab_p.u_pref[i] = act_pref[i];
461 if (i == 5) { // elevator
462 wls_stab_p.u_pref[i] = actuator_state_filt_vect[i]; // Set change in prefered state to 0 for elevator
463 wls_stab_p.u_min[i] = 0; // cmd 0 is lowest position for elevator
464 }
465 if (i == 7) { // flaperons
466 // If an offset is used, limit the max differential command to prevent unilateral saturation.
471 }
472 if (i==8) { // pusher
473 // dt (min to max) MAX_PPRZ / (dt * f) dt_min == 0.002
474 Bound(eff_sched_pusher_time, 0.002, 5.);
478
481 }
482 }
483}
484
485void guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_angle, float pitch_angle)
486{
487 // adjust weights
488 float fixed_wing_percentile = (rotwing_state_hover_motors_idling())? 1:0; // TODO: when hover props go below 40%, ...
490#define AIRSPEED_IMPORTANCE_IN_FORWARD_WEIGHT 16
491
493
494 // Increase importance of forward acceleration in forward flight
495 wls_guid_p.Wv[0] = Wv_original[0] * (1.0f + fixed_wing_percentile *
496 AIRSPEED_IMPORTANCE_IN_FORWARD_WEIGHT); // stall n low hover motor_off (weight 16x more important than vertical weight)
497
498 struct FloatEulers eulers_zxy;
500
504 Bound(du_min_thrust_z, -50., 0.);
507 Bound(du_max_thrust_z, 0., 50.);
508
512
514 float quad_pitch_limit_rad = RadOfDeg(5.0);
515
516 float airspeed = stateGetAirspeed_f();
517
518 float scheduled_pitch_angle = 0.f;
519 float pitch_angle_range = 3.;
521 Bound(meas_skew_angle, 0, 90); // Bound to prevent errors
524 wls_guid_p.Wu[1] = Wu_gih_original[1];
526 } else {
527 float pitch_progression = (airspeed - rotwing_state.fw_min_airspeed) / 2.f;
528 Bound(pitch_progression, 0.f, 1.f);
530 wls_guid_p.Wu[1] = Wu_gih_original[1] * (1.f - pitch_progression*0.99);
532 }
536 }
539
541
542 // Set lower limits
543 wls_guid_p.u_min[0] = -roll_limit_rad - roll_angle; //roll
544 wls_guid_p.u_min[1] = min_pitch_limit_rad - pitch_angle; // pitch
545
546 // Set upper limits limits
547 wls_guid_p.u_max[0] = roll_limit_rad - roll_angle; //roll
548 wls_guid_p.u_max[1] = max_pitch_limit_rad - pitch_angle; // pitch
549
551 wls_guid_p.u_min[2] = du_min_thrust_z;
552 wls_guid_p.u_max[2] = du_max_thrust_z;
553 } else {
554 wls_guid_p.u_min[2] = 0.;
555 wls_guid_p.u_max[2] = 0.;
556 }
557
559 wls_guid_p.u_min[3] = (-actuator_state_filt_vect[8] * g1g2[4][8]);
560 wls_guid_p.u_max[3] = 9.0; // Hacky value to prevent drone from pitching down in transition
561 } else {
562 wls_guid_p.u_min[3] = 0.;
563 wls_guid_p.u_max[3] = 0.;
564 }
565
566 // Set prefered states
567 wls_guid_p.u_pref[0] = 0; // prefered delta roll angle
568 wls_guid_p.u_pref[1] = -pitch_angle + pitch_pref_rad;// prefered delta pitch angle
569 wls_guid_p.u_pref[2] = wls_guid_p.u_max[2]; // Low thrust better for efficiency
570 wls_guid_p.u_pref[3] = body_v[0]; // solve the body acceleration
571}
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:67
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
Core autopilot interface common to all firmwares.
bool in_flight
in flight status
Definition autopilot.h:70
#define UNUSED(x)
void stabilization_indi_set_wls_settings(void)
Function that sets the u_min, u_max and u_pref if function not elsewhere defined.
void eff_scheduling_rotwing_update_flaperon_effectiveness(void)
void eff_scheduling_rotwing_update_rudder_effectiveness(void)
void eff_scheduling_rotwing_update_aileron_effectiveness(void)
float eff_scheduling_rotwing_lift_d
static const float Wu_gih_original[GUIDANCE_INDI_HYBRID_U]
struct rotwing_eff_sched_var_t eff_sched_var
void eff_scheduling_rotwing_update_MMOI(void)
#define WING_ROTATION_CAN_ROTWING_ID
ABI binding wing position data.
void eff_scheduling_rotwing_update_airspeed(void)
float roll_eff_slider
int32_t rw_flap_offset
void eff_scheduling_rotwing_update_cmd(void)
void eff_scheduling_rotwing_schedule_liftd(void)
float guidance_indi_get_liftd(float pitch UNUSED, float theta UNUSED)
#define AIRSPEED_IMPORTANCE_IN_FORWARD_WEIGHT
void eff_scheduling_rotwing_update_wing_angle(void)
struct rotwing_eff_sched_param_t eff_sched_p
void eff_scheduling_rotwing_update_hover_motor_effectiveness(void)
static abi_event wing_position_ev
void eff_scheduling_rotwing_init(void)
void eff_scheduling_rotwing_update_elevator_effectiveness(void)
float eff_sched_pusher_time
float bound_or_zero(float value, float low_lim, float up_lim)
void eff_scheduling_rotwing_update_pusher_effectiveness(void)
void eff_scheduling_rotwing_periodic(void)
static void wing_position_cb(uint8_t sender_id UNUSED, struct act_feedback_t *pos_msg, uint8_t num_act)
void guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_angle, float pitch_angle)
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
float guidance_indi_max_bank
float guidance_indi_pitch_pref_deg
struct FloatEulers eulers_zxy
state eulers in zxy order
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more!
#define GUIDANCE_INDI_MAX_PITCH
#define GUIDANCE_INDI_MIN_PITCH
uint16_t foo
Definition main_demo5.c:58
Hardware independent API for actuators (servos, motor controllers).
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
#define MAX_PPRZ
Definition paparazzi.h:8
bool rotwing_state_pusher_motor_running(void)
bool rotwing_state_hover_motors_running(void)
bool rotwing_state_hover_motors_idling(void)
Check if hover motors are idling (COMMAND_THRUST < ROTWING_QUAD_IDLE_MIN_THRUST) for ROTWING_QUAD_IDL...
struct rotwing_state_t rotwing_state
#define ROTWING_QUAD_PREF_PITCH
float meas_skew_angle_deg
#define ROTWING_SKEW_ANGLE_STEP
float act_pref[INDI_NUM_ACT]
bool act_is_servo[INDI_NUM_ACT]
struct WLS_t wls_stab_p
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
float actuator_state_filt_vect[INDI_NUM_ACT]
API to get/set the generic vehicle states.
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float u_min[WLS_N_U_MAX]
Definition wls_alloc.h:75
float u_max[WLS_N_U_MAX]
Definition wls_alloc.h:76
float u_pref[WLS_N_U_MAX]
Definition wls_alloc.h:74