Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
control_mixing_heewing.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
28#include "generated/modules.h"
31#include "autopilot.h"
32#include "state.h"
39
40// Tilt position in forward flight
41#ifndef CMH_TILT_FORWARD
42#define CMH_TILT_FORWARD 0
43#endif
44
45// Tilt vertical position for hovering
46#ifndef CMH_TILT_VERTICAL
47#define CMH_TILT_VERTICAL 8700
48#endif
49
50// Max tilt differential for yaw
51#ifndef CMH_TILT_DIFF_MAX
52#define CMH_TILT_DIFF_MAX (MAX_PPRZ-CMH_TILT_VERTICAL)
53#endif
54
55// Motor idle position
56#ifndef CMH_MOTOR_IDLE
57#define CMH_MOTOR_IDLE 800
58#endif
59
60// Time for forward transition
61#ifndef CMH_TRANSITION_TIME
62#define CMH_TRANSITION_TIME 4.f
63#endif
64
65// Transition airspeed, set a negative value to disable
66#ifndef CMH_TRANSITION_AIRSPEED
67#define CMH_TRANSITION_AIRSPEED 10.f
68#endif
69
70#define TRANSITION_TO_HOVER false
71#define TRANSITION_TO_FORWARD true
72
73static float transition_ratio;
75
76static void transition_run(bool to_forward) {
77 if (to_forward && transition_ratio < 1.f) {
82 }
85 }
86 }
87 } else if (!to_forward && transition_ratio > 0.f) {
88 transition_ratio = 0.f; // immediately switch back to hover
89 }
90 Bound(transition_ratio, 0.f, 1.f);
91}
92
97
99{
100 transition_ratio = 0.f; // 0. for hover to 1. for forward flight
101}
102
116
144
152
172
181
183{
185
186 if (transition_ratio < 0.5f) {
189 }
191 struct FloatEulers rc_sp = {
194 .psi = 0.f
195 };
198
202 if (autopilot_in_flight()) {
203 if (transition_ratio < 0.5f) {
204 // only hover stabilization
208 } else {
209 // blend with plane control
213 }
214 } else {
218 }
222
223}
224
231
233{
237
239 if (transition_ratio < 0.8f) {
241 }
243 if (transition_ratio < 0.5f) {
246 struct FloatEulers eulers_sp = { .phi = 0.f , .theta = 0.f, .psi = stateGetNedToBodyEulers_f()->psi };
248 stabilization_run(autopilot_in_flight(), &hover_stab_sp, &hover_th_sp, stabilization.cmd); // will overwrite COMMAND_THRUST
249 } else {
251 }
252 nav.heading = stateGetNedToBodyEulers_f()->psi; // overwrite nav heading to avoid problems when transition to hover
253
259 if (transition_ratio < 0.5f) {
260 // only hover stabilization
264 } else {
265 // blend with plane control
269 }
271 } else {
276 }
277
278 } else {
279 // all other nav modes are in rotorcraft flight mode
284
288
293 if (autopilot_in_flight()) {
295 } else {
297 }
299 } else {
305 }
306 }
308}
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
bool autopilot_get_motors_on(void)
get motors status
Definition autopilot.c:295
bool autopilot_in_flight(void)
get in_flight flag
Definition autopilot.c:340
Core autopilot interface common to all firmwares.
pprz_t throttle
throttle level as will be displayed in GCS
Definition autopilot.h:66
Hardware independent code for commands handling.
void control_mixing_heewing_nav_enter(void)
void control_mixing_heewing_nav_run(void)
void stabilization_indi_set_wls_settings(void)
Function that sets the u_min, u_max and u_pref if function not elsewhere defined.
static float transition_ratio
void control_mixing_heewing_manual(void)
Direct manual control in plane style flight.
void control_mixing_heewing_attitude_plane(void)
void control_mixing_heewing_init(void)
#define CMH_TILT_FORWARD
#define CMH_TILT_VERTICAL
void control_mixing_heewing_attitude_direct(void)
Stabilization in attitude direct mode.
void control_mixing_heewing_attitude_plane_enter(void)
static int32_t command_from_transition(int32_t hover_cmd, int32_t forward_cmd)
#define CMH_TRANSITION_AIRSPEED
static const float transition_increment
#define CMH_MOTOR_IDLE
#define CMH_TRANSITION_TIME
#define CMH_TILT_DIFF_MAX
#define TRANSITION_TO_FORWARD
#define TRANSITION_TO_HOVER
static void transition_run(bool to_forward)
void control_mixing_heewing_attitude_direct_enter(void)
#define CMH_ACT_MOTOR_RIGHT
#define CMH_ACT_YAW
#define CMH_ACT_MOTOR_TAIL
#define CMH_ACT_MOTOR_LEFT
float phi
in radians
float psi
in radians
euler angles
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static bool stateIsAirspeedValid(void)
test if air speed is available.
Definition state.h:1411
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition state.h:1590
struct GuidancePlane guidance_plane
Guidance PID structyre.
struct StabilizationSetpoint guidance_plane_attitude_from_nav(bool in_flight UNUSED)
run horizontal control loop for position and speed control
struct ThrustSetpoint guidance_plane_thrust_from_nav(bool in_flight)
run vertical control loop for position and speed control
Guidance controller for planes in rotorcraft firmware using basic PID controller no airspeed control.
uint16_t foo
Definition main_demo5.c:58
Hardware independent API for actuators (servos, motor controllers).
#define MAX_PPRZ
Definition paparazzi.h:8
#define MIN_PPRZ
Definition paparazzi.h:9
Generic interface for radio control modules.
static pprz_t radio_control_get(uint8_t idx)
Get a radio control channel value.
void guidance_h_mode_changed(uint8_t new_mode)
Definition guidance_h.c:128
struct StabilizationSetpoint guidance_h_run(bool in_flight)
Definition guidance_h.c:244
#define GUIDANCE_H_MODE_NAV
Definition guidance_h.h:58
#define GUIDANCE_H_MODE_NONE
Definition guidance_h.h:56
void guidance_v_mode_changed(uint8_t new_mode)
Definition guidance_v.c:133
struct ThrustSetpoint guidance_v_run(bool in_flight)
Guidance vertical run functions.
Definition guidance_v.c:223
#define GUIDANCE_V_MODE_RC_DIRECT
Definition guidance_v.h:36
#define GUIDANCE_V_MODE_NAV
Definition guidance_v.h:40
struct RotorcraftNavigation nav
Definition navigation.c:51
Rotorcraft navigation functions.
#define NAV_HORIZONTAL_MODE_CIRCLE
Definition navigation.h:87
#define NAV_HORIZONTAL_MODE_ROUTE
Definition navigation.h:86
float heading
heading setpoint (in radians)
Definition navigation.h:133
static const ShellCommand commands[]
Definition shell_arch.c:78
struct Stabilization stabilization
void stabilization_mode_changed(uint8_t new_mode, uint8_t submode)
Check mode change.
void stabilization_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Call default stabilization control.
struct StabilizationSetpoint stab_sp_from_eulers_f(struct FloatEulers *eulers)
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
#define STABILIZATION_MODE_ATTITUDE
#define STABILIZATION_ATT_SUBMODE_HEADING
Stabilization sub-modes for attitude.
#define THRUST_AXIS_X
struct StabilizationSetpoint rc_sp
Keep it ? FIXME.
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
#define STABILIZATION_MODE_NONE
Stabilization modes.
void stabilization_attitude_plane_pid_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
void stabilization_attitude_plane_pid_enter(void)
Basic fixed-wing attitude stabilization in euler float version.
float act_pref[INDI_NUM_ACT]
struct WLS_t wls_stab_p
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...
int int32_t
Typedef defining 32 bit int type.
float u_min[WLS_N_U_MAX]
Definition wls_alloc.h:75
float u_max[WLS_N_U_MAX]
Definition wls_alloc.h:76
float u_pref[WLS_N_U_MAX]
Definition wls_alloc.h:74