-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlucciRTB.h
286 lines (242 loc) · 9.54 KB
/
lucciRTB.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/**
* \file lucciRTB.h
* Author: erupter
*
* Created on October 25, 2012, 12:19 PM
*/
#ifndef LUCCIRTB_H
#define LUCCIRTB_H
#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/param.h>
#include "lucciSERVICE.h"
/** \defgroup ReturnToBase*/
/** \brief RTB operating mode EUCLIDEAN constant
*
* \ingroup ReturnToBase
* Constant used in defining RTB's behavior, it is used
* in conjunction with the RTB_GEO_MODE variable
* @see RTB_GEO_MODE
* @see RTB_GEO_MODE_LATLON
*/
#define RTB_GEO_MODE_EUCLIDEAN 0
/** \brief RTB operating mode Geographical Coordinates constant
*
* \ingroup ReturnToBase
* Constant used in defining RTB's behavior, it is used
* in conjunction with the RTB_GEO_MODE variable
* @see RTB_GEO_MODE
* @see RTB_GEO_MODE_EUCLIDEAN
*/
#define RTB_GEO_MODE_LATLON 1
/** \brief RTB Record-mode waypoint saving distance threshold
*
* \ingroup ReturnToBase
* This value determines
* the minimum distance between two consecutive points to use to
* perform the automatic return-to-base. Points with relative
* distance inferior to this value are discarded.
* PLEASE NOTE: the software is unable to determine circular paths,
* unless this value is such as to fully enclose the path.
*/
#define RTB_SAVE_DIST_TRSH 10.0
/** \brief RTB Record-mode adaptive saving distance, speed rate
*
* \ingroup ReturnToBase
* If this option is enabled the above value of maximum distance between two
* consecutive waypoints, is modulated by the vehicle actual longitudinal speed.
* The speed is calculated with a simple difference quotient method.
* Using this capability requires adapting the maximum and minimum vehicle speed
* values accordingly.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_ANGULAR
* @see RTB_SAVE_DIST_ADAPTIVE_MAX_SPEED
* @see RTB_SAVE_DIST_ADAPTIVE_MIN_SPEED
*/
#define RTB_SAVE_DIST_ADAPTIVE_LONGITUDINAL 1 //bool, either 1 or 0
/** \brief RTB Record-mode adaptive saving distance, angular rate
*
* \ingroup ReturnToBase
* When this option is enabled, the distance between two consecutive waypoints is
* modulated according to the angular speed of the vehicle. Meaning the faster the
* turns, the more points will be used to store the trajectory.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_LONGITUDINAL
*/
#define RTB_SAVE_DIST_ADAPTIVE_ANGULAR 1 //bool, either 1 or 0
/** \brief RTB Record-mode adaptive saving distance, maximum speed
*
* \ingroup ReturnToBase
* The maximum speed the vehicle is capable of. Used internally to normalize the
* distance between consecutive waypoints.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_LONGITUDINAL
*/
#define RTB_SAVE_DIST_ADAPTIVE_MAX_SPEED 2.0 //in meters per second
/** \brief RTB Record-mode adaptive saving distance, minimum speed
*
* \ingroup ReturnToBase
* The minimum speed the vehicle is capable of. Used internally to normalize the
* distance between consecutive waypoints.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_LONGITUDINAL
*/
#define RTB_SAVE_DIST_ADAPTIVE_MIN_SPEED 0.2 //in meters per second
/** \brief RTB Record-mode adaptive saving distance, angular sensitivity
*
* \ingroup ReturnToBase
* This value controls how intense the sensitivity to the angular rate is.
* The higher the value the higher the number of stored waypoints during turns.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_ANGULAR
*/
#define RTB_SAVE_DIST_ADAPTIVE_ANGULAR_SENSITIVITY 2 //absolute
/** \brief RTB Record-mode adaptive saving distance, maximum angular speed
*
* \ingroup ReturnToBase
* The maximum speed the vehicle is capable of turning at. Used internally to normalize the
* distance between consecutive waypoints.
* @see RTB_SAVE_DIST_TRSH
* @see RTB_SAVE_DIST_ADAPTIVE_ANGULAR
*/
#define RTB_SAVE_DIST_ADAPTIVE_MAX_ANGULAR_SPEED 0.8 //in radians per second
/** \brief RTB Record-mode waypoint flushing distance threshold
*
* \ingroup ReturnToBase
* During recording the algorithm attempts to optimize the cache of recorded waypoints.
* This distance is the threshold to which every old point is confronted: if an already known
* waypoint is found that passes this threshold, the chain of waypoints saved between the actual
* position and the found one will be deleted. (circular path detection attempt)
*/
#define RTB_FLUSH_DIST_TRSH 1.0
/** \brief RTB Track-mode waypoint change threshold
*
* \ingroup ReturnToBase
* This value determines the distance from the current waypoint at which the
* auto-guidance switches to the next waypoint.
*/
#define RTB_GUIDE_CHANGE_DIST_TRSH 1.0
/** \brief RTB Track-mode global update frequency
*
* \ingroup ReturnToBase
* This represents the decimator used to to perform a global update of all distances
* of all cached waypoints. The base frequency is represented by the super-loop, thus
* it is not know to the algorithm. It just chops down the number of times ti gets
* called by this number, thus performing the global update at a frequency equal to
* SUPERLOOP-CALLS / RTB_GUIDE_UPDATE_TIME_TRSH
*/
#define RTB_GUIDE_UPDATE_TIME_TRSH 10
/** \brief RTB operating mode selection
*
* \ingroup ReturnToBase
* This value takes either of the RTB_GEO_MODE constants to shape
* the software's behavior.
* @see RTB_GEO_MODE_EUCLIDEAN
* @see RTB_GEO_MODE_LATLON
*/
#define RTB_GEO_MODE RTB_GEO_MODE_EUCLIDEAN
/** \brief RTB generalized Earth radius in Km
*
* \ingroup ReturnToBase
* Generalized Earth radius used in mathematical operations
*/
#define EARTH 6371
/** \brief RTB minimum distance between waypoints
*
* \ingroup ReturnToBase
* Minimum distance between waypoints
*/
#define RTB_MIN_WAYPOINT_DIST 1.0 // meters
/** \brief RTB initialization call
*
* \ingroup ReturnToBase
* This function must be called when the module is loaded, it sets the internal status to a known state.
* It is not necessary to call this function any further after initialization.
*/
void RTB_init(void);
/** \brief RTB mode selection
*
* \ingroup ReturnToBase
* Used in conjunction with RTB_mode
* @see RTB_mode
*
* Parent program must actively call this function to change operating mode of the module.
*/
void RTB_set_mode(RTB_mode);
/** \brief RTB main cycle handler
*
* \ingroup ReturnToBase
* This function must be periodically called to guarantee correct recording of positions.
* It is designed to be integrated in a superloop.
* If the module is disabled, calling this function won't affect performance, as no operations
* will be performed in such a case (the module will check its state and immediately return).
* @param localx value either euclidean or lon
* @param localy value either euclidean or lat
* @param xspeed
* @param aspeed
* @return a pointer to the current status
* @see RTB_status, RTB_GEO_MODE
*/
void RTB_update(RTB_FLOAT_TYPE localx, RTB_FLOAT_TYPE localy, RTB_FLOAT_TYPE xspeed, RTB_FLOAT_TYPE aspeed);
#if (RTB_GEO_MODE == RTB_GEO_MODE_EUCLIDEAN)
/** @struct RTB_point
* @brief Waypoint struct (Cartesian)
* \ingroup ReturnToBase
*
* Used in a list, each element holds essential information for the waypoints acquired during operation.
* @param x Member 'x' contains the X value of the point.
* @param y Member 'y' contains the Y value of the point.
* @param distance_from_start Member 'distance_from_start' contains the distance of the point from the origin.
* @param next Member 'next' contains a pointer to the next waypoint (farther from the origin).
* @param previous Member 'previous' contains a pointer to the previous waypoint (nearer to the origin).
*/
typedef struct RTB_point{
RTB_FLOAT_TYPE x; /**< RTB_FLOAT_TYPE contains the X value of the point. */
RTB_FLOAT_TYPE y; /**< RTB_FLOAT_TYPE contains the Y value of the point. */
RTB_FLOAT_TYPE distance_from_start; /**< RTB_FLOAT_TYPE contains the distance of the point from the origin. */
struct RTB_point* next; /**< RTB_point* contains a pointer to the next waypoint (farther from the origin). */
struct RTB_point* previous; /**< RTB_point* contains a pointer to the previous waypoint (nearer to the origin). */
} RTB_point;
#elif (RTB_GEO_MODE == RTB_GEO_MODE_LATLON)
/** @struct RTB_point
* @brief Waypoint struct (Lat/Lon)
* @var RTB_point::lat
* Member 'lat' contains the Latitude value of the point.
* @var RTB_point::lon
* Member 'lon' contains the Longitude value of the point.
* @var RTB_point::distance_from_start
* Member 'distance_from_start' contains the distance of the point from the origin.
* @var RTB_point::next
* Member 'next' contains a pointer to the next waypoint (farther from the origin).
* @var RTB_point::previous
* Member 'previous' contains a pointer to the previous waypoint (nearer to the origin).
*/
typedef struct RTB_point{
RTB_FLOAT_TYPE lat;
RTB_FLOAT_TYPE lon;
RTB_FLOAT_TYPE distance_from_start;
struct RTB_point* next;
struct RTB_point* previous;
} RTB_point;
#else
#error ("No geo mode specified in lucciRTB.h")
#endif
/**
* @brief Debug define. Set to 1 to enable.
* \ingroup ReturnToBase
*/
#define DEBUG 0
/**
* @brief Simulator define. Set to 1 to enable.
* \ingroup ReturnToBase
* This requires Player 3 and Stage 4 to be installed on the system.
*/
#define SIMUL 0
#ifdef __cplusplus
}
#endif
#endif /* LUCCIRTB_H */