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
55static void guidance_indi_calcG_yxz(float Gmat[3][6], struct FloatEulers euler_yxz)
56{
57 // Euler Angles
58 const float sphi = sinf(euler_yxz.phi);
59 const float cphi = cosf(euler_yxz.phi);
60 const float stheta = sinf(euler_yxz.theta);
61 const float ctheta = cosf(euler_yxz.theta);
62 const float cpsi = cosf(euler_yxz.psi);
63 const float spsi = sinf(euler_yxz.psi);
64
65 // Estimated Thrust
66 const float Tx = stab_thrust_filt.x;
67 const float Ty = stab_thrust_filt.y;
68 const float Tz = stab_thrust_filt.z;
69
70 // dPhi (Roll)
71 Gmat[0][0] = Tx * (stheta * cphi * spsi) + Ty * (stheta * cphi * cpsi) + Tz * (-stheta * sphi);
72 Gmat[1][0] = Tx * (-sphi * spsi) + Ty * (-sphi * cpsi) + Tz * (-cphi);
73 Gmat[2][0] = Tx * (ctheta * cphi * spsi) + Ty * (ctheta * cphi * cpsi) + Tz * (-ctheta * sphi);
74
75 // dTheta (Pitch)
76 Gmat[0][1] = Tx * (-stheta * cpsi + ctheta * sphi * spsi) + Ty * (stheta * spsi + ctheta * sphi * cpsi) + Tz * (ctheta * cphi);
77 Gmat[1][1] = 0.f;
78 Gmat[2][1] = Tx * (-ctheta * cpsi - stheta * sphi * spsi) +Ty * (ctheta * spsi - stheta * sphi * cpsi) + Tz * (-stheta * cphi);
79
80 // dPsi added to add constraints on psi
81 Gmat[0][2] = 0.f;
82 Gmat[1][2] = 0.f;
83 Gmat[2][2] = 0.f;
84
85 // dTx
86 Gmat[0][3] = ctheta * cpsi - stheta * sphi * spsi;
87 Gmat[1][3] = ctheta * spsi;
88 Gmat[2][3] = -stheta * cpsi + ctheta * sphi * spsi;
89
90 // dTy
91 Gmat[0][4] = -ctheta * spsi + stheta * sphi * cpsi;
92 Gmat[1][4] = cphi * cpsi;
93 Gmat[2][4] = stheta * spsi + ctheta * sphi * cpsi;
94
95 // dTz
96 Gmat[0][5] = stheta * cphi;
97 Gmat[1][5] = -sphi;
98 Gmat[2][5] = ctheta * cphi;
99}
100
105void guidance_indi_calcG(float Gmat[3][6], struct FloatEulers euler) {
107}
108
109void guidance_indi_set_wls_settings(struct WLS_t *wls, struct FloatEulers *euler_yxz, float heading_sp)
110{
111 struct FloatEulers euler_yxz_ref = { 0 };
112#if GUIDANCE_INDI_RC_SWITCH_EULER
115#endif
116 euler_yxz_ref.psi = heading_sp;
117
118 // Set lower limits
119 wls->u_min[0] = -guidance_indi_max_bank - euler_yxz->phi; // phi
120 wls->u_min[1] = -guidance_indi_max_bank - euler_yxz->theta; // theta
121 wls->u_min[2] = -M_PI - euler_yxz->psi; // psi
125
126 // Set lower limits limits
127 wls->u_max[0] = guidance_indi_max_bank - euler_yxz->phi; // phi
128 wls->u_max[1] = guidance_indi_max_bank - euler_yxz->theta; // theta
129 wls->u_max[2] = M_PI - euler_yxz->psi; // psi
132 wls->u_max[5] = 9.81f * GUIDANCE_INDI_MASS - stab_thrust_filt.z; // Tz
133
134 // Set prefered states
135 wls->u_pref[0] = euler_yxz_ref.phi - euler_yxz->phi; // prefered delta phi
136 wls->u_pref[1] = euler_yxz_ref.theta - euler_yxz->theta; // prefered delta theta
137 wls->u_pref[2] = euler_yxz_ref.psi - euler_yxz->psi; // prefered delta psi
138 wls->u_pref[3] = stab_thrust_filt.x; // prefered delta Tx
139 wls->u_pref[4] = stab_thrust_filt.y; // prefered delta Ty
140 wls->u_pref[5] = stab_thrust_filt.z; // prefered delta Tz
141}
142
float phi
in radians
euler angles
float guidance_indi_max_bank
static float Gmat[GUIDANCE_INDI_NV][GUIDANCE_INDI_NU]
A guidance mode based on Incremental Nonlinear Dynamic Inversion.
void guidance_indi_set_wls_settings(struct WLS_t *wls, struct FloatEulers *euler_yxz, float heading_sp)
#define GUIDANCE_INDI_MAX_H_THRUST
static void guidance_indi_calcG_yxz(float Gmat[3][6], struct FloatEulers euler_yxz)
#define GUIDANCE_INDI_MAX_V_THRUST
void guidance_indi_calcG(float Gmat[3][6], struct FloatEulers euler)
Compute effectiveness matrix for guidance.
float guidance_indi_max_v_thrust
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.