Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
guidance_indi_fully_actuated.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3 * 20025 Mohamad Hachem
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 */
21
32#include "state.h"
33#include "generated/modules.h"
34
35// FIXME should be a function of the mass
36
37#ifndef GUIDANCE_INDI_MAX_H_THRUST
38#define GUIDANCE_INDI_MAX_H_THRUST 2.f
39#endif
40
41#ifndef GUIDANCE_INDI_MAX_V_THRUST
42#define GUIDANCE_INDI_MAX_V_THRUST 15.f
43#endif
44
47
55void guidance_indi_calcG(float Gmat[3][6], const struct FloatQuat *att)
56{
59 // Euler Angles
60 const float sphi = sinf(euler_yxz.phi);
61 const float cphi = cosf(euler_yxz.phi);
62 const float stheta = sinf(euler_yxz.theta);
63 const float ctheta = cosf(euler_yxz.theta);
64 const float cpsi = cosf(euler_yxz.psi);
65 const float spsi = sinf(euler_yxz.psi);
66
67 // Estimated Thrust
68 const float Tx = stab_thrust_filt.x;
69 const float Ty = stab_thrust_filt.y;
70 const float Tz = stab_thrust_filt.z;
71
72 // dPhi (Roll)
73 Gmat[0][0] = Tx * (stheta * cphi * spsi) + Ty * (stheta * cphi * cpsi) + Tz * (-stheta * sphi);
74 Gmat[1][0] = Tx * (-sphi * spsi) + Ty * (-sphi * cpsi) + Tz * (-cphi);
75 Gmat[2][0] = Tx * (ctheta * cphi * spsi) + Ty * (ctheta * cphi * cpsi) + Tz * (-ctheta * sphi);
76
77 // dTheta (Pitch)
78 Gmat[0][1] = Tx * (-stheta * cpsi + ctheta * sphi * spsi) + Ty * (stheta * spsi + ctheta * sphi * cpsi) + Tz * (ctheta * cphi);
79 Gmat[1][1] = 0.f;
80 Gmat[2][1] = Tx * (-ctheta * cpsi - stheta * sphi * spsi) +Ty * (ctheta * spsi - stheta * sphi * cpsi) + Tz * (-stheta * cphi);
81
82 // dPsi added to add constraints on psi
83 Gmat[0][2] = 0.f;
84 Gmat[1][2] = 0.f;
85 Gmat[2][2] = 0.f;
86
87 // dTx
88 Gmat[0][3] = ctheta * cpsi - stheta * sphi * spsi;
89 Gmat[1][3] = ctheta * spsi;
90 Gmat[2][3] = -stheta * cpsi + ctheta * sphi * spsi;
91
92 // dTy
93 Gmat[0][4] = -ctheta * spsi + stheta * sphi * cpsi;
94 Gmat[1][4] = cphi * cpsi;
95 Gmat[2][4] = stheta * spsi + ctheta * sphi * cpsi;
96
97 // dTz
98 Gmat[0][5] = stheta * cphi;
99 Gmat[1][5] = -sphi;
100 Gmat[2][5] = ctheta * cphi;
101}
102
103void guidance_indi_set_wls_settings(struct WLS_t *wls, const struct FloatQuat *att, const float heading_sp)
104{
105 struct FloatEulers euler_yxz_ref = { 0 };
106#if GUIDANCE_INDI_RC_SWITCH_EULER
109#endif
110 euler_yxz_ref.psi = heading_sp;
111
112 struct FloatEulers euler_yxz;
114
115 // Set lower limits
116 wls->u_min[0] = -guidance_indi_max_bank - euler_yxz.phi; // phi
117 wls->u_min[1] = -guidance_indi_max_bank - euler_yxz.theta; // theta
118 wls->u_min[2] = -M_PI - euler_yxz.psi; // psi
122
123 // Set lower limits limits
124 wls->u_max[0] = guidance_indi_max_bank - euler_yxz.phi; // phi
125 wls->u_max[1] = guidance_indi_max_bank - euler_yxz.theta; // theta
126 wls->u_max[2] = M_PI - euler_yxz.psi; // psi
129 wls->u_max[5] = 9.81f * GUIDANCE_INDI_MASS - stab_thrust_filt.z; // Tz
130
131 // Set prefered states
132 wls->u_pref[0] = euler_yxz_ref.phi - euler_yxz.phi; // prefered delta phi
133 wls->u_pref[1] = euler_yxz_ref.theta - euler_yxz.theta; // prefered delta theta
134 wls->u_pref[2] = euler_yxz_ref.psi - euler_yxz.psi; // prefered delta psi
135 wls->u_pref[3] = stab_thrust_filt.x; // prefered delta Tx
136 wls->u_pref[4] = stab_thrust_filt.y; // prefered delta Ty
137 wls->u_pref[5] = stab_thrust_filt.z; // prefered delta Tz
138}
139
float phi
in radians
void float_eulers_of_quat_yxz(struct FloatEulers *e, const struct FloatQuat *q)
euler rotation 'YXZ' This function calculates from a quaternion the Euler angles with the order YXZ,...
euler angles
Roation quaternion.
float guidance_indi_max_bank
static float Gmat[GUIDANCE_INDI_NV][GUIDANCE_INDI_NU]
A guidance mode based on Incremental Nonlinear Dynamic Inversion.
#define GUIDANCE_INDI_MAX_H_THRUST
void guidance_indi_calcG(float Gmat[3][6], const struct FloatQuat *att)
#define GUIDANCE_INDI_MAX_V_THRUST
float guidance_indi_max_v_thrust
void guidance_indi_set_wls_settings(struct WLS_t *wls, const struct FloatQuat *att, const float heading_sp)
float guidance_indi_max_h_thrust
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
static pprz_t radio_control_get(uint8_t idx)
Get a radio control channel value.
struct FloatVect3 stab_thrust_filt
API to get/set the generic vehicle states.