Paparazzi UAS v7.1_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
31#if FLIGHTRECORDER_SDLOG
34#endif
35
38
40{
42#if FLIGHTRECORDER_SDLOG
44 &wp_id, &x, &y, &z);
45#endif
46}
47
48static void waypoint_send_moved_lla(uint8_t wp_id, int32_t lat, int32_t lon, int32_t hmsl)
49{
50 DOWNLINK_SEND_WP_MOVED_LLA(DefaultChannel, DefaultDevice, &wp_id, &lat, &lon, &hmsl);
51#if FLIGHTRECORDER_SDLOG
53 &wp_id, &lat, &lon, &hmsl);
54#endif
55}
56
57#if PERIODIC_TELEMETRY
59#include "math/pprz_random.h"
60
61static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
62{
63 static uint8_t i;
64
65 // Randomness added for multiple transport devices
66 if (rand_uniform() > 0.02f) { i++; }
67
68 if (i >= nb_waypoint) { i = 0; }
70 &i,
71 &(waypoints[i].enu_i.x),
72 &(waypoints[i].enu_i.y),
73 &(waypoints[i].enu_i.z));
74}
75#endif
76
79{
82 /* element in array is TRUE if absolute/global waypoint */
84 uint8_t i = 0;
85 for (i = 0; i < nb_waypoint; i++) {
86 /* clear all flags */
87 waypoints[i].flags = 0;
88 /* init waypoint as global LLA or local ENU */
89 if (is_global[i]) {
92 } else {
94 }
95 }
96
97#if PERIODIC_TELEMETRY
99#endif
100}
101
103{
104 if (wp_id < nb_waypoint) {
105 return bit_is_set(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
106 }
107 return false;
108}
109
111{
112 if (wp_id < nb_waypoint) {
113 SetBit(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
114 }
115}
116
118{
119 if (wp_id < nb_waypoint) {
120 ClearBit(waypoints[wp_id].flags, WP_FLAG_GLOBAL);
121 }
122}
123
125{
126 if (wp_id < nb_waypoint) {
127 return waypoints[wp_id].enu_f.x;
128 }
129 return 0.f;
130}
131
133{
134 if (wp_id < nb_waypoint) {
135 return waypoints[wp_id].enu_f.y;
136 }
137 return 0.f;
138}
139
141{
142 if (wp_id < nb_waypoint) {
143 return waypoints[wp_id].enu_f.z;
144 }
145 return 0.f;
146}
147
149{
150 if (wp_id < nb_waypoint) {
151 return waypoints[wp_id].lla.alt/1000.f - stateGetLlaOrigin_i().alt/1000.f;
152 }
153 return 0.f;
154}
155
157{
158 if (wp_id < nb_waypoint) {
159 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
160 waypoint_globalize(wp_id);
161 }
162 return DEG_OF_EM7DEG(waypoints[wp_id].lla.lat);
163 }
164 else {
165 return 0.f;
166 }
167}
168
170{
171 return RadOfDeg(waypoint_get_lat_deg(wp_id));
172}
173
175{
176 if (wp_id < nb_waypoint) {
177 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
178 waypoint_globalize(wp_id);
179 }
180 return DEG_OF_EM7DEG(waypoints[wp_id].lla.lon);
181 }
182 else {
183 return 0.f;
184 }
185}
186
188{
189 return RadOfDeg(waypoint_get_lon_deg(wp_id));
190}
191
193{
194 if (wp_id < nb_waypoint) {
195 waypoints[wp_id].enu_i = *enu;
196 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
197 ENU_FLOAT_OF_BFP(waypoints[wp_id].enu_f, waypoints[wp_id].enu_i);
198 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
199 ClearBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
200 waypoint_globalize(wp_id);
201 }
202}
203
205{
206 if (wp_id < nb_waypoint) {
207 waypoints[wp_id].enu_f = *enu;
208 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
209 ENU_BFP_OF_REAL(waypoints[wp_id].enu_i, waypoints[wp_id].enu_f);
210 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
211 ClearBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
212 waypoint_globalize(wp_id);
213 }
214}
215
217{
218 if (wp_id < nb_waypoint) {
221 }
222}
223
229{
230 if (wp_id < nb_waypoint) {
231 waypoints[wp_id].enu_i.x = x;
232 waypoints[wp_id].enu_i.y = y;
233 /* also update ENU float representation */
234 waypoints[wp_id].enu_f.x = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.x);
235 waypoints[wp_id].enu_f.y = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.y);
236 waypoint_globalize(wp_id);
237 }
238}
239
241{
242 if (wp_id < nb_waypoint) {
243 waypoint_set_xy_i(wp_id, x, y);
244 waypoint_send_moved_enu(wp_id, x, y, waypoints[wp_id].enu_i.z);
245 }
246}
247
249{
250 if (wp_id < nb_waypoint) {
251 waypoints[wp_id].enu_i.z = alt;
252 /* also update ENU float representation */
253 waypoints[wp_id].enu_f.z = POS_FLOAT_OF_BFP(waypoints[wp_id].enu_i.z);
254 waypoint_globalize(wp_id);
255 }
256}
257
258void waypoint_set_alt(uint8_t wp_id, float alt)
259{
260 if (wp_id < nb_waypoint) {
261 waypoints[wp_id].enu_f.z = alt;
262 /* also update ENU fixed point representation */
263 waypoints[wp_id].enu_i.z = POS_BFP_OF_REAL(waypoints[wp_id].enu_f.z);
264 waypoint_globalize(wp_id);
265 }
266}
267
268void waypoint_set_lla(uint8_t wp_id, struct LlaCoor_i *lla)
269{
270 if (wp_id >= nb_waypoint) {
271 return;
272 }
273 waypoints[wp_id].lla = *lla;
274 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
275 waypoint_localize(wp_id);
276}
277
278void waypoint_move_lla(uint8_t wp_id, struct LlaCoor_i *lla)
279{
280 if (wp_id >= nb_waypoint) {
281 return;
282 }
283 waypoint_set_lla(wp_id, lla);
284 if (waypoint_is_global(wp_id)) {
285 /* lla->alt is above ellipsoid, WP_MOVED_LLA has hmsl alt */
287 waypoint_send_moved_lla(wp_id, lla->lat, lla->lon, hmsl);
288 } else {
289 waypoint_send_moved_enu(wp_id, waypoints[wp_id].enu_i.x,
290 waypoints[wp_id].enu_i.y, waypoints[wp_id].enu_i.z);
291 }
292}
293
295void waypoint_set_latlon(uint8_t wp_id, struct LlaCoor_i *lla)
296{
297 if (wp_id >= nb_waypoint) {
298 return;
299 }
300 waypoints[wp_id].lla.lat = lla->lat;
301 waypoints[wp_id].lla.lon = lla->lon;
302 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
303 waypoint_localize(wp_id);
304}
305
308{
309 if (wp_id >= nb_waypoint) {
310 return;
311 }
312 if (waypoint_is_global(wp_id)) {
314 } else {
316 }
317}
318
321{
322 if (wp_id >= nb_waypoint) {
323 return;
324 }
325 if (waypoint_is_global(wp_id)) {
327 } else {
329 }
330}
331
333{
334 if (wp_id >= nb_waypoint) {
335 return;
336 }
337 if (waypoint_is_global(wp_id)) {
338 /* lla->alt is above ellipsoid, WP_MOVED_LLA has hmsl alt */
339 struct LlaCoor_i *lla = &(waypoints[wp_id].lla);
341 waypoint_send_moved_lla(wp_id, lla->lat, lla->lon, hmsl);
342 } else {
343 waypoint_send_moved_enu(wp_id, waypoints[wp_id].enu_i.x,
344 waypoints[wp_id].enu_i.y, waypoints[wp_id].enu_i.z);
345 }
346}
347
349{
351 struct EcefCoor_i ecef;
352 ecef_of_enu_pos_i(&ecef, stateGetNedOrigin_i(), &waypoints[wp_id].enu_i);
353 lla_of_ecef_i(&waypoints[wp_id].lla, &ecef);
354 SetBit(waypoints[wp_id].flags, WP_FLAG_LLA_I);
355 }
356}
357
360{
362 struct EnuCoor_i enu;
364 // convert ENU pos from cm to BFP with INT32_POS_FRAC
365 enu.x = POS_BFP_OF_REAL((int64_t) enu.x) / 100;
366 enu.y = POS_BFP_OF_REAL((int64_t) enu.y) / 100;
367 enu.z = POS_BFP_OF_REAL((int64_t) enu.z) / 100;
368 waypoints[wp_id].enu_i = enu;
369 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_I);
370 ENU_FLOAT_OF_BFP(waypoints[wp_id].enu_f, waypoints[wp_id].enu_i);
371 SetBit(waypoints[wp_id].flags, WP_FLAG_ENU_F);
372 }
373}
374
377{
378 uint8_t i = 0;
379 for (i = 0; i < nb_waypoint; i++) {
380 if (waypoint_is_global(i)) {
382 }
383 }
384}
385
394{
395 if (wp_id < nb_waypoint) {
396 if (!waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_LLA_I)) {
397 waypoint_globalize(wp_id);
398 }
399 return &waypoints[wp_id].lla;
400 }
401 else {
402 return NULL;
403 }
404}
405
407{
408 if (wp_id < nb_waypoint) {
409 if (waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_ENU_F)) {
410 waypoint_localize(wp_id);
411 }
412 return &waypoints[wp_id].enu_f;
413 }
414 else {
415 return NULL;
416 }
417}
418
420{
421 if (wp_id < nb_waypoint) {
422 if (waypoint_is_global(wp_id) && !bit_is_set(waypoints[wp_id].flags, WP_FLAG_ENU_I)) {
423 waypoint_localize(wp_id);
424 }
425 return &waypoints[wp_id].enu_i;
426 }
427 else {
428 return NULL;
429 }
430}
431
438
static struct uart_periph * dev
#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:432
static void waypoint_send_moved_enu(uint8_t wp_id, int32_t x, int32_t y, int32_t z)
Definition waypoints.c:39
void waypoint_globalize(uint8_t wp_id)
update global LLA coordinates from its ENU coordinates
Definition waypoints.c:348
void waypoint_set_here_2d(uint8_t wp_id)
set waypoint to current horizontal location without modifying altitude
Definition waypoints.c:320
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
Definition waypoints.c:376
void waypoint_position_copy(uint8_t wp_dest, uint8_t wp_src)
Definition waypoints.c:439
struct EnuCoor_i * waypoint_get_enu_i(uint8_t wp_id)
Get ENU coordinates (integer)
Definition waypoints.c:419
struct LlaCoor_i * waypoint_get_lla(uint8_t wp_id)
Get LLA coordinates of waypoint.
Definition waypoints.c:393
static void waypoint_send_moved_lla(uint8_t wp_id, int32_t lat, int32_t lon, int32_t hmsl)
Definition waypoints.c:48
void waypoint_move_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Definition waypoints.c:240
bool waypoint_is_global(uint8_t wp_id)
Definition waypoints.c:102
float waypoint_get_lon_rad(uint8_t wp_id)
Get longitude of waypoint in rad.
Definition waypoints.c:187
float waypoint_get_alt(uint8_t wp_id)
Get altitude of waypoint in meters (above reference)
Definition waypoints.c:140
float waypoint_get_x(uint8_t wp_id)
Get X/East coordinate of waypoint in meters.
Definition waypoints.c:124
struct EnuCoor_f * waypoint_get_enu_f(uint8_t wp_id)
Get ENU coordinates (float)
Definition waypoints.c:406
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:228
void waypoint_set_here(uint8_t wp_id)
set waypoint to current location and altitude
Definition waypoints.c:307
float waypoint_get_lon_deg(uint8_t wp_id)
Get longitude of waypoint in deg.
Definition waypoints.c:174
void waypoint_set_global_flag(uint8_t wp_id)
Definition waypoints.c:110
void waypoint_set_latlon(uint8_t wp_id, struct LlaCoor_i *lla)
set waypoint latitude/longitude without updating altitude
Definition waypoints.c:295
void waypoints_init(void)
initialize global and local waypoints
Definition waypoints.c:78
float waypoint_get_lla_alt(uint8_t wp_id)
Definition waypoints.c:148
float waypoint_get_lat_deg(uint8_t wp_id)
Get latitude of waypoint in deg.
Definition waypoints.c:156
void waypoint_move_enu_i(uint8_t wp_id, struct EnuCoor_i *new_pos)
Definition waypoints.c:216
float waypoint_get_y(uint8_t wp_id)
Get Y/North coordinate of waypoint in meters.
Definition waypoints.c:132
const uint8_t nb_waypoint
Definition waypoints.c:36
void waypoint_set_enu_i(uint8_t wp_id, struct EnuCoor_i *enu)
Definition waypoints.c:192
void waypoint_clear_global_flag(uint8_t wp_id)
Definition waypoints.c:117
void waypoint_set_lla(uint8_t wp_id, struct LlaCoor_i *lla)
Definition waypoints.c:268
void waypoint_set_alt_i(uint8_t wp_id, int32_t alt)
Definition waypoints.c:248
void waypoint_move_here_2d(uint8_t wp_id)
Definition waypoints.c:332
struct Waypoint waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition waypoints.c:37
void waypoint_localize(uint8_t wp_id)
update local ENU coordinates from its LLA coordinates
Definition waypoints.c:359
void waypoint_set_alt(uint8_t wp_id, float alt)
Set altitude of waypoint in meters (above reference)
Definition waypoints.c:258
static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
Definition waypoints.c:61
void waypoint_move_lla(uint8_t wp_id, struct LlaCoor_i *lla)
Definition waypoints.c:278
float waypoint_get_lat_rad(uint8_t wp_id)
Get latitude of waypoint in rad.
Definition waypoints.c:169
void waypoint_set_enu(uint8_t wp_id, struct EnuCoor_f *enu)
Set local ENU waypoint coordinates.
Definition waypoints.c:204
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
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Definition pprzlog_tp.c:29
Initialize pprzlog transport.
API to get/set the generic vehicle states.
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.