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_survey_polygon_gvf.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 The Paparazzi Team
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, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
31
33#include "state.h"
34#include "autopilot.h"
35#include "generated/flight_plan.h"
37
38#ifdef DIGITAL_CAM
40#endif
41
43
46static void gvf_circle_direction(float rad)
47{
48 if (rad > 0) {
50 } else {
52 }
53}
54
63static bool gvf_intercept_two_lines(struct FloatVect2 *p, struct FloatVect2 x, struct FloatVect2 y, float a1, float a2,
64 float b1, float b2)
65{
66 float divider, fac;
67
68 divider = (((b2 - a2) * (y.x - x.x)) + ((x.y - y.y) * (b1 - a1)));
69 if (divider == 0) { return false; }
70 fac = ((y.x * (x.y - a2)) + (x.x * (a2 - y.y)) + (a1 * (y.y - x.y))) / divider;
71 if (fac > 1.0) { return false; }
72 if (fac < 0.0) { return false; }
73
74 p->x = a1 + fac * (b1 - a1);
75 p->y = a2 + fac * (b2 - a2);
76
77 return true;
78}
79
86static bool gvf_get_two_intersects(struct FloatVect2 *x, struct FloatVect2 *y, struct FloatVect2 a, struct FloatVect2 b)
87{
88 int i, count = 0;
89 struct FloatVect2 tmp;
90
91 for (i = 0; i < gvf_survey.poly_count - 1; i++)
94 if (count == 0) {
95 *x = tmp;
96 count++;
97 } else {
98 *y = tmp;
99 count++;
100 break;
101 }
102 }
103
104 //wrapover first,last polygon waypoint
105 if (count == 1
109 *y = tmp;
110 count++;
111 }
112
113 if (count != 2) {
114 return false;
115 }
116
117 //change points
119 if ((y->x - x->x) / gvf_survey.dir_vec.x < 0.0) {
120 tmp = *x;
121 *x = *y;
122 *y = tmp;
123 }
124 } else if ((y->y - x->y) / gvf_survey.dir_vec.y < 0.0) {
125 tmp = *x;
126 *x = *y;
127 *y = tmp;
128 }
129
130 return true;
131}
132
145void nav_gvf_survey_polygon_setup(uint8_t first_wp, uint8_t size, float angle, float sweep_width, float shot_dist,
146 float min_rad, float altitude)
147{
148 int i;
149 struct FloatVect2 small, sweep;
150 float divider, angle_rad = angle / 180.0 * M_PI;
151
152 if (angle < 0.0) { angle += 360.0; }
153 if (angle >= 360.0) { angle -= 360.0; }
154
156 gvf_survey.poly_count = size;
157
158 gvf_survey.psa_sweep_width = sweep_width;
162
164 gvf_survey.return_angle = angle + 180;
165 if (gvf_survey.return_angle > 359) { gvf_survey.return_angle -= 360; }
166
167 if (angle <= 45.0 || angle >= 315.0) {
168 //north
169 gvf_survey.dir_vec.y = 1.0;
171 sweep.x = 1.0;
173 } else if (angle <= 135.0) {
174 //east
175 gvf_survey.dir_vec.x = 1.0;
177 sweep.y = -1.0;
179 } else if (angle <= 225.0) {
180 //south
181 gvf_survey.dir_vec.y = -1.0;
183 sweep.x = -1.0;
185 } else {
186 //west
187 gvf_survey.dir_vec.x = -1.0;
189 sweep.y = 1.0;
191 }
192
193 //normalize
195
198
199 //begin at leftmost position (relative to gvf_survey.dir_vec)
201
203
204 //calculate the leftmost point if one sees the dir vec as going "up" and the sweep vec as going right
205 if (divider < 0.0) {
206 for (i = 1; i < gvf_survey.poly_count; i++) {
208 (small.x - waypoints[gvf_survey.poly_first + i].x)) > 0.0) {
210 }
211 }
212 } else {
213 for (i = 1; i < gvf_survey.poly_count; i++) {
215 (small.x - waypoints[gvf_survey.poly_first + i].x)) > 0.0) {
217 }
218 }
219 }
220
221 //calculate the line the defines the first flyover
225
228 return;
229 }
230
231 //center of the entry circle
233
234 //fast climbing to desired altitude
237
239}
240
247{
250
251 //entry circle around entry-center until the desired altitude is reached
252 if (gvf_survey.stage == gENTRY) {
260#ifdef DIGITAL_CAM
263#endif
264 }
265 }
266 //fly the segment until seg_end is reached
267 if (gvf_survey.stage == gSEG) {
269 //calculate all needed points for the next flyover
271#ifdef DIGITAL_CAM
272 dc_stop();
273#endif
277
278 //if we get no intersection the survey is finished
279 static struct FloatVect2 sum_start_sweep;
280 static struct FloatVect2 sum_end_sweep;
284 return false;
285 }
286
289
292
295 }
296 }
297 //turn from stage to return
298 else if (gvf_survey.stage == gTURN1) {
304 }
305 //return
306 } else if (gvf_survey.stage == gRET) {
311 }
312 //turn from return to stage
313 } else if (gvf_survey.stage == gTURN2) {
320#ifdef DIGITAL_CAM
323#endif
324 }
325 }
326
327 return true;
328}
static int32_t altitude
Core autopilot interface common to all firmwares.
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
uint8_t dc_survey(float interval, float x, float y)
Sets the dc control in distance mode.
Definition dc.c:240
uint8_t dc_stop(void)
Stop dc control.
Definition dc.c:262
Standard Digital Camera Control Interface.
#define FLOAT_VECT2_NORMALIZE(_v)
#define VECT2_SMUL(_vo, _vi, _s)
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_COPY(_a, _b)
#define VECT2_SUM(_c, _a, _b)
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition state.h:821
bool nav_gvf_segment_points(struct FloatVect2 start, struct FloatVect2 end)
Definition nav_line.c:253
void gvf_set_direction(int8_t s)
Definition gvf.c:232
Guidance algorithm based on vector fields.
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
bool nav_gvf_ellipse_XY(float x, float y, float a, float b, float alpha)
Definition nav_ellipse.c:64
bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time)
Decide if the UAV is approaching the current waypoint.
Definition nav.c:325
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
Definition nav.c:92
float last_y
Definition nav.c:47
float last_x
Definition nav.c:47
Fixedwing Navigation library.
#define NavCourseCloseTo(x)
Definition nav.h:163
#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
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition nav.h:177
static bool gvf_intercept_two_lines(struct FloatVect2 *p, struct FloatVect2 x, struct FloatVect2 y, float a1, float a2, float b1, float b2)
Intercept two lines and give back the point of intersection.
static bool gvf_get_two_intersects(struct FloatVect2 *x, struct FloatVect2 *y, struct FloatVect2 a, struct FloatVect2 b)
Intersects a line with the polygon and gives back the two intersection points.
bool nav_gvf_survey_polygon_run(void)
Main navigation routine.
struct gvf_SurveyPolyAdv gvf_survey
void nav_gvf_survey_polygon_setup(uint8_t first_wp, uint8_t size, float angle, float sweep_width, float shot_dist, float min_rad, float altitude)
Initializes the variables needed for the survey to start.
static void gvf_circle_direction(float rad)
struct FloatVect2 seg_center2
struct FloatVect2 rad_vec
struct FloatVect2 ret_end
struct FloatVect2 entry_center
struct FloatVect2 seg_end
enum gvf_SurveyStage stage
struct FloatVect2 dir_vec
struct FloatVect2 seg_start
struct FloatVect2 sweep_vec
struct FloatVect2 seg_center1
struct FloatVect2 ret_start
#define CARROT
default approaching_time for a wp
Definition navigation.h:70
API to get/set the generic vehicle states.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202