Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
rover_guidance_steering.h
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  *
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 
22 #ifndef ROVER_GUIDANCE_STEERING_H
23 #define ROVER_GUIDANCE_STEERING_H
24 
31 #include "std.h"
32 #include <math.h>
33 
34 #include "generated/airframe.h"
35 
36 // Check critical global definitiones
37 #ifndef SERVO_MOTOR_THROTTLE_IDX
38 #error "Steering rover firmware requires the servo MOTOR_THROTTLE"
39 #endif
40 
41 #ifndef SERVO_MOTOR_STEERING_IDX
42 #error "Steering rover firmware requires the servo MOTOR_STEERING"
43 #endif
44 
45 #ifndef COMMAND_THROTTLE
46 #error "Steering rover firmware requires the command COMMAND_THROTTLE"
47 #endif
48 
49 #ifndef COMMAND_STEERING
50 #error "Steering rover firmware requires the command COMMAND_STEERING"
51 #endif
52 
53 
56 // MIN_DELTA, MAX_DELTA: Min and max wheels turning angle (deg)
57 // You should measure this angle if you want to have an
58 // efficient control in your steering
59 #ifndef MAX_DELTA
60 #define MAX_DELTA 15.0
61 #endif
62 #ifndef MIN_DELTA
63 #define MIN_DELTA MAX_DELTA
64 #endif
65 
66 // This variables allow you to configurate de max and min
67 // steering actuator signal. There is a mecanic limitation
68 // for the actuator in the steering of our rover, so we have
69 // to limit the actuator travel.
70 #ifndef MAX_CMD_SHUT
71 #define MAX_CMD_SHUT 0
72 #endif
73 #ifndef MIN_CMD_SHUT
74 #define MIN_CMD_SHUT 0
75 #endif
76 
77 // MIN_SPEED, MAX_SPEED: Min and max state speed (m/s)
78 #ifndef MAX_SPEED
79 #define MAX_SPEED 999.0 //We don't really use that variable
80 #endif
81 #ifndef MIN_SPEED
82 #define MIN_SPEED 0.2 //But this one is mandatory because we have
83 #endif //to deal with GPS noise (and 1/v in guidance control).
84 
85 // DRIVE_SHAFT_DISTANCE: Distance between front and rear wheels (m)
86 #ifndef DRIVE_SHAFT_DISTANCE
87 #define DRIVE_SHAFT_DISTANCE 0.25
88 #warning "Construction variable DRIVE_SHAFT_DISTANCE for steering wheel rover not defined"
89 #endif
90 
91 // SR_MEASURED_KF: Lineal feed forward control constant (have to be measured in new servos)
92 #ifndef SR_MEASURED_KF
93 #define SR_MEASURED_KF 10
94 #warning "Construction constant SR_MEASURED_KF for steering wheel rover not defined"
95 #endif
96 
97 
99 // High level commands
100 typedef struct {
101  float speed;
102  float delta;
103 } sr_cmd_t;
104 
105 // Main structure
106 typedef struct {
108  float throttle;
109 
110  float speed_error;
111  float kf;
112  float kp;
113  float ki;
114 } rover_ctrl;
115 
117 
119 extern void rover_guidance_steering_init(void);
120 extern void rover_guidance_steering_heading_ctrl(float omega);
121 extern void rover_guidance_steering_speed_ctrl(void);
122 extern void rover_guidance_steering_pid_reset(void);
123 extern void rover_guidance_steering_kill(void);
124 
125 
127 // Bound delta
128 #define BoundDelta(delta) (delta < -MIN_DELTA ? -MIN_DELTA : \
129  (delta > MAX_DELTA ? MAX_DELTA : \
130  delta))
131 
132 // Bound speed
133 #define BoundSpeed(speed) (speed < MIN_SPEED ? MIN_SPEED : \
134  (speed > MAX_SPEED ? MAX_SPEED : \
135  speed))
136 
137 // Bound throttle
138 #define BoundThrottle(throttle) TRIM_PPRZ((int)throttle)
139 
140 // Set low level commands from high level commands
141 #define GetCmdFromDelta(delta) (delta >= 0 ? -delta/MAX_DELTA * (MAX_PPRZ - (int)MAX_CMD_SHUT) : \
142  -delta/MIN_DELTA * (MAX_PPRZ - (int)MIN_CMD_SHUT))
143 
144 // This macro is for NAV state
145 #define GetCmdFromThrottle(throttle) (autopilot_throttle_killed() ? 0 : TRIM_PPRZ((int)throttle))
146 
147 // Set AP throttle value
148 #define SetAPThrottleFromCommands(void) { \
149  autopilot.throttle = commands[COMMAND_THROTTLE]; \
150  }
151 
152 #endif // ROVER_GUIDANCE_STEERING_H
void rover_guidance_steering_kill(void)
rover_ctrl guidance_control
Mandatory dependencies header.
void rover_guidance_steering_speed_ctrl(void)
void rover_guidance_steering_init(void)
Steering rover guidance EXT FUNCTIONS.
void rover_guidance_steering_pid_reset(void)
PID RESET function.
void rover_guidance_steering_heading_ctrl(float omega)
CTRL functions.
Steering rover guidance STRUCTURES.