Paparazzi UAS v7.1_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 * 2025 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
35#include "state.h"
36#include "generated/modules.h"
37
38// FIXME should be a function of the mass
39
40#ifndef GUIDANCE_INDI_MAX_H_THRUST
41#define GUIDANCE_INDI_MAX_H_THRUST 2.f
42#endif
43
44#ifndef GUIDANCE_INDI_MAX_V_THRUST
45#define GUIDANCE_INDI_MAX_V_THRUST 15.f
46#endif
47
50
58void guidance_indi_calcG(float Gmat[3][6], const struct FloatQuat *att)
59{
62 // Euler Angles
63 const float sphi = sinf(euler_yxz.phi);
64 const float cphi = cosf(euler_yxz.phi);
65 const float stheta = sinf(euler_yxz.theta);
66 const float ctheta = cosf(euler_yxz.theta);
67 const float cpsi = cosf(euler_yxz.psi);
68 const float spsi = sinf(euler_yxz.psi);
69
70 // Estimated Thrust
71 const float Tx = stab_thrust_filt.x;
72 const float Ty = stab_thrust_filt.y;
73 const float Tz = stab_thrust_filt.z;
74
75 // dPhi (Roll)
76 Gmat[0][0] = Tx * (stheta * cphi * spsi) + Ty * (stheta * cphi * cpsi) + Tz * (-stheta * sphi);
77 Gmat[1][0] = Tx * (-sphi * spsi) + Ty * (-sphi * cpsi) + Tz * (-cphi);
78 Gmat[2][0] = Tx * (ctheta * cphi * spsi) + Ty * (ctheta * cphi * cpsi) + Tz * (-ctheta * sphi);
79
80 // dTheta (Pitch)
81 Gmat[0][1] = Tx * (-stheta * cpsi + ctheta * sphi * spsi) + Ty * (stheta * spsi + ctheta * sphi * cpsi) + Tz * (ctheta * cphi);
82 Gmat[1][1] = 0.f;
83 Gmat[2][1] = Tx * (-ctheta * cpsi - stheta * sphi * spsi) +Ty * (ctheta * spsi - stheta * sphi * cpsi) + Tz * (-stheta * cphi);
84
85 // dPsi added to add constraints on psi
86 Gmat[0][2] = 0.f;
87 Gmat[1][2] = 0.f;
88 Gmat[2][2] = 0.f;
89
90 // dTx
91 Gmat[0][3] = ctheta * cpsi - stheta * sphi * spsi;
92 Gmat[1][3] = ctheta * spsi;
93 Gmat[2][3] = -stheta * cpsi + ctheta * sphi * spsi;
94
95 // dTy
96 Gmat[0][4] = -ctheta * spsi + stheta * sphi * cpsi;
97 Gmat[1][4] = cphi * cpsi;
98 Gmat[2][4] = stheta * spsi + ctheta * sphi * cpsi;
99
100 // dTz
101 Gmat[0][5] = stheta * cphi;
102 Gmat[1][5] = -sphi;
103 Gmat[2][5] = ctheta * cphi;
104}
105
106void guidance_indi_set_wls_settings(struct WLS_t *wls, const struct FloatQuat *att, const float heading_sp)
107{
108 struct FloatEulers euler_yxz_ref = { 0 };
109#if GUIDANCE_INDI_RC_SWITCH_EULER
112#endif
113 euler_yxz_ref.psi = heading_sp;
114
115 struct FloatEulers euler_yxz;
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
144{
145 float thrust[3];
146 thrust[0] = -radio_control_get(RADIO_PITCH) / MAX_PPRZ;
148 thrust[2] = th_sp_to_thrust_f(v_sp, 0, THRUST_AXIS_Z);
149 return th_sp_from_thrust_vect_f(thrust);
150}
151
153{
154 struct FloatEulers eulers = stab_sp_to_eulers_f(a_sp);
155 eulers.phi = 0.f;
156 eulers.theta = 0.f;
157 return stab_sp_from_eulers_f(&eulers);
158}
159
float phi
in radians
float theta
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
struct ThrustSetpoint guidance_set_rc_h_thrust(struct ThrustSetpoint *v_sp)
Set horizontal thrust from RC Horizontal is passed as an argument.
struct StabilizationSetpoint guidance_set_rc_h_att(struct StabilizationSetpoint *a_sp)
Set flat attitude setpoint from RC Heading setpoint is kept.
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 FloatEulers stab_sp_to_eulers_f(struct StabilizationSetpoint *sp)
struct ThrustSetpoint th_sp_from_thrust_vect_f(float thrust[3])
struct StabilizationSetpoint stab_sp_from_eulers_f(struct FloatEulers *eulers)
float th_sp_to_thrust_f(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
#define THRUST_AXIS_Z
struct FloatVect3 stab_thrust_filt
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...