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_poles_rotorcraft.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 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
33
35
36// local variables
38static float oval_radius;
40
41#if USE_MISSION
43
44static bool nav_poles_mission(uint8_t nb, float *params, enum MissionRunFlag flag)
45{
46 if (flag == MissionInit && nb == 6) {
47 uint8_t wp1_id = (uint8_t)(params[0]);
48 uint8_t wp2_id = (uint8_t)(params[1]);
49 float height = params[2];
50 float radius = params[3];
51 float margin = params[4];
52 int8_t nb_laps = (uint8_t)(params[5]);
53 if (nav_poles_setup_wp(wp1_id, wp2_id, height, radius, margin, nb_laps)) {
54 return nav_poles_run();
55 } else {
56 return false;
57 }
58 } else if (flag == MissionInit && nb == 8) {
59 float height = params[4];
60 struct LlaCoor_f lla1 = {
61 .lat = RadOfDeg(params[0]),
62 .lon = RadOfDeg(params[1]),
63 .alt = stateGetLlaOrigin_f().alt + height
64 };
65 struct LlaCoor_f lla2 = {
66 .lat = RadOfDeg(params[2]),
67 .lon = RadOfDeg(params[3]),
68 .alt = stateGetLlaOrigin_f().alt + height
69 };
70 float radius = params[5];
71 float margin = params[6];
72 int8_t nb_laps = (uint8_t)(params[7]);
73 if (nav_poles_setup_lla(&lla1, &lla2, height, radius, margin, nb_laps)) {
74 return nav_poles_run();
75 } else {
76 return false;
77 }
78 } else if (flag == MissionRun) {
79 return nav_poles_run();
80 }
81 return false; // not a valid case
82}
83#endif
84
86{
88 nav_poles_nb_laps = -1; // no limit
89 oval_radius = 0.f;
90
91#if USE_MISSION
93#endif
94}
95
96static bool compute_oval_points(struct EnuCoor_f *enu1, struct EnuCoor_f *enu2, float height, float radius, float margin)
97{
98 float dx = enu2->x - enu1->x;
99 float dy = enu2->y - enu1->y;
100 float d = sqrtf(dx * dx + dy * dy);
101 if (d < 0.001f) {
102 return false;
103 }
104
105 /* Unit vector from wp1 to wp2 */
106 dx /= d;
107 dy /= d;
108
109 oval_wp1.x = enu1->x + (dx * (1.f - margin) - dy) * radius;
110 oval_wp1.y = enu1->y + (dy * (1.f - margin) + dx) * radius;
111 oval_wp1.z = height;
112
113 oval_wp2.x = enu2->x - (dx * (1.f - margin) + dy) * radius;
114 oval_wp2.y = enu2->y - (dy * (1.f - margin) - dx) * radius;
115 oval_wp2.z = height;
116
117 oval_radius = radius;
118 NavVerticalAltitudeMode(height, 0.f);
119
120 return true;
121}
122
124 float radius, float margin, int8_t nb_laps)
125{
128 if (enu1 == NULL || enu2 == NULL) {
129 return false;
130 }
132 return compute_oval_points(enu1, enu2, height, radius, margin);
133}
134
135bool nav_poles_setup_lla(struct LlaCoor_f *lla1, struct LlaCoor_f *lla2, float height,
136 float radius, float margin, int8_t nb_laps)
137{
138 struct EnuCoor_f enu1;
139 struct EnuCoor_f enu2;
143 return compute_oval_points(&enu1, &enu2, height, radius, margin);
144}
145
147{
149#ifdef NavOvalCount
151 if (nav_poles_nb_laps < 0) {
152 return true;
153 } else {
155 }
156#else
157 return true;
158#endif
159}
160
161
static struct LtpDef_f * stateGetNedOrigin_f(void)
Get the coordinate NED frame origin (float)
Definition state.h:566
struct LlaCoor_f stateGetLlaOrigin_f(void)
Get the LLA position of the frame origin (float)
Definition state.c:143
uint16_t foo
Definition main_demo5.c:58
bool mission_register(mission_custom_cb cb, char *type)
Register a new navigation or action callback function.
mission planner library
MissionRunFlag
@ MissionInit
first exec
@ MissionRun
normal run
struct EnuCoor_f * waypoint_get_enu_f(uint8_t wp_id)
Get ENU coordinates (float)
Definition waypoints.c:387
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
Definition nav.h:191
uint8_t nav_poles_count
bool nav_poles_run(void)
bool nav_poles_setup_wp(uint8_t wp1, uint8_t wp2, float height, float radius, float margin, int8_t nb_laps)
Init poles from flight plan waypoints.
bool nav_poles_setup_lla(struct LlaCoor_f *lla1, struct LlaCoor_f *lla2, float height, float radius, float margin, int8_t nb_laps)
Init poles from waypoints coordinates in LLA format.
static float oval_radius
static int8_t nav_poles_nb_laps
static struct EnuCoor_f oval_wp1 oval_wp2
void nav_poles_init(void)
Global init.
static bool compute_oval_points(struct EnuCoor_f *enu1, struct EnuCoor_f *enu2, float height, float radius, float margin)
Turn around 2 points, with possible margins Can be used in mission mode.
#define NavOvalCount
void enu_of_lla_point_f(struct EnuCoor_f *enu, struct LtpDef_f *def, struct LlaCoor_f *lla)
float alt
in meters (normally above WGS84 reference ellipsoid)
float y
in meters
float x
in meters
float lat
in radians
float z
in meters
vector in East North Up coordinates Units: meters
vector in Latitude, Longitude and Altitude
struct RotorcraftNavigation nav
Definition navigation.c:51
Rotorcraft navigation functions.
navigation_oval nav_oval
Definition navigation.h:156
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.