Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
rover_guidance_steering.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Jesús Bautista <jesusbautistavillar@gmail.com>
3 * Hector García <noeth3r@gmail.com>
4 * 2025 Gautier Hattenberger <gautier.hattenberger@gmail.com>
5 *
6 * This file is part of paparazzi.
7 *
8 * paparazzi is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * paparazzi is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with paparazzi; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23#define AUTOPILOT_CORE_GUIDANCE_C
24
27
28#include "generated/airframe.h"
29#include "generated/autopilot_core_guidance.h"
30
31#include "autopilot.h"
32#include "state.h"
33
34#include "filters/pid.h" // Used for p+i speed controller
35
36#ifndef ROVER_GUIDANCE_POS_KP
37#define ROVER_GUIDANCE_POS_KP 1.f
38#endif
39
40#ifndef ROVER_GUIDANCE_HEADING_KP
41#define ROVER_GUIDANCE_HEADING_KP 1.f
42#endif
43
44#ifndef ROVER_GUIDANCE_SPEED_KP
45#define ROVER_GUIDANCE_SPEED_KP 10.f
46#endif
47
48#ifndef ROVER_GUIDANCE_SPEED_KI
49#define ROVER_GUIDANCE_SPEED_KI 100.f
50#endif
51
52#ifndef ROVER_GUIDANCE_MAX_POS_ERR
53#define ROVER_GUIDANCE_MAX_POS_ERR 10.f // max position error
54#endif
55
56#ifndef ROVER_GUIDANCE_MAX_SPEED
57#define ROVER_GUIDANCE_MAX_SPEED 10.f
58#endif
59
60#ifndef ROVER_GUIDANCE_PROXIMITY_DISTANCE
61#define ROVER_GUIDANCE_PROXIMITY_DISTANCE 2.f // proximity distance TODO improve with hysteresis ?
62#endif
63
64// Guidance control main variables
66
67static struct PID_f rover_pid;
68static float time_step;
69
89
91{
92 // from code generation
94}
95
97// Steering control (GVF)
98void rover_guidance_steering_heading_ctrl(float omega) //GVF give us this omega
99{
100 // Speed is bounded to avoid GPS noise while driving at small velocity
102 // Compute steering angle
103 float delta = DegOfRad(atanf(omega*DRIVE_SHAFT_DISTANCE/speed));
104
106}
107
108// Speed control (feed feed forward + propotional + integral controler) (PID)
117
119{
120 // compute position error
121 struct FloatVect2 pos_2d;
123 struct FloatVect2 pos_err;
127
128 // speed and heading update when far enough
130 // compute speed error
133 // if not close to WP, compute desired heading
135 // update nav sp
136 *heading_sp = guidance_control.heading_sp;
137 // angular error
139 NormRadAngle(heading_err);
140 // compute omega setpoint
142 }
143 else {
145 guidance_control.heading_sp = *heading_sp;
147 }
148}
149
155
161
167
174
Core autopilot interface common to all firmwares.
float psi
in radians
static float float_vect2_norm(struct FloatVect2 *v)
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_COPY(_a, _b)
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition state.h:1076
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
Several forms of PID controllers.
float sum
integral of input
Definition pid.h:45
static float get_pid_f(struct PID_f *pid)
Get current value of the PID command.
Definition pid.h:89
static void set_gains_pid_f(struct PID_f *pid, float Kp, float Kd, float Ki)
Set gains of the PID struct.
Definition pid.h:113
static void reset_pid_f(struct PID_f *pid)
Reset PID struture, gains left unchanged.
Definition pid.h:98
static float update_pid_f(struct PID_f *pid, float value, float dt)
Update PID with a new value and return new command.
Definition pid.h:68
static void init_pid_f(struct PID_f *pid, float Kp, float Kd, float Ki, float max_sum)
Definition pid.h:50
Simple PID structure floating point.
Definition pid.h:42
vector in East North Up coordinates Units: meters
void rover_guidance_steering_kill(void)
#define ROVER_GUIDANCE_MAX_SPEED
rover_ctrl guidance_control
void rover_guidance_steering_speed_ctrl(void)
#define ROVER_GUIDANCE_MAX_POS_ERR
void rover_guidance_steering_set_speed_igain(float igain)
void rover_guidance_steering_periodic(void)
static float time_step
#define ROVER_GUIDANCE_SPEED_KI
#define ROVER_GUIDANCE_HEADING_KP
#define ROVER_GUIDANCE_POS_KP
Mandatory dependencies header.
void rover_guidance_steering_init(void)
INIT function.
#define ROVER_GUIDANCE_SPEED_KP
static struct PID_f rover_pid
#define ROVER_GUIDANCE_PROXIMITY_DISTANCE
void rover_guidance_steering_pid_reset(void)
PID RESET function.
void rover_guidance_steering_setpoints(struct EnuCoor_f pos_sp, float *heading_sp)
void rover_guidance_steering_heading_ctrl(float omega)
CTRL functions.
void rover_guidance_steering_set_speed_pgain(float pgain)
#define BoundDelta(delta)
MACROS.
#define BoundThrottle(throttle)
#define SR_MEASURED_KF
float omega_sp
omega setpoint
float heading_sp
heading setpoint
#define BoundSpeed(speed)
#define DRIVE_SHAFT_DISTANCE
API to get/set the generic vehicle states.