Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mission_rover_nav.c
Go to the documentation of this file.
1
8#include <stdio.h>
10#include "autopilot.h"
12#include "generated/flight_plan.h"
13
14// Buffer zone in [m] before MAX_DIST_FROM_HOME
15#define BUFFER_ZONE_DIST 10
16
19{
20 // return FALSE if there is no valid local coordinate system
22 return false;
23 }
24
25 // For a rover, GPS z altitude is ignored. The altitude is forced to 0.
26 lla->alt = 0;
27
28 // Compute ENU components from LLA with respect to ltp origin
32 // result of enu_of_lla_point_i is in cm, convert to float in m
34
35 // Bound the new waypoint with max distance from home
36 struct FloatVect2 home;
37 home.x = waypoint_get_x(WP_HOME);
38 home.y = waypoint_get_y(WP_HOME);
41
42 // Saturate the mission wp not to overflow max_dist_from_home
43 // including a buffer zone before limits
48 }
49 // set new point (2D)
50 point->x = home.x + vect_from_home.x;
51 point->y = home.y + vect_from_home.y;
52 point->z = 0.0f; // to be sure the altitude is at 0
53
54 return true;
55}
56
57// navigation time step
58static const float dt_navigation = 1.0f / ((float)NAVIGATION_FREQUENCY);
59
60// last_mission_wp, last target wp from mission elements, not used actively and kept for future implementations
61struct EnuCoor_f last_mission_wp = { 0.f, 0.f, 0.f };
62
65static inline bool mission_nav_wp(struct _mission_element *el)
66{
67 struct EnuCoor_f *target_wp = &(el->element.mission_wp.wp);
68
69 //Check proximity and wait for 'duration' seconds in proximity circle if desired
72
73 if (el->duration > 0.f) {
74 if (nav_check_wp_time(target_wp, el->duration)) { return false; }
75 } else { return false; }
76
77 }
78 //Go to Mission Waypoint
80
81 return true;
82}
83
87static inline bool mission_nav_circle(struct _mission_element *el)
88{
89 struct EnuCoor_f *center_wp = &(el->element.mission_circle.center);
90 float radius = el->element.mission_circle.radius;
91
92 //Draw the desired circle for a 'duration' time
93 nav.nav_circle(center_wp, radius);
94
95 if (el->duration > 0.f && mission.element_time >= el->duration) {
96 return false;
97 }
98
99 if (el-> duration <= 0.f){
100 return false;
101 }
102
103 return true;
104}
105
106
109static inline bool mission_nav_segment(struct _mission_element *el)
110{
111 struct EnuCoor_f *from_wp = &(el->element.mission_segment.from);
112 struct EnuCoor_f *to_wp = &(el->element.mission_segment.to);
113
114 //Check proximity and wait for 'duration' seconds in proximity circle if desired
115 if (nav.nav_approaching(to_wp, from_wp, CARROT)) {
116 last_mission_wp = *to_wp;
117
118 if (el->duration > 0.f) {
119 if (nav_check_wp_time(to_wp, el->duration)) { return false; }
120 } else { return false; }
121 }
122
123 //Route Between from-to
124 nav.nav_route(from_wp, to_wp);
125
126 return true;
127}
128
129
130#ifndef MISSION_PATH_SKIP_GOTO
131#define MISSION_PATH_SKIP_GOTO FALSE
132#endif
133
136static inline bool mission_nav_path(struct _mission_element *el)
137{
138 if (el->element.mission_path.nb == 0) {
139 return false; // nothing to do
140 }
141
142 if (el->element.mission_path.path_idx == 0) { //first wp of path
143 el->element.mission_wp.wp = el->element.mission_path.path[0];
144 if (MISSION_PATH_SKIP_GOTO || !mission_nav_wp(el)) { el->element.mission_path.path_idx++; }
145 }
146
147 else if (el->element.mission_path.path_idx < el->element.mission_path.nb) { //standart wp of path
148
149 struct EnuCoor_f *from_wp = &(el->element.mission_path.path[(el->element.mission_path.path_idx) - 1]);
150 struct EnuCoor_f *to_wp = &(el->element.mission_path.path[el->element.mission_path.path_idx]);
151
152 //Check proximity and wait for t seconds in proximity circle if desired
153 if (nav.nav_approaching(to_wp, from_wp, CARROT)) {
154 last_mission_wp = *to_wp;
155
156 if (el->duration > 0.f) {
157 if (nav_check_wp_time(to_wp, el->duration)) {
158 el->element.mission_path.path_idx++;
159 }
160 } else { el->element.mission_path.path_idx++; }
161 }
162 //Route Between from-to
163 nav.nav_route(from_wp, to_wp);
164 } else { return false; } //end of path
165
166 return true;
167}
168
171static inline bool mission_nav_custom(struct _mission_custom *custom, bool init)
172{
173 if (init) {
174 return custom->reg->cb(custom->nb, custom->params, MissionInit);
175 } else {
176 return custom->reg->cb(custom->nb, custom->params, MissionRun);
177 }
178}
179
183#ifndef MISSION_WAIT_TIMEOUT
184#define MISSION_WAIT_TIMEOUT 30 // wait 30 seconds before ending mission
185#endif
186
187static bool mission_wait_started = false;
188#if MISSION_WAIT_TIMEOUT
189static float mission_wait_time = 0.f;
191static bool mission_wait_pattern(void) {
194 mission_wait_time = 0.f;
196 }
199
200 return (mission_wait_time < (float)MISSION_WAIT_TIMEOUT); // keep flying until TIMEOUT
201}
202#else
203static bool mission_wait_pattern(void) {
204 return false; // no TIMEOUT, end mission now
205}
206#endif
207
209{
210 // current element
211 struct _mission_element *el = NULL;
212 if ((el = mission_get()) == NULL) {
213 return mission_wait_pattern();
214 }
215 mission_wait_started = false;
216 bool el_running = false;
217
218 switch (el->type) {
219 case MissionWP:
221 break;
222
223 case MissionCircle:
225 break;
226
227 case MissionSegment:
229 break;
230
231 case MissionPath:
233 break;
234
235 case MissionCustom:
236 el_running = mission_nav_custom(&(el->element.mission_custom), mission.element_time < dt_navigation);
237 break;
238
239 default:
240 // invalid type or pattern not yet handled
241 break;
242 }
243
244 // increment element_time
246
247 if (!el_running) {
248 // reset timer
250 // go to next element
252 }
253 return true;
254}
255
Core autopilot interface common to all firmwares.
float y
Definition common_nav.h:41
float x
Definition common_nav.h:40
static float float_vect2_norm(struct FloatVect2 *v)
#define VECT2_SMUL(_vo, _vi, _s)
#define VECT2_DIFF(_c, _a, _b)
#define VECT3_SMUL(_vo, _vi, _s)
int32_t alt
in millimeters above WGS84 reference ellipsoid
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.
vector in East North Up coordinates
vector in Latitude, Longitude and Altitude
struct State state
Definition state.c:36
bool ned_initialized_i
true if local int coordinate frame is initialsed
Definition state.h:199
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
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
struct _mission mission
struct _mission_element * mission_get(void)
Get current mission element.
mission planner library
union _mission_element::@299 element
@ MissionCustom
@ MissionCircle
@ MissionWP
@ MissionSegment
@ MissionPath
@ MissionInit
first exec
@ MissionRun
normal run
float element_time
time in second spend in the current element
#define MISSION_ELEMENT_NB
Max number of elements in the tasks' list can be redefined.
uint8_t current_idx
current mission element index
static bool mission_wait_pattern(void)
struct EnuCoor_f last_mission_wp
static bool mission_nav_wp(struct _mission_element *el)
Navigation function to a single waypoint (2D)
static bool mission_nav_segment(struct _mission_element *el)
Navigation function along a segment (2D)
static bool mission_nav_circle(struct _mission_element *el)
Navigation function on a circle.
static bool mission_nav_custom(struct _mission_custom *custom, bool init)
Call custom navigation function.
int mission_run()
Run mission.
bool mission_point_of_lla(struct EnuCoor_f *point, struct LlaCoor_i *lla)
Utility function: converts lla (int) to local point (float)
#define BUFFER_ZONE_DIST
static const float dt_navigation
#define MISSION_WAIT_TIMEOUT
Implement waiting pattern Only called when MISSION_WAIT_TIMEOUT is not 0.
static bool mission_nav_path(struct _mission_element *el)
Navigation function along a path (2D)
#define MISSION_PATH_SKIP_GOTO
static bool mission_wait_started
float waypoint_get_x(uint8_t wp_id)
Get X/East coordinate of waypoint in meters.
Definition waypoints.c:102
float waypoint_get_y(uint8_t wp_id)
Get Y/North coordinate of waypoint in meters.
Definition waypoints.c:110
#define NAVIGATION_FREQUENCY
Default fixedwing navigation frequency.
Definition nav.h:49
bool init
Definition nav_gls.c:57
vector in East North Up coordinates Units: meters
struct RotorcraftNavigation nav
Definition navigation.c:51
bool nav_check_wp_time(struct EnuCoor_f *wp, uint16_t stay_time)
Check the time spent in a radius of 'ARRIVED_AT_WAYPOINT' around a wp
Definition navigation.c:180
navigation_approaching nav_approaching
Definition navigation.h:153
navigation_circle nav_circle
Definition navigation.h:154
#define CARROT
default approaching_time for a wp
Definition navigation.h:70
navigation_goto nav_goto
Definition navigation.h:151
navigation_route nav_route
Definition navigation.h:152
Rover navigation functions.