Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_rover_base.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 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
30
40
62
63static bool nav_approaching(struct EnuCoor_f *wp, struct EnuCoor_f *from, float approaching_time)
64{
65 float dist_to_point;
66 struct FloatVect2 diff;
67 struct EnuCoor_f *pos = stateGetPositionEnu_f();
68
69 /* if an approaching_time is given, estimate diff after approching_time secs */
70 if (approaching_time > 0.f) {
73 struct EnuCoor_f *speed = stateGetSpeedEnu_f();
77 }
78 /* else use current position */
79 else {
80 VECT2_DIFF(diff, *wp, *pos);
81 }
82 /* compute distance of estimated/current pos to target wp
83 */
84 //nav.dist_to_point = float_vect2_norm(&diff); FIXME
86
87 /* return TRUE if we have arrived */
89 return true;
90 }
91
92 /* if coming from a valid waypoint */
93 if (from != NULL) {
94 /* return TRUE if normal line at the end of the segment is crossed */
95 struct FloatVect2 from_diff;
96 VECT2_DIFF(from_diff, *wp, *from);
97 return (diff.x * from_diff.x + diff.y * from_diff.y < 0.f);
98 }
99
100 return false;
101}
102
103static void nav_circle(struct EnuCoor_f *wp_center, float radius)
104{
105 struct FloatVect2 pos_diff;
107 // store last qdr
109 // compute qdr
111 // increment circle radians
115
116 // direction of rotation
117 float sign_radius = radius > 0.f ? 1.f : -1.f;
118 // absolute radius
119 float abs_radius = fabsf(radius);
120 if (abs_radius > 0.1f) {
121 // carrot_angle
126 // compute setpoint
128 VECT2_SUM(nav.target, *wp_center, pos_diff);
129 }
130 else {
131 // radius is too small, direct to center
132 VECT2_COPY(nav.target, *wp_center);
133 }
134
135 nav_rover_base.circle.center = *wp_center;
137 nav.mode = NAV_MODE_CIRCLE;
138}
139
146#ifndef LINE_START_FUNCTION
147#define LINE_START_FUNCTION {}
148#endif
149#ifndef LINE_STOP_FUNCTION
150#define LINE_STOP_FUNCTION {}
151#endif
152
153static void _nav_oval_init(void)
154{
157}
158
159static void nav_oval(struct EnuCoor_f *wp1, struct EnuCoor_f *wp2, float radius)
160{
161 (void) wp1;
162 (void) wp2;
163 (void) radius;
164#if 0
165 radius = - radius; /* Historical error ? */
166 int32_t alt = waypoints[p1].enu_i.z;
167 waypoints[p2].enu_i.z = alt;
168
169 float p2_p1_x = waypoints[p1].enu_f.x - waypoints[p2].enu_f.x;
170 float p2_p1_y = waypoints[p1].enu_f.y - waypoints[p2].enu_f.y;
171 float d = sqrtf(p2_p1_x * p2_p1_x + p2_p1_y * p2_p1_y);
172
173 /* Unit vector from p1 to p2 */
176
177 /* The half circle centers and the other leg */
178 struct EnuCoor_i p1_center = { waypoints[p1].enu_i.x + radius * -u_y,
179 waypoints[p1].enu_i.y + radius * u_x,
180 alt
181 };
182 struct EnuCoor_i p1_out = { waypoints[p1].enu_i.x + 2 * radius * -u_y,
183 waypoints[p1].enu_i.y + 2 * radius * u_x,
184 alt
185 };
186
187 struct EnuCoor_i p2_in = { waypoints[p2].enu_i.x + 2 * radius * -u_y,
188 waypoints[p2].enu_i.y + 2 * radius * u_x,
189 alt
190 };
191 struct EnuCoor_i p2_center = { waypoints[p2].enu_i.x + radius * -u_y,
192 waypoints[p2].enu_i.y + radius * u_x,
193 alt
194 };
195
198 if (radius < 0) {
201 }
202 int32_t qdr_anticipation = ANGLE_BFP_OF_REAL(radius > 0 ? -15 : 15);
203
204 switch (oval_status) {
205 case OC1 :
209 InitStage();
211 }
212 return;
213
214 case OR12:
219 InitStage();
221 }
222 return;
223
224 case OC2 :
228 InitStage();
230 }
231 return;
232
233 case OR21:
234 nav_route(&waypoints[p2].enu_i, &waypoints[p1].enu_i);
235 if (nav_approaching_from(&waypoints[p1].enu_i, &waypoints[p2].enu_i, CARROT)) {
237 InitStage();
239 }
240 return;
241
242 default: /* Should not occur !!! Doing nothing */
243 return;
244 }
245#endif
246}
247
248#if PERIODIC_TELEMETRY
250
251#if ROVER_BASE_SEND_TRAJECTORY
252static void send_segment(struct transport_tx *trans, struct link_device *dev)
253{
259}
260
261static void send_circle(struct transport_tx *trans, struct link_device *dev)
262{
267}
268#endif // ROVER_BASE_SEND_TRAJECTORY
269
270static void send_nav_status(struct transport_tx *trans, struct link_device *dev)
271{
278 &nav.mode);
279#if ROVER_BASE_SEND_TRAJECTORY
280 if (nav.mode == NAV_MODE_ROUTE) {
281 send_segment(trans, dev);
282 } else if (nav.mode == NAV_MODE_CIRCLE) {
283 send_circle(trans, dev);
284 }
285#endif // ROVER_BASE_SEND_TRAJECTORY
286}
287#endif
288
307
308
uint8_t nav_stage
uint8_t nav_block
uint16_t stage_time
In s.
uint16_t block_time
#define InitStage()
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:44
float y
Definition common_nav.h:41
float x
Definition common_nav.h:40
#define Min(x, y)
Definition esc_dshot.c:109
static float float_vect2_norm(struct FloatVect2 *v)
#define VECT2_SMUL(_vo, _vi, _s)
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_COPY(_a, _b)
#define VECT2_SUM(_c, _a, _b)
#define VECT2_ASSIGN(_a, _x, _y)
#define INT32_DEG_OF_RAD(_rad)
#define ANGLE_BFP_OF_REAL(_af)
#define INT32_ANGLE_PI
#define POS_BFP_OF_REAL(_af)
vector in East North Up coordinates
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition state.h:1058
uint16_t foo
Definition main_demo5.c:58
uint8_t nav_oval_count
Navigation along a figure O.
Definition nav.c:754
static void send_circle(struct transport_tx *trans, struct link_device *dev)
Definition nav.c:504
static void send_segment(struct transport_tx *trans, struct link_device *dev)
Definition nav.c:512
oval_status
Definition nav.h:60
@ OC2
Definition nav.h:60
@ OC1
Definition nav.h:60
@ OR12
Definition nav.h:60
@ OR21
Definition nav.h:60
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
Definition nav.h:161
static void send_nav_status(struct transport_tx *trans, struct link_device *dev)
#define LINE_STOP_FUNCTION
static void nav_goto(struct EnuCoor_f *wp)
Implement basic nav function.
void nav_rover_init(void)
Init and register nav functions.
#define LINE_START_FUNCTION
Navigation along a figure O.
static void _nav_oval_init(void)
static void nav_route(struct EnuCoor_f *wp_start, struct EnuCoor_f *wp_end)
static void nav_circle(struct EnuCoor_f *wp_center, float radius)
struct RoverNavBase nav_rover_base
static bool nav_approaching(struct EnuCoor_f *wp, struct EnuCoor_f *from, float approaching_time)
static void nav_oval(struct EnuCoor_f *wp1, struct EnuCoor_f *wp2, float radius)
struct RoverNavCircle circle
uint8_t count
number of laps
float leg_progress
progress over leg
struct RoverNavOval oval
enum oval_status status
oval status
struct RoverNavGoto goto_wp
float radians
incremental angular distance
struct EnuCoor_f from
start WP position
float leg_length
leg length
struct EnuCoor_f center
center WP position
float qdr
qdr in radians
float dist2_to_wp
squared distance to next waypoint
struct EnuCoor_f to
end WP position
float radius
radius in meters
Basic Nav struct.
struct FloatVect2 pos_diff
float y
in meters
float x
in meters
vector in East North Up coordinates Units: meters
int32_t int32_atan2_2(int32_t y, int32_t x)
void nav_register_oval(navigation_oval_init _nav_oval_init, navigation_oval nav_oval)
Definition navigation.c:404
struct RotorcraftNavigation nav
Definition navigation.c:51
void nav_register_circle(navigation_circle nav_circle)
Definition navigation.c:399
void nav_register_goto_wp(navigation_goto nav_goto, navigation_route nav_route, navigation_approaching nav_approaching)
Registering functions.
Definition navigation.c:392
float get_dist2_to_point(struct EnuCoor_f *p)
Returns squared horizontal distance to given point.
Definition navigation.c:308
float dist2_to_home
squared distance to home waypoint
Definition navigation.h:143
#define DEFAULT_CIRCLE_RADIUS
default nav_circle_radius in meters
Definition navigation.h:42
#define CARROT
default approaching_time for a wp
Definition navigation.h:70
struct EnuCoor_f target
final target position (in meters)
Definition navigation.h:126
#define ARRIVED_AT_WAYPOINT
minimum horizontal distance to waypoint to mark as arrived
Definition navigation.h:55
#define NAV_MODE_CIRCLE
Definition navigation.h:74
#define CARROT_DIST
Definition navigation.h:43
#define NAV_MODE_ROUTE
Definition navigation.h:73
#define NAV_MODE_WAYPOINT
Nav modes.
Definition navigation.h:72
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
int int32_t
Typedef defining 32 bit int type.