Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
waypoints.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Felix Ruess <felix.ruess@gmail.com>
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
27#include "state.h"
29#include "generated/flight_plan.h"
30
33
34#if PERIODIC_TELEMETRY
36#include "math/pprz_random.h"
37
38static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
39{
40 static uint8_t i;
41 i++;
42
43 // Randomness added for multiple transport devices
44 if (rand_uniform() > 0.02) { i++; }
45
46 if (i >= nb_waypoint) { i = 0; }
48 &i,
49 &(waypoints[i].enu_i.x),
50 &(waypoints[i].enu_i.y),
51 &(waypoints[i].enu_i.z));
52}
53#endif
54
57{
60 /* element in array is TRUE if absolute/global waypoint */
62 uint8_t i = 0;
63 for (i = 0; i < nb_waypoint; i++) {
64 /* clear all flags */
65 waypoints[i].flags = 0;
66 /* init waypoint as global LLA or local ENU */
67 if (is_global[i]) {
70 } else {
72 }
73 }
74
75#if PERIODIC_TELEMETRY
77#endif
78}
79
81{
82 if (wp_id < nb_waypoint) {
83 return bit_is_set(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
84 }
85 return false;
86}
87
89{
90 if (wp_id < nb_waypoint) {
91 SetBit(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
92 }
93}
94
96{
97 if (wp_id < nb_waypoint) {
98 ClearBit(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
99 }
100}
101
103{
104 if (wp_id < nb_waypoint) {
105 return waypoints[wp_id].enu_f.x;
106 }
107 return 0.f;
108}
109
111{
112 if (wp_id < nb_waypoint) {
113 return waypoints[wp_id].enu_f.y;
114 }
115 return 0.f;
116}
117
119{
120 if (wp_id < nb_waypoint) {
121 return waypoints[wp_id].enu_f.z;
122 }
123 return 0.f;
124}
125
127{
128 if (wp_id < nb_waypoint) {
129 return waypoints[wp_id].lla.alt/1000.f - stateGetLlaOrigin_i().alt/1000.f;
130 }
131 return 0.f;
132}
133
135{
136 if (wp_id < nb_waypoint) {
137 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
138 waypoint_globalize(wp_id);
139 }
140 return DEG_OF_EM7DEG(waypoints[wp_id].lla.lat);
141 }
142 else {
143 return 0.f;
144 }
145}
146
148{
149 return RadOfDeg(waypoint_get_lat_deg(wp_id));
150}
151
153{
154 if (wp_id < nb_waypoint) {
155 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
156 waypoint_globalize(wp_id);
157 }
158 return DEG_OF_EM7DEG(waypoints[wp_id].lla.lon);
159 }
160 else {
161 return 0.f;
162 }
163}
164
166{
167 return RadOfDeg(waypoint_get_lon_deg(wp_id));
168}
169
171{
172 if (wp_id < nb_waypoint) {
173 waypoints[wp_id].enu_i = *enu;
174 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
175 ENU_FLOAT_OF_BFP(waypoints[wp_id].enu_f, waypoints[wp_id].enu_i);
176 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
177 ClearBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
178 waypoint_globalize(wp_id);
179 }
180}
181
183{
184 if (wp_id < nb_waypoint) {
185 waypoints[wp_id].enu_f = *enu;
186 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
187 ENU_BFP_OF_REAL(waypoints[wp_id].enu_i, waypoints[wp_id].enu_f);
188 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
189 ClearBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
190 waypoint_globalize(wp_id);
191 }
192}
193
195{
196 if (wp_id < nb_waypoint) {
199 &(new_pos->y), &(new_pos->z));
200 }
201}
202
208{
209 if (wp_id < nb_waypoint) {
210 waypoints[wp_id].enu_i.x = x;
211 waypoints[wp_id].enu_i.y = y;
212 /* also update ENU float representation */
213 waypoints[wp_id].enu_f.x = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.x);
214 waypoints[wp_id].enu_f.y = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.y);
215 waypoint_globalize(wp_id);
216 }
217}
218
220{
221 if (wp_id < nb_waypoint) {
222 waypoint_set_xy_i(wp_id, x, y);
224 &(waypoints[wp_id].enu_i.z));
225 }
226}
227
229{
230 if (wp_id < nb_waypoint) {
231 waypoints[wp_id].enu_i.z = alt;
232 /* also update ENU float representation */
233 waypoints[wp_id].enu_f.z = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.z);
234 waypoint_globalize(wp_id);
235 }
236}
237
238void waypoint_set_alt(uint8_t wp_id, float alt)
239{
240 if (wp_id < nb_waypoint) {
241 waypoints[wp_id].enu_f.z = alt;
242 /* also update ENU fixed point representation */
243 waypoints[wp_id].enu_i.z = POS_BFP_OF_REAL(waypoints[wp_id].enu_f.z);
244 waypoint_globalize(wp_id);
245 }
246}
247
248void waypoint_set_lla(uint8_t wp_id, struct LlaCoor_i *lla)
249{
250 if (wp_id >= nb_waypoint) {
251 return;
252 }
253 waypoints[wp_id].lla = *lla;
254 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
255 waypoint_localize(wp_id);
256}
257
258void waypoint_move_lla(uint8_t wp_id, struct LlaCoor_i *lla)
259{
260 if (wp_id >= nb_waypoint) {
261 return;
262 }
263 waypoint_set_lla(wp_id, lla);
264 if (waypoint_is_global(wp_id)) {
265 /* lla->alt is above ellipsoid, WP_MOVED_LLA has hmsl alt */
268 &lla->lat, &lla->lon, &hmsl);
269 } else {
271 &waypoints[wp_id].enu_i.x,
272 &waypoints[wp_id].enu_i.y,
273 &waypoints[wp_id].enu_i.z);
274 }
275}
276
278void waypoint_set_latlon(uint8_t wp_id, struct LlaCoor_i *lla)
279{
280 if (wp_id >= nb_waypoint) {
281 return;
282 }
283 waypoints[wp_id].lla.lat = lla->lat;
284 waypoints[wp_id].lla.lon = lla->lon;
285 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
286 waypoint_localize(wp_id);
287}
288
291{
292 if (wp_id >= nb_waypoint) {
293 return;
294 }
295 if (waypoint_is_global(wp_id)) {
297 } else {
299 }
300}
301
304{
305 if (wp_id >= nb_waypoint) {
306 return;
307 }
308 if (waypoint_is_global(wp_id)) {
310 } else {
312 }
313}
314
316{
317 if (wp_id >= nb_waypoint) {
318 return;
319 }
320 if (waypoint_is_global(wp_id)) {
321 /* lla->alt is above ellipsoid, WP_MOVED_LLA has hmsl alt */
322 struct LlaCoor_i *lla = &(waypoints[wp_id].lla);
325 &lla->lat, &lla->lon, &hmsl);
326 } else {
328 &waypoints[wp_id].enu_i.x,
329 &waypoints[wp_id].enu_i.y,
330 &waypoints[wp_id].enu_i.z);
331 }
332}
333
335{
337 struct EcefCoor_i ecef;
338 ecef_of_enu_pos_i(&ecef, stateGetNedOrigin_i(), &waypoints[wp_id].enu_i);
339 lla_of_ecef_i(&waypoints[wp_id].lla, &ecef);
340 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
341 }
342}
343
346{
348 struct EnuCoor_i enu;
350 // convert ENU pos from cm to BFP with INT32_POS_FRAC
351 enu.x = POS_BFP_OF_REAL((int64_t) enu.x) / 100;
352 enu.y = POS_BFP_OF_REAL((int64_t) enu.y) / 100;
353 enu.z = POS_BFP_OF_REAL((int64_t) enu.z) / 100;
354 waypoints[wp_id].enu_i = enu;
355 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
356 ENU_FLOAT_OF_BFP(waypoints[wp_id].enu_f, waypoints[wp_id].enu_i);
357 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
358 }
359}
360
363{
364 uint8_t i = 0;
365 for (i = 0; i < nb_waypoint; i++) {
366 if (waypoint_is_global(i)) {
368 }
369 }
370}
371
380{
381 if (wp_id < nb_waypoint) {
382 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
383 waypoint_globalize(wp_id);
384 }
385 return &waypoints[wp_id].lla;
386 }
387 else {
388 return NULL;
389 }
390}
391
393{
394 if (wp_id < nb_waypoint) {
395 if (waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_ENU_F)) {
396 waypoint_localize(wp_id);
397 }
398 return &waypoints[wp_id].enu_f;
399 }
400 else {
401 return NULL;
402 }
403}
404
406{
407 if (wp_id < nb_waypoint) {
408 if (waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_ENU_I)) {
409 waypoint_localize(wp_id);
410 }
411 return &waypoints[wp_id].enu_i;
412 }
413 else {
414 return NULL;
415 }
416}
417
424
#define POS_FLOAT_OF_BFP(_ai)
#define POS_BFP_OF_REAL(_af)
int32_t lat
in degrees*1e7
int32_t y
North.
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
Up.
int32_t x
East.
int32_t lon
in degrees*1e7
#define ENU_FLOAT_OF_BFP(_o, _i)
#define ENU_BFP_OF_REAL(_o, _i)
#define DEG_OF_EM7DEG(_r)
void ecef_of_enu_pos_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct EnuCoor_i *enu)
Convert a local ENU position to ECEF.
void enu_of_lla_point_i(struct EnuCoor_i *enu, struct LtpDef_i *def, struct LlaCoor_i *lla)
Convert a point from LLA to local ENU.
void lla_of_ecef_i(struct LlaCoor_i *out, struct EcefCoor_i *in)
Convert a ECEF to LLA.
vector in EarthCenteredEarthFixed coordinates
vector in East North Up coordinates
vector in Latitude, Longitude and Altitude
struct State state
Definition state.c:36
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
Definition state.h:812
bool ned_initialized_i
true if local int coordinate frame is initialsed
Definition state.h:199
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition state.h:803
int32_t stateGetHmslOrigin_i(void)
Get the HMSL of the frame origin (int)
Definition state.c:190
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int)
Definition state.c:124
static struct LtpDef_i * stateGetNedOrigin_i(void)
Get the coordinate NED frame origin (int)
Definition state.h:556
uint16_t foo
Definition main_demo5.c:58
void waypoint_copy(uint8_t wp_dest, uint8_t wp_src)
copy one waypoint to another, this includes all flags from the source waypoint
Definition waypoints.c:418
void waypoint_globalize(uint8_t wp_id)
update global LLA coordinates from its ENU coordinates
Definition waypoints.c:334
void waypoint_set_here_2d(uint8_t wp_id)
set waypoint to current horizontal location without modifying altitude
Definition waypoints.c:303
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
Definition waypoints.c:362
void waypoint_position_copy(uint8_t wp_dest, uint8_t wp_src)
Definition waypoints.c:425
struct EnuCoor_i * waypoint_get_enu_i(uint8_t wp_id)
Get ENU coordinates (integer)
Definition waypoints.c:405
struct LlaCoor_i * waypoint_get_lla(uint8_t wp_id)
Get LLA coordinates of waypoint.
Definition waypoints.c:379
void waypoint_move_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Definition waypoints.c:219
bool waypoint_is_global(uint8_t wp_id)
Definition waypoints.c:80
float waypoint_get_lon_rad(uint8_t wp_id)
Get longitude of waypoint in rad.
Definition waypoints.c:165
float waypoint_get_alt(uint8_t wp_id)
Get altitude of waypoint in meters (above reference)
Definition waypoints.c:118
float waypoint_get_x(uint8_t wp_id)
Get X/East coordinate of waypoint in meters.
Definition waypoints.c:102
struct EnuCoor_f * waypoint_get_enu_f(uint8_t wp_id)
Get ENU coordinates (float)
Definition waypoints.c:392
void waypoint_set_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Set only local XY coordinates of waypoint without update altitude.
Definition waypoints.c:207
void waypoint_set_here(uint8_t wp_id)
set waypoint to current location and altitude
Definition waypoints.c:290
float waypoint_get_lon_deg(uint8_t wp_id)
Get longitude of waypoint in deg.
Definition waypoints.c:152
void waypoint_set_global_flag(uint8_t wp_id)
Definition waypoints.c:88
void waypoint_set_latlon(uint8_t wp_id, struct LlaCoor_i *lla)
set waypoint latitude/longitude without updating altitude
Definition waypoints.c:278
void waypoints_init(void)
initialize global and local waypoints
Definition waypoints.c:56
float waypoint_get_lla_alt(uint8_t wp_id)
Definition waypoints.c:126
float waypoint_get_lat_deg(uint8_t wp_id)
Get latitude of waypoint in deg.
Definition waypoints.c:134
void waypoint_move_enu_i(uint8_t wp_id, struct EnuCoor_i *new_pos)
Definition waypoints.c:194
float waypoint_get_y(uint8_t wp_id)
Get Y/North coordinate of waypoint in meters.
Definition waypoints.c:110
const uint8_t nb_waypoint
Definition waypoints.c:31
void waypoint_set_enu_i(uint8_t wp_id, struct EnuCoor_i *enu)
Definition waypoints.c:170
void waypoint_clear_global_flag(uint8_t wp_id)
Definition waypoints.c:95
void waypoint_set_lla(uint8_t wp_id, struct LlaCoor_i *lla)
Definition waypoints.c:248
void waypoint_set_alt_i(uint8_t wp_id, int32_t alt)
Definition waypoints.c:228
void waypoint_move_here_2d(uint8_t wp_id)
Definition waypoints.c:315
struct Waypoint waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition waypoints.c:32
void waypoint_localize(uint8_t wp_id)
update local ENU coordinates from its LLA coordinates
Definition waypoints.c:345
void waypoint_set_alt(uint8_t wp_id, float alt)
Set altitude of waypoint in meters (above reference)
Definition waypoints.c:238
static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
Definition waypoints.c:38
void waypoint_move_lla(uint8_t wp_id, struct LlaCoor_i *lla)
Definition waypoints.c:258
float waypoint_get_lat_rad(uint8_t wp_id)
Get latitude of waypoint in rad.
Definition waypoints.c:147
void waypoint_set_enu(uint8_t wp_id, struct EnuCoor_f *enu)
Set local ENU waypoint coordinates.
Definition waypoints.c:182
struct LlaCoor_i lla
Definition waypoints.h:46
#define WP_FLAG_ENU_I
Definition waypoints.h:38
#define WP_FLAG_GLOBAL
Definition waypoints.h:37
uint8_t flags
bitmask encoding valid representations and if local or global
Definition waypoints.h:43
struct EnuCoor_i enu_i
with INT32_POS_FRAC
Definition waypoints.h:44
struct EnuCoor_f enu_f
Definition waypoints.h:45
#define WP_FLAG_ENU_F
Definition waypoints.h:39
#define WP_FLAG_LLA_I
Definition waypoints.h:40
float y
in meters
float x
in meters
float z
in meters
vector in East North Up coordinates Units: meters
double rand_uniform(void)
Definition pprz_random.c:45
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.