Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
guidance_indi_hybrid.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Ewoud Smeur <ewoud.smeur@gmail.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, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
30#include "generated/airframe.h"
34#include "state.h"
35#include "mcu_periph/sys_time.h"
36#include "autopilot.h"
37#include "stdio.h"
41#include "modules/core/abi.h"
43
44
45// The acceleration reference is calculated with these gains. If you use GPS,
46// they are probably limited by the update rate of your GPS. The default
47// values are tuned for 4 Hz GPS updates. If you have high speed position updates, the
48// gains can be higher, depending on the speed of the inner loop.
49#ifndef GUIDANCE_INDI_SPEED_GAIN
50#define GUIDANCE_INDI_SPEED_GAIN 1.8
51#define GUIDANCE_INDI_SPEED_GAINZ 1.8
52#endif
53
54#ifndef GUIDANCE_INDI_POS_GAIN
55#define GUIDANCE_INDI_POS_GAIN 0.5
56#define GUIDANCE_INDI_POS_GAINZ 0.5
57#endif
58
59#ifndef GUIDANCE_INDI_LIFTD_ASQ
60#define GUIDANCE_INDI_LIFTD_ASQ 0.20
61#endif
62
63#ifndef GUIDANCE_INDI_MAX_PUSHER_INCREMENT
64#define GUIDANCE_INDI_MAX_PUSHER_INCREMENT MAX_PPRZ
65#endif
66
67/* If lift effectiveness at low airspeed not defined,
68 * just make one interpolation segment that connects to
69 * the quadratic part from 12 m/s onward
70 */
71#ifndef GUIDANCE_INDI_LIFTD_P50
72#define GUIDANCE_INDI_LIFTD_P80 (GUIDANCE_INDI_LIFTD_ASQ*12*12)
73#define GUIDANCE_INDI_LIFTD_P50 (GUIDANCE_INDI_LIFTD_P80/2)
74#endif
75
76#ifndef GUIDANCE_INDI_MAX_AIRSPEED
77#error "You must have an airspeed sensor to use this guidance"
78#endif
79
80#ifndef GUIDANCE_INDI_MIN_AIRSPEED
81#define GUIDANCE_INDI_MIN_AIRSPEED -10.f
82#endif
83
87#ifndef GUIDANCE_INDI_FWD_CLIMB_SPEED
88#define GUIDANCE_INDI_FWD_CLIMB_SPEED 4.0
89#endif
90
94#ifndef GUIDANCE_INDI_FWD_DESCEND_SPEED
95#define GUIDANCE_INDI_FWD_DESCEND_SPEED -4.0
96#endif
97
101#ifndef GUIDANCE_INDI_QUAD_CLIMB_SPEED
102#define GUIDANCE_INDI_QUAD_CLIMB_SPEED 2.0
103#endif
104
108#ifndef GUIDANCE_INDI_QUAD_DESCEND_SPEED
109#define GUIDANCE_INDI_QUAD_DESCEND_SPEED -2.0
110#endif
111
114 .pos_gainz = GUIDANCE_INDI_POS_GAINZ,
115
116 .speed_gain = GUIDANCE_INDI_SPEED_GAIN,
117 .speed_gainz = GUIDANCE_INDI_SPEED_GAINZ,
118
119 .heading_bank_gain = GUIDANCE_INDI_HEADING_BANK_GAIN,
120 .liftd_asq = GUIDANCE_INDI_LIFTD_ASQ, // coefficient of airspeed squared
121 .liftd_p80 = GUIDANCE_INDI_LIFTD_P80,
122 .liftd_p50 = GUIDANCE_INDI_LIFTD_P50,
123 .min_airspeed = GUIDANCE_INDI_MIN_AIRSPEED,
124 .max_airspeed = GUIDANCE_INDI_MAX_AIRSPEED,
125 .stall_protect_gain = 1.5, // m/s^2 downward acceleration per m/s airspeed loss
126 .climb_vspeed_fwd = GUIDANCE_INDI_FWD_CLIMB_SPEED,
127 .descend_vspeed_fwd = GUIDANCE_INDI_FWD_DESCEND_SPEED,
128 .climb_vspeed_quad = GUIDANCE_INDI_QUAD_CLIMB_SPEED,
129 .descend_vspeed_quad = GUIDANCE_INDI_QUAD_DESCEND_SPEED,
130};
131
132// Quadplanes can hover at various pref pitch
134
135
136// If using WLS, check that the matrix size is sufficient
137#if GUIDANCE_INDI_HYBRID_USE_WLS
138#if GUIDANCE_INDI_HYBRID_U > WLS_N_U_MAX
139#error Matrix-WLS_N_U_MAX too small: increase WLS_N_U_MAX in airframe file
140#endif
141
142#if GUIDANCE_INDI_HYBRID_V > WLS_N_V_MAX
143#error Matrix-WLS_N_V_MAX too small: increase WLS_N_V_MAX in airframe file
144#endif
145#endif
146
147// Default WLS priorities on control objectives (e.g. ax, ay, and az)
148#ifndef GUIDANCE_INDI_WLS_PRIORITIES
149#define GUIDANCE_INDI_WLS_PRIORITIES { 100.f, 100.f, 1.f }
150#endif
151
152// Weighting of outputs in the cost function (depends on the type of plateform)
153#ifndef GUIDANCE_INDI_WLS_WU
154#define GUIDANCE_INDI_WLS_WU {[0 ... GUIDANCE_INDI_HYBRID_U - 1] = 1.0}
155#endif
156
157// Tell the guidance that the airspeed needs to be zeroed.
158// Recomended to also put GUIDANCE_INDI_NAV_SPEED_MARGIN low in this case.
159#ifndef GUIDANCE_INDI_ZERO_AIRSPEED
160#define GUIDANCE_INDI_ZERO_AIRSPEED FALSE
161#endif
162
163/*Airspeed threshold where making a turn is "worth it"*/
164#ifndef TURN_AIRSPEED_TH
165#define TURN_AIRSPEED_TH 13.0
166#endif
167
168/*Boolean to force the heading to a static value (only use for specific experiments)*/
170
171bool force_forward = false;
172
174
175
176struct FloatVect3 sp_accel = {0.0,0.0,0.0};
177
178#ifndef GUIDANCE_INDI_FILTER_CUTOFF
179#ifdef STABILIZATION_INDI_FILT_CUTOFF
180#define GUIDANCE_INDI_FILTER_CUTOFF STABILIZATION_INDI_FILT_CUTOFF
181#else
182#define GUIDANCE_INDI_FILTER_CUTOFF 3.0
183#endif
184#endif
185
186#ifndef GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
187#define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF 0.5
188#endif
189
190#ifndef GUIDANCE_INDI_MAX_LAT_ACCEL
191#define GUIDANCE_INDI_MAX_LAT_ACCEL 9.81
192#endif
193
194#ifndef GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED
195#define GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED 10.0
196#endif
197
198#ifndef GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED
199#define GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED 30.0
200#endif
201
202#ifndef GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN
203#define GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN 0.0
204#endif
205
206float inv_eff[4];
207
208// Max bank angle in radians
211
212#if defined(ROTWING_STATE_FW_MAX_AIRSPEED) && defined(ROTWING_STATE_QUAD_MAX_AIRSPEED)
215#else
218#endif
219
221
224
229
230#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
231float thrust_dyn = 0.f;
232float thrust_act = 0.f;
235static void guidance_indi_filter_thrust(void);
236
237#ifndef GUIDANCE_INDI_THRUST_DYNAMICS_FREQ
238#ifndef STABILIZATION_INDI_ACT_FREQ_P
239#error "You need to define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ to be able to use indi vertical control"
240#else // assume that the same actuators are used for thrust as for roll (e.g. quadrotor)
241#define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ STABILIZATION_INDI_ACT_FREQ_P
242#endif
243#endif //GUIDANCE_INDI_THRUST_DYNAMICS_FREQ
244
245#endif //GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
246
249
252
253float du_gih[GUIDANCE_INDI_HYBRID_U]; // = {0.0f, 0.0f, 0.0f};
254
255#if GUIDANCE_INDI_HYBRID_USE_WLS
256#include "math/wls/wls_alloc.h"
258struct WLS_t wls_guid_p = {
261 .gamma_sq = 100000.0,
262 .v = {0.0},
265 .u_pref = {0.0},
266 .u_min = {0.0},
267 .u_max = {0.0},
268 .PC = 0.0,
269 .SC = 0.0,
270 .iter = 0
271};
272#endif
273// The control objective
274float v_gih[3];
275
276// Filters
279
284
285struct FloatVect3 gi_speed_sp = {0.0, 0.0, 0.0};
286
287#ifndef GUIDANCE_INDI_VEL_SP_ID
288#define GUIDANCE_INDI_VEL_SP_ID ABI_BROADCAST
289#endif
291static void vel_sp_cb(uint8_t sender_id, struct FloatVect3 *vel_sp);
292struct FloatVect3 indi_vel_sp = {0.0, 0.0, 0.0};
293float time_of_vel_sp = 0.0;
294
295static void guidance_indi_init_filters(struct FloatEulers *eulers);
296static void guidance_indi_propagate_filters(void);
297
298#if PERIODIC_TELEMETRY
324
325#if GUIDANCE_INDI_HYBRID_USE_WLS
326static void send_wls_v_guid(struct transport_tx *trans, struct link_device *dev)
327{
328 send_wls_v("guid", &wls_guid_p, trans, dev);
329}
330static void send_wls_u_guid(struct transport_tx *trans, struct link_device *dev)
331{
332 send_wls_u("guid", &wls_guid_p, trans, dev);
333}
334#endif // GUIDANCE_INDI_HYBRID_USE_WLS
335
336#endif // PERIODIC_TELEMETRY
337
342{
343 /*AbiBindMsgACCEL_SP(GUIDANCE_INDI_ACCEL_SP_ID, &accel_sp_ev, accel_sp_cb);*/
345
346#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
348#endif
349
350 struct FloatEulers zero = {0.f, 0.f, 0.f};
352
353#if GUIDANCE_INDI_HYBRID_USE_WLS
354 for (int8_t i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
355 Bwls_gih[i] = Ga[i];
356 }
357#endif
358
359#if PERIODIC_TELEMETRY
362#if GUIDANCE_INDI_HYBRID_USE_WLS
365#endif
366#endif
367}
368
374{
375 /* Obtain eulers with zxy rotation order*/
379 // reset filters
381}
382
383void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed) {
384 gih_params.min_airspeed = min_airspeed;
386}
387
391
396
401
410{
411 // set global accel sp variable FIXME clean this
413
414 /* Obtain eulers with zxy rotation order */
418
419 /* Calculate the transition ratio so that the ctrl_effecitveness scheduling works */
422
423 // filter accel to get rid of noise and filter attitude to synchronize with accel
425
426 struct FloatVect3 a_diff;
428 VECT3_DIFF(a_diff, sp_accel, accel_filt);
429
430 // Bound the acceleration error so that the linearization still holds
431 Bound(a_diff.x, -6.0, 6.0);
432 Bound(a_diff.y, -6.0, 6.0);
433 Bound(a_diff.z, -9.0, 9.0);
434
435 // If the thrust to specific force ratio has been defined, include vertical control
436 // else ignore the vertical acceleration error
437#ifndef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
438#ifndef STABILIZATION_ATTITUDE_INDI_FULL
439 a_diff.z = 0.0;
440#endif
441#endif
442
443 // Calculate matrix of partial derivatives and control objective
445
446#if GUIDANCE_INDI_HYBRID_USE_WLS
447
448 // Calculate the maximum deflections
450
452
453 for (int i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
454 wls_guid_p.v[i] = v_gih[i];
455 }
456 wls_alloc(&wls_guid_p, Bwls_gih, 0, 0, 10);
457 for (int i = 0; i < GUIDANCE_INDI_HYBRID_U; i++) {
458 du_gih[i] = wls_guid_p.u[i];
459 }
460 euler_cmd.x = du_gih[0];
461 euler_cmd.y = du_gih[1];
462 euler_cmd.z = du_gih[2];
463
464#else
465 // compute inverse matrix of Ga
466 float Ga_inv[3][3] = {};
468 // Calculate roll,pitch and thrust command
470#endif
471
472 // Coordinated turn
473 // feedforward estimate angular rotation omega = g*tan(phi)/v
474 float omega;
475 const float max_phi = RadOfDeg(60.0f);
476#if GUIDANCE_INDI_ZERO_AIRSPEED
477 float airspeed_turn = 0.f;
478#else
480#endif
481 // We are dividing by the airspeed, so a lower bound is important
483
484 // Update roll and pitch setpoint
487
488 // Bound euler angles to prevent flipping
491
492 // Use the current roll angle to determine the corresponding heading rate of change.
494
495 // When tilting backwards (e.g. waypoint behind the drone), we have to yaw around to face the direction
496 // of flight even when the drone is not rolling much (yet). Determine the shortest direction in which to yaw by
497 // looking at the roll angle.
498 if ((eulers_zxy.theta > 0.0f) && (fabsf(eulers_zxy.phi) < eulers_zxy.theta)) {
499 if (eulers_zxy.phi > 0.0f) {
501 } else {
503 }
504 }
505
507 omega = 9.81f / airspeed_turn * tanf(coordinated_turn_roll);
508 } else { //max 60 degrees roll
509 omega = 9.81f / airspeed_turn * 1.72305f * ((coordinated_turn_roll > 0.0f) - (coordinated_turn_roll < 0.0f));
510 }
511
512#ifdef FWD_SIDESLIP_GAIN
513 // Add sideslip correction
514 omega -= accely_filt.o[0]*FWD_SIDESLIP_GAIN;
515#endif
516
517 // We can pre-compute the required rates to achieve this turn rate:
518 // NOTE: there *should* not be any problems possible with Euler singularities here
520 struct FloatRates ff_rates;
521 ff_rates.p = -sinf(euler_zyx->theta) * omega;
522 ff_rates.q = cosf(euler_zyx->theta) * sinf(euler_zyx->phi) * omega;
523 ff_rates.r = cosf(euler_zyx->theta) * cosf(euler_zyx->phi) * omega;
524
525 // For a hybrid it is important to reduce the sideslip, which is done by changing the heading.
526 // For experiments, it is possible to fix the heading to a different value.
528 // heading is fixed by nav
529 guidance_euler_cmd.psi = heading_sp;
530 }
531 else {
532 // heading is free and controlled by guidance
535 // limit heading setpoint to be within bounds of current heading
536#ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
541 if (delta_psi > delta_limit) {
543 } else if (delta_psi < -delta_limit) {
545 }
547#endif
549 }
550
551
552 // compute required thrust setpoint
553#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
555 // Add the increment in specific force * specific_force_to_thrust_gain to the filtered thrust
558 // return required thrust
560
561#else
562 float thrust_vect[3];
563#if GUIDANCE_INDI_HYBRID_U > 3
564 thrust_vect[0] = du_gih[3];
567 }
568#else
569 thrust_vect[0] = 0;
570#endif
571 thrust_vect[1] = 0;
573 // specific force not defined, return required increment
575#endif
576
577 // Set the quaternion setpoint from eulers_zxy
578 struct FloatQuat sp_quat;
581
583}
584
585// compute accel setpoint from speed setpoint
587{
588 struct FloatVect3 accel_sp = { 0.f, 0.f, 0.f };
589
591
592 //for rc control horizontal, rotate from body axes to NED
593 float psi = eulers_zxy.psi;
594 float cpsi = cosf(psi);
595 float spsi = sinf(psi);
596 float speed_sp_b_x = cpsi * speed_sp->x + spsi * speed_sp->y;
597 float speed_sp_b_y = -spsi * speed_sp->x + cpsi * speed_sp->y;
598
599 // Get airspeed or zero it
600#if GUIDANCE_INDI_ZERO_AIRSPEED
601 float airspeed = 0.f;
602#else
603 float airspeed = stateGetAirspeed_f();
604 Bound(airspeed, 0.0f, 100.0f);
606 airspeed = guidance_indi_airspeed_filt.o[0];
607 }
608#endif
610 struct FloatVect2 airspeed_v = { cpsi * airspeed, spsi * airspeed };
611 struct FloatVect2 windspeed;
613
614 VECT2_DIFF(desired_airspeed, *speed_sp, windspeed); // Use 2d part of speed_sp
616
618
619 // Check if some minimum airspeed is desired (e.g. to prevent stall)
622 }
623
625
626 // Make turn instead of straight line, control airspeed
627 if ((airspeed > TURN_AIRSPEED_TH) && (norm_des_as > (TURN_AIRSPEED_TH+2.0f))) {
628
629 // Give the wind cancellation priority.
631 float groundspeed_factor = 0.0f;
632
633 // if the wind is faster than we can fly, just fly in the wind direction
635 float av = speed_sp->x * speed_sp->x + speed_sp->y * speed_sp->y;
636 float bv = -2.f * (windspeed.x * speed_sp->x + windspeed.y * speed_sp->y);
638
639 float dv = bv * bv - 4.0f * av * cv;
640
641 // dv can only be positive, but just in case
642 if (dv < 0.0f) {
643 dv = fabsf(dv);
644 }
645 float d_sqrt = sqrtf(dv);
646
647 groundspeed_factor = (-bv + d_sqrt) / (2.0f * av);
648 }
649
652
654 }
655
656 if (force_forward) {
658 }
659
660 // Calculate accel sp in body axes, because we need to regulate airspeed
661 struct FloatVect2 sp_accel_b;
662 // In turn acceleration proportional to heading diff
666
668
669 // Control the airspeed
671
672 accel_sp.x = cpsi * sp_accel_b.x - spsi * sp_accel_b.y;
673 accel_sp.y = spsi * sp_accel_b.x + cpsi * sp_accel_b.y;
675 }
676 else { // Go somewhere in the shortest way
677
678 if (airspeed > 10.f) {
679 // Groundspeed vector in body frame
680 float groundspeed_x = cpsi * stateGetSpeedNed_f()->x + spsi * stateGetSpeedNed_f()->y;
682
683 // limit groundspeed setpoint to max_airspeed + (diff gs and airspeed)
684 if ((speed_increment + airspeed) > gih_params.max_airspeed) {
686 }
687 }
688
689 float speed_sp_x = cpsi * speed_sp_b_x - spsi * speed_sp_b_y;
690 float speed_sp_y = spsi * speed_sp_b_x + cpsi * speed_sp_b_y;
691
695 }
696
697 // Bound the acceleration setpoint
698 float accelbound = 3.0f + airspeed / gih_params.max_airspeed * 5.0f; // FIXME remove hard coded values
700 BoundAbs(accel_sp.z, 3.0);
701
702#ifdef ROTWING_FW_MIN_AIRSPEED
705 BoundAbs(accel_sp.z, 5.0);
706 }
707#endif
708
709 return accel_sp;
710}
711
712static float bound_vz_sp(float vz_sp)
713{
714 // Bound vertical speed setpoint
717 } else {
719 }
720 return vz_sp;
721}
722
724{
725 struct FloatVect3 pos_err = { 0 };
726 struct FloatVect3 accel_sp = { 0 };
727
729 //Linear controller to find the acceleration setpoint from position and velocity
737 } else if (v_mode == GUIDANCE_INDI_HYBRID_V_SPEED) {
739 } else {
740 gi_speed_sp.z = 0.f;
741 }
742 accel_sp = compute_accel_from_speed_sp(&gi_speed_sp); // compute accel sp
744 accel_sp.z = (gi_speed_sp.z - stateGetSpeedNed_f()->z) * gih_params.speed_gainz + ACCEL_FLOAT_OF_BFP(gv->zdd_ref); // overwrite accel
745 }
746 }
748 gi_speed_sp.x = SPEED_FLOAT_OF_BFP(gh->ref.speed.x);
749 gi_speed_sp.y = SPEED_FLOAT_OF_BFP(gh->ref.speed.y);
753 } else if (v_mode == GUIDANCE_INDI_HYBRID_V_SPEED) {
755 } else {
756 gi_speed_sp.z = 0.f;
757 }
758 accel_sp = compute_accel_from_speed_sp(&gi_speed_sp); // compute accel sp
760 accel_sp.z = (gi_speed_sp.z - stateGetSpeedNed_f()->z) * gih_params.speed_gainz + ACCEL_FLOAT_OF_BFP(gv->zdd_ref); // overwrite accel
761 }
762 }
763 else { // H_ACCEL
764 gi_speed_sp.x = 0.f;
765 gi_speed_sp.y = 0.f;
769 } else if (v_mode == GUIDANCE_INDI_HYBRID_V_SPEED) {
771 } else {
772 gi_speed_sp.z = 0.f;
773 }
774 accel_sp = compute_accel_from_speed_sp(&gi_speed_sp); // compute accel sp in case z control is required
775 // overwrite accel X and Y
779 accel_sp.z = (gi_speed_sp.z - stateGetSpeedNed_f()->z) * gih_params.speed_gainz + ACCEL_FLOAT_OF_BFP(gv->zdd_ref); // overwrite accel
780 }
781 }
782 return accel_sp;
783}
784
786{
787 struct FloatVect3 accel_sp = { 0 };
788
789 // First check for velocity setpoint from module // FIXME should be called like this
790 float dt = get_sys_time_float() - time_of_vel_sp;
791 // If the input command is not updated after a timeout, switch back to flight plan control
792 if (dt < 0.5) {
796 accel_sp = compute_accel_from_speed_sp(&gi_speed_sp); // compute accel sp
797 }
798 else {
800 }
801
802 return guidance_indi_run(&accel_sp, gh->sp.heading);
803}
804
829
849
850#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
855{
856 // Actuator dynamics
858
859 // same filter as for the acceleration
861}
862#endif
863
871float WEAK guidance_indi_get_liftd(float airspeed, float theta) {
872 float liftd = 0.0f;
873
874 if (airspeed < 12.f) {
875 /* Assume the airspeed is too low to be measured accurately
876 * Use scheduling based on pitch angle instead.
877 * You can define two interpolation segments
878 */
879 float pitch_interp = DegOfRad(theta);
880 const float min_pitch = -80.0f;
881 const float middle_pitch = -50.0f;
882 const float max_pitch = -20.0f;
883
886 float ratio = (pitch_interp - max_pitch)/(middle_pitch - max_pitch);
887 liftd = -gih_params.liftd_p50*ratio;
888 } else {
889 float ratio = (pitch_interp - middle_pitch)/(min_pitch - middle_pitch);
891 }
892 } else {
893 liftd = -gih_params.liftd_asq*airspeed*airspeed;
894 }
895
896 //TODO: bound liftd
897 return liftd;
898}
899
904{
905 indi_vel_sp.x = vel_sp->x;
906 indi_vel_sp.y = vel_sp->y;
907 indi_vel_sp.z = vel_sp->z;
909}
910
911
912#if GUIDANCE_INDI_HYBRID_USE_AS_DEFAULT
913// guidance indi control function is implementing the default functions of guidance
914
915void guidance_h_run_enter(void)
916{
918}
919
920void guidance_v_run_enter(void)
921{
922 // nothing to do
923}
924
925static struct VerticalGuidance *_gv = &guidance_v;
927
929{
931}
932
934{
936}
937
939{
941}
942
944{
945 _gv = gv;
947 return thrust_sp;
948}
949
951{
952 _gv = gv;
954 return thrust_sp;
955}
956
958{
959 _gv = gv;
961 return thrust_sp;
962}
963
964#endif
965
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
Core autopilot interface common to all firmwares.
#define UNUSED(x)
static struct uart_periph * dev
float phi
in radians
float p
in rad/s
float theta
in radians
float psi
in radians
static void float_quat_normalize(struct FloatQuat *q)
#define FLOAT_ANGLE_NORMALIZE(_a)
void float_eulers_of_quat_zxy(struct FloatEulers *e, const struct FloatQuat *q)
euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
void float_mat3_mult(struct FloatVect3 *vect_out, const float mat[3][3], const struct FloatVect3 vect_in)
Multiply 3D matrix with vector.
bool float_mat_inv_3d(float inv_out[3][3], const float mat_in[3][3])
3x3 matrix inverse
void float_quat_of_eulers_zxy(struct FloatQuat *q, const struct FloatEulers *e)
quat from euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
void float_vect3_bound_in_2d(struct FloatVect3 *vect3, const float bound)
#define FLOAT_VECT2_NORM(_v)
euler angles
Roation quaternion.
angular rates
#define VECT2_DIFF(_c, _a, _b)
#define VECT3_DIFF(_c, _a, _b)
#define POS_FLOAT_OF_BFP(_ai)
#define SPEED_FLOAT_OF_BFP(_ai)
#define ACCEL_FLOAT_OF_BFP(_ai)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition state.h:1203
static struct FloatEulers * stateGetNedToBodyEulersZxy_f(void)
Get vehicle body attitude ZXY euler angles (float).
Definition state.h:1320
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1314
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
Definition state.h:1302
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
Definition state.h:839
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Definition state.h:1049
static struct Int32Vect3 * stateGetAccelBody_i(void)
Get acceleration in Body coordinates (int).
Definition state.h:1094
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition state.h:1604
int32_t max_airspeed
struct FloatVect3 speed_sp
float thrust_act
struct FloatMat33 Ga_inv
float thrust_vect[3]
float thrust_dyn
Butterworth2LowPass thrust_filt
float guidance_indi_specific_force_gain
struct Butterworth2LowPassVect3 filt_accel_ned
struct FloatVect3 indi_vel_sp
#define GUIDANCE_INDI_WLS_WU
bool force_forward
forward flight for hybrid nav
QuatButterworthLowPass quat_filt
#define GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN
Butterworth2LowPass accely_filt
static void vel_sp_cb(uint8_t sender_id, struct FloatVect3 *vel_sp)
ABI callback that obtains the velocity setpoint from a module.
float time_of_vel_sp
#define GUIDANCE_INDI_QUAD_DESCEND_SPEED
Descend speed when navigation is doing direct lines.
#define GUIDANCE_INDI_SPEED_GAINZ
#define GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED
struct guidance_indi_hybrid_params gih_params
float thrust_in
#define GUIDANCE_INDI_MAX_LAT_ACCEL
struct FloatVect3 gi_speed_sp
float guidance_indi_min_pitch
float guidance_indi_max_bank
#define GUIDANCE_INDI_MIN_AIRSPEED
float gih_coordinated_turn_min_airspeed
struct StabilizationSetpoint guidance_indi_run_mode(bool in_flight UNUSED, struct HorizontalGuidance *gh, struct VerticalGuidance *gv, enum GuidanceIndiHybrid_HMode h_mode, enum GuidanceIndiHybrid_VMode v_mode)
void guidance_set_max_bank_angle(float max_bank)
float inv_eff[4]
static void guidance_indi_init_filters(struct FloatEulers *eulers)
Initialized low pass filters.
#define GUIDANCE_INDI_FWD_DESCEND_SPEED
Descend speed when navigation is making turns instead of direct lines.
void guidance_set_max_climb_speed(float max_climb_speed_quad, float max_climb_speed_fwd)
float gih_coordinated_turn_max_airspeed
struct FloatVect3 sp_accel
struct FloatEulers guidance_euler_cmd
float guidance_indi_pitch_pref_deg
#define GUIDANCE_INDI_LIFTD_ASQ
#define GUIDANCE_INDI_QUAD_CLIMB_SPEED
Climb speed when navigation is doing direct lines.
float guidance_indi_airspeed_filt_cutoff
void guidance_indi_enter(void)
Call upon entering indi guidance.
Butterworth2LowPass guidance_indi_airspeed_filt
#define GUIDANCE_INDI_POS_GAIN
#define GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED
#define GUIDANCE_INDI_FWD_CLIMB_SPEED
Climb speed when navigation is making turns instead of direct lines.
bool take_heading_control
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
struct FloatVect3 WEAK guidance_indi_controller(bool in_flight UNUSED, struct HorizontalGuidance *gh, struct VerticalGuidance *gv, enum GuidanceIndiHybrid_HMode h_mode, enum GuidanceIndiHybrid_VMode v_mode)
float guidance_indi_hybrid_heading_sp
float WEAK guidance_indi_get_liftd(float airspeed, float theta)
Get the derivative of lift w.r.t.
struct ThrustSetpoint thrust_sp
#define GUIDANCE_INDI_LIFTD_P50
static void send_guidance_indi_hybrid(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_INDI_WLS_PRIORITIES
void guidance_indi_init(void)
Init function.
float filter_cutoff
#define GUIDANCE_INDI_FILTER_CUTOFF
void guidance_set_max_descend_speed(float max_descend_speed_quad, float max_descend_speed_fwd)
#define GUIDANCE_INDI_MAX_PUSHER_INCREMENT
float Ga[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U]
struct FloatVect3 euler_cmd
static float bound_vz_sp(float vz_sp)
struct FloatEulers eulers_zxy
state eulers in zxy order
float gi_unbounded_airspeed_sp
#define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
#define GUIDANCE_INDI_POS_GAINZ
#define TURN_AIRSPEED_TH
static void send_eff_mat_guid_indi_hybrid(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_INDI_VEL_SP_ID
struct StabilizationSetpoint guidance_indi_run(struct FloatVect3 *accel_sp, float heading_sp)
bool coordinated_turn_use_accel
float v_gih[3]
static void guidance_indi_propagate_filters(void)
Low pass the accelerometer measurements to remove noise from vibrations.
bool guidance_indi_airspeed_filtering
#define GUIDANCE_INDI_LIFTD_P80
abi_event vel_sp_ev
static struct FloatVect3 compute_accel_from_speed_sp(struct FloatVect3 *speed_sp)
#define GUIDANCE_INDI_SPEED_GAIN
float du_gih[GUIDANCE_INDI_HYBRID_U]
struct FloatVect2 desired_airspeed
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more!
void guidance_indi_calcg_wing(float Gmat[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U], struct FloatVect3 a_diff, float v_body[GUIDANCE_INDI_HYBRID_V])
Perform WLS.
GuidanceIndiHybrid_VMode
@ GUIDANCE_INDI_HYBRID_V_POS
@ GUIDANCE_INDI_HYBRID_V_SPEED
@ GUIDANCE_INDI_HYBRID_V_ACCEL
GuidanceIndiHybrid_HMode
@ GUIDANCE_INDI_HYBRID_H_SPEED
@ GUIDANCE_INDI_HYBRID_H_ACCEL
@ GUIDANCE_INDI_HYBRID_H_POS
void WEAK guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_angle, float pitch_angle)
#define GUIDANCE_INDI_MAX_PITCH
#define GUIDANCE_INDI_MIN_PITCH
static enum GuidanceOneloop_VMode _v_mode
void guidance_v_run_enter(void)
static struct VerticalGuidance * _gv
struct ThrustSetpoint guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
Simple first order low pass filter with bilinear transform.
float o[2]
output history
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, const float tau, const float sample_time, const float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, const float value)
Update second order Butterworth low pass filter state with a new value.
Second order low pass filter structure.
Definitions and inline functions for 1st order low-pass filter vector types.
static struct FloatVect3 get_butterworth_2_low_pass_vect3(const struct Butterworth2LowPassVect3 *filter)
Retrieve the filtered output from 3D vector Butterworth filters.
static void init_butterworth_2_low_pass_vect3(struct Butterworth2LowPassVect3 *filter, const struct FloatVect3 *omega, const float dt)
Initialize a set of Butterworth low-pass filters to zero for 3D vector data.
static struct FloatVect3 update_butterworth_2_low_pass_vect3(struct Butterworth2LowPassVect3 *filter, const struct FloatVect3 *input)
Update 3D vector Butterworth filters with new input data.
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
float z
in meters
float x
in meters
float y
in meters
vector in North East Down coordinates Units: meters
Quaternion second order filter.
static struct FloatQuat update_quat_butterworth_low_pass(QuatButterworthLowPass *filter, const struct FloatQuat quat)
Update second order quaternion Butterworth low pass filter state with a new value.
static void init_quat_butterworth_low_pass(QuatButterworthLowPass *filter, const float omega, const float sample_time, const struct FloatQuat q0)
Init a second order quaternion Butterworth filter.
Quaternion second order filter model (float)
Generic interface for radio control modules.
Some helper functions to check RC sticks.
void guidance_h_run_enter(void)
struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
#define GUIDANCE_H_MAX_BANK
Max bank controlled by guidance.
Definition guidance_h.h:64
struct VerticalGuidance guidance_v
Definition guidance_v.c:60
struct RotorcraftNavigation nav
Definition navigation.c:51
Rotorcraft navigation functions.
float heading
heading setpoint (in radians)
Definition navigation.h:133
bool rotwing_state_pusher_motor_running(void)
bool rotwing_state_hover_motors_running(void)
struct Stabilization stabilization
struct ThrustSetpoint th_sp_from_incr_vect_f(float th_increment[3])
struct StabilizationSetpoint stab_sp_from_quat_ff_rates_f(struct FloatQuat *quat, struct FloatRates *rates)
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
#define THRUST_AXIS_Z
float transition_ratio
transition percentage for hybrids (0.: hover; 1.: forward)
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
float stabilization_attitude_get_heading_f(void)
Get attitude heading as float (avoiding jumps)
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
API to get/set the generic vehicle states.
Stabilization setpoint.
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:168
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.
float heading
Definition wedgebug.c:258
void send_wls_v(char *name, struct WLS_t *WLS_p, struct transport_tx *trans, struct link_device *dev)
Definition wls_alloc.c:61
void wls_alloc(struct WLS_t *WLS_p, float **B, float *u_guess, float *W_init, int imax)
active set algorithm for control allocation
Definition wls_alloc.c:119
void send_wls_u(char *name, struct WLS_t *WLS_p, struct transport_tx *trans, struct link_device *dev)
Definition wls_alloc.c:71
int nu
Definition wls_alloc.h:67