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_line.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Hector Garcia de Marina
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 */
22
23#include "nav_line.h"
24
25#include "generated/airframe.h"
27
29#ifndef GVF_LINE_KE
30#define GVF_LINE_KE 1
31#endif
32
34#ifndef GVF_LINE_KN
35#define GVF_LINE_KN 1
36#endif
37
39#ifndef GVF_LINE_HEADING
40#define GVF_LINE_HEADING 0
41#endif
42
44#ifndef GVF_SEGMENT_D1
45#define GVF_SEGMENT_D1 0
46#endif
47
49#ifndef GVF_SEGMENT_D2
50#define GVF_SEGMENT_D2 0
51#endif
52
55
56// Param array lenght
57static int gvf_p_len_wps = 0;
58
61static void gvf_line(float a, float b, float heading)
62{
63 float e;
64 struct gvf_grad grad_line;
65 struct gvf_Hess Hess_line;
66
68 gvf_trajectory.p[0] = a;
69 gvf_trajectory.p[1] = b;
72 gvf_p_len_wps = 0;
73
77
79
81
82 gvf_segment.seg = 0;
83}
84
85static int out_of_segment_area(float x1, float y1, float x2, float y2, float d1, float d2)
86{
88 float px = p->x - x1;
89 float py = p->y - y1;
90
91 float zx = x2 - x1;
92 float zy = y2 - y1;
93 float alpha = atan2f(zy, zx);
94
95 float cosa = cosf(-alpha);
96 float sina = sinf(-alpha);
97
98 float pxr = px * cosa - py * sina;
99 float zxr = zx * cosa - zy * sina;
100
101 int s = 0;
102
103 if (pxr < -d1) {
104 s = 1;
105 } else if (pxr > (zxr + d2)) {
106 s = -1;
107 }
108
109 if (zy < 0) {
110 s *= -1;
111 }
112
113 return s;
114}
115
118// STRAIGHT LINE
119
120bool nav_gvf_line_XY_heading(float a, float b, float heading)
121{
123 gvf_line(a, b, heading);
124 return true;
125}
126
128{
130
131 float a = WaypointX(wp);
132 float b = WaypointY(wp);
133
135}
136
137bool nav_gvf_line_XY1_XY2(float x1, float y1, float x2, float y2)
138{
139 if (gvf_p_len_wps != 2) {
140 gvf_trajectory.p[3] = x2;
141 gvf_trajectory.p[4] = y2;
142 gvf_trajectory.p[5] = 0;
143 gvf_p_len_wps = 3;
144 }
145
146 float zx = x2 - x1;
147 float zy = y2 - y1;
148
150
152 gvf_segment.seg = 1;
153 gvf_segment.x1 = x1;
154 gvf_segment.y1 = y1;
155 gvf_segment.x2 = x2;
156 gvf_segment.y2 = y2;
157
158 return true;
159}
160
162{
163 gvf_trajectory.p[3] = wp1;
164 gvf_trajectory.p[4] = wp2;
165 gvf_p_len_wps = 2;
166
167 float x1 = WaypointX(wp1);
168 float y1 = WaypointY(wp1);
169 float x2 = WaypointX(wp2);
170 float y2 = WaypointY(wp2);
171
172 return nav_gvf_line_XY1_XY2(x1, y1, x2, y2);
173}
174
175// SEGMENT
176
177bool nav_gvf_segment_loop_XY1_XY2(float x1, float y1, float x2, float y2, float d1, float d2)
178{
179 int s = out_of_segment_area(x1, y1, x2, y2, d1, d2);
180 if (s != 0) {
182 }
183
184 float zx = x2 - x1;
185 float zy = y2 - y1;
186 float alpha = atanf(zx / zy);
187
188 gvf_line(x1, y1, alpha);
189
191
192 gvf_segment.seg = 1;
193 gvf_segment.x1 = x1;
194 gvf_segment.y1 = y1;
195 gvf_segment.x2 = x2;
196 gvf_segment.y2 = y2;
197
198 return true;
199}
200
202{
203 gvf_trajectory.p[3] = wp1;
204 gvf_trajectory.p[4] = wp2;
205 gvf_trajectory.p[5] = d1;
206 gvf_trajectory.p[6] = d2;
207 gvf_p_len_wps = 4;
208
209 float x1 = WaypointX(wp1);
210 float y1 = WaypointY(wp1);
211 float x2 = WaypointX(wp2);
212 float y2 = WaypointY(wp2);
213
214 return nav_gvf_segment_loop_XY1_XY2(x1, y1, x2, y2, d1, d2);
215}
216
217bool nav_gvf_segment_XY1_XY2(float x1, float y1, float x2, float y2)
218{
220 float px = p->x - x1;
221 float py = p->y - y1;
222
223 float zx = x2 - x1;
224 float zy = y2 - y1;
225
226 float beta = atan2f(zy, zx);
227 float cosb = cosf(-beta);
228 float sinb = sinf(-beta);
229 float zxr = zx * cosb - zy * sinb;
230 float pxr = px * cosb - py * sinb;
231
232 if ((zxr > 0 && pxr > zxr) || (zxr < 0 && pxr < zxr)) {
233 return false;
234 }
235
236 return nav_gvf_line_XY1_XY2(x1, y1, x2, y2);
237}
238
240{
241 gvf_trajectory.p[3] = wp1;
242 gvf_trajectory.p[4] = wp2;
243 gvf_p_len_wps = 2;
244
245 float x1 = WaypointX(wp1);
246 float y1 = WaypointY(wp1);
247 float x2 = WaypointX(wp2);
248 float y2 = WaypointY(wp2);
249
250 return nav_gvf_segment_XY1_XY2(x1, y1, x2, y2);
251}
252
253bool nav_gvf_segment_points(struct FloatVect2 start, struct FloatVect2 end)
254{
255 return nav_gvf_segment_XY1_XY2(start.x, start.y, end.x, end.y);
256}
static uint16_t d1
static uint16_t d2
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointY(_wp)
Definition common_nav.h:46
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
#define GVF_LINE_HEADING
Definition nav_line.c:40
#define GVF_LINE_KE
Definition nav_line.c:30
#define GVF_SEGMENT_D2
Definition nav_line.c:50
bool nav_gvf_segment_XY1_XY2(float x1, float y1, float x2, float y2)
Definition nav_line.c:217
bool nav_gvf_segment_wp1_wp2(uint8_t wp1, uint8_t wp2)
Definition nav_line.c:239
bool nav_gvf_line_wp1_wp2(uint8_t wp1, uint8_t wp2)
Definition nav_line.c:161
static int out_of_segment_area(float x1, float y1, float x2, float y2, float d1, float d2)
Definition nav_line.c:85
bool nav_gvf_segment_loop_XY1_XY2(float x1, float y1, float x2, float y2, float d1, float d2)
Definition nav_line.c:177
bool nav_gvf_line_XY_heading(float a, float b, float heading)
Definition nav_line.c:120
#define GVF_SEGMENT_D1
Definition nav_line.c:45
#define GVF_LINE_KN
Definition nav_line.c:35
static void gvf_line(float a, float b, float heading)
Definition nav_line.c:61
static int gvf_p_len_wps
Definition nav_line.c:57
gvf_seg_par gvf_segment_par
Definition nav_line.c:54
bool nav_gvf_segment_points(struct FloatVect2 start, struct FloatVect2 end)
Definition nav_line.c:253
bool nav_gvf_line_XY1_XY2(float x1, float y1, float x2, float y2)
Definition nav_line.c:137
gvf_li_par gvf_line_par
Definition nav_line.c:53
bool nav_gvf_segment_loop_wp1_wp2(uint8_t wp1, uint8_t wp2, float d1, float d2)
Definition nav_line.c:201
bool nav_gvf_line_wp_heading(uint8_t wp, float heading)
Definition nav_line.c:127
float ke
Definition nav_line.h:42
float kn
Definition nav_line.h:43
gvf_con gvf_control
Definition gvf.c:30
void gvf_control_2D(float ke, float kn, float e, struct gvf_grad *grad, struct gvf_Hess *hess)
Definition gvf.c:100
void gvf_set_direction(int8_t s)
Definition gvf.c:232
Guidance algorithm based on vector fields.
float ke
Definition gvf.h:54
float error
Definition gvf.h:56
void gvf_line_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
Definition gvf_traj.c:29
gvf_seg gvf_segment
Definition gvf_traj.c:25
gvf_tra gvf_trajectory
Definition gvf_traj.c:24
float x1
Definition gvf_traj.h:68
enum trajectories type
Definition gvf_traj.h:34
float p[16]
Definition gvf_traj.h:35
int p_len
Definition gvf_traj.h:36
int seg
Definition gvf_traj.h:67
float y1
Definition gvf_traj.h:69
float y2
Definition gvf_traj.h:71
float x2
Definition gvf_traj.h:70
static float p[2][2]
static uint32_t s
uint16_t foo
Definition main_demo5.c:58
Fixedwing navigation along a line with nice U-turns.
vector in East North Up coordinates Units: meters
float alpha
Definition textons.c:133
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202
float heading
Definition wedgebug.c:258