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 1.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 float sphi = sinf(euler_yxz.phi);
59 float cphi = cosf(euler_yxz.phi);
60 float stheta = sinf(euler_yxz.theta);
61 float ctheta = cosf(euler_yxz.theta);
62 float cpsi = cosf(euler_yxz.psi);
63 float spsi = sinf(euler_yxz.psi);
64
65 // Estimated Thrust
66 float Tx = stab_thrust_filt.x;
67 float Ty = stab_thrust_filt.y;
68 float Tz = stab_thrust_filt.z;
69
70 // dPhi (Roll)
71 Gmat[0][0] = Tx * (-spsi * cphi * stheta) + Ty * (spsi * sphi) + Tz * (spsi * cphi * ctheta);
72 Gmat[1][0] = Tx * (cpsi * cphi * stheta) + Ty * (-cpsi * sphi) + Tz * (-cpsi * cphi * ctheta);
73 Gmat[2][0] = Tx * (sphi * stheta) + Ty * (cphi) + Tz * (-sphi * ctheta);
74
75 // dTheta (Pitch)
76 Gmat[0][1] = Tx * (-cpsi * stheta - spsi * sphi * ctheta) + Tz * (cpsi * ctheta - spsi * sphi * stheta);
77 Gmat[1][1] = Tx * (-spsi * stheta + cpsi * sphi * ctheta) + Tz * (spsi * ctheta + cpsi * sphi * stheta);
78 Gmat[2][1] = Tx * (-cphi * ctheta) + Tz * (-cphi * stheta);
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] = cpsi * ctheta - spsi * sphi * stheta;
87 Gmat[1][3] = spsi * ctheta + cpsi * sphi * stheta;
88 Gmat[2][3] = -stheta * cphi;
89
90 // dTy
91 Gmat[0][4] = -spsi * cphi;
92 Gmat[1][4] = cpsi * cphi;
93 Gmat[2][4] = sphi;
94
95 // dTz
96 Gmat[0][5] = cpsi * stheta + spsi * sphi * ctheta;
97 Gmat[1][5] = spsi * stheta - cpsi * sphi * ctheta;
98 Gmat[2][5] = cphi * ctheta;
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 UNUSED)
110{
111 struct FloatEulers euler_yxz_ref = { 0 };
112#if GUIDANCE_INDI_RC_SWITCH_EULER
115 euler_yxz_ref.psi = heading_sp // TODO check this one
116#endif
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 FIXME M_PI or a lower bound ? (was 1 in initial code)
124 wls->u_min[5] = -guidance_indi_max_v_thrust - stab_thrust_filt.z; //Tz (MAX_PPRZ - stabilization.cmd[COMMAND_THRUST])
125
126 // ->r 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 // ->ered 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 Ty
138 wls->u_pref[3] = stab_thrust_filt.x; // prefred Tx
139 wls->u_pref[4] = stab_thrust_filt.y; // prefered Ty
140 wls->u_pref[5] = stab_thrust_filt.z; // prefered Tz
141}
142
#define UNUSED(x)
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.
#define GUIDANCE_INDI_MAX_H_THRUST
static void guidance_indi_calcG_yxz(float Gmat[3][6], struct FloatEulers euler_yxz)
void guidance_indi_set_wls_settings(struct WLS_t *wls, struct FloatEulers *euler_yxz, float heading_sp UNUSED)
#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.