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_IK_LINE_KE
30#define GVF_IK_LINE_KE 1
31#endif
32
34#ifndef GVF_IK_LINE_KN
35#define GVF_IK_LINE_KN 1
36#endif
37
39#ifndef GVF_IK_LINE_HEADING
40#define GVF_IK_LINE_HEADING 0
41#endif
42
44#ifndef GVF_IK_SEGMENT_D1
45#define GVF_IK_SEGMENT_D1 0
46#endif
47
49#ifndef GVF_IK_SEGMENT_D2
50#define GVF_IK_SEGMENT_D2 0
51#endif
52
55
56// Param array lenght
57static int gvf_p_len_wps = 0;
58
61static void gvf_ik_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_ik_line_XY_heading(float a, float b, float heading)
121{
123 gvf_ik_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_ik_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_ik_line_XY1_XY2(x1, y1, x2, y2);
173}
174
175bool nav_gvf_ik_segment_loop_XY1_XY2(float x1, float y1, float x2, float y2, float d1, float d2)
176{
177 int s = out_of_segment_area(x1, y1, x2, y2, d1, d2);
178 if (s != 0) {
180 }
181
182 float zx = x2 - x1;
183 float zy = y2 - y1;
184 float alpha = atanf(zx / zy);
185
186 gvf_ik_line(x1, y1, alpha);
187
189
190 gvf_segment.seg = 1;
191 gvf_segment.x1 = x1;
192 gvf_segment.y1 = y1;
193 gvf_segment.x2 = x2;
194 gvf_segment.y2 = y2;
195
196 return true;
197}
198
200{
201 gvf_trajectory.p[3] = wp1;
202 gvf_trajectory.p[4] = wp2;
203 gvf_trajectory.p[5] = d1;
204 gvf_trajectory.p[6] = d2;
205 gvf_p_len_wps = 4;
206
207 float x1 = WaypointX(wp1);
208 float y1 = WaypointY(wp1);
209 float x2 = WaypointX(wp2);
210 float y2 = WaypointY(wp2);
211
212 return nav_gvf_ik_segment_loop_XY1_XY2(x1, y1, x2, y2, d1, d2);
213}
214
215bool nav_gvf_ik_segment_XY1_XY2(float x1, float y1, float x2, float y2)
216{
218 float px = p->x - x1;
219 float py = p->y - y1;
220
221 float zx = x2 - x1;
222 float zy = y2 - y1;
223
224 float beta = atan2f(zy, zx);
225 float cosb = cosf(-beta);
226 float sinb = sinf(-beta);
227 float zxr = zx * cosb - zy * sinb;
228 float pxr = px * cosb - py * sinb;
229
230 if ((zxr > 0 && pxr > zxr) || (zxr < 0 && pxr < zxr)) {
231 return false;
232 }
233
234 return nav_gvf_ik_line_XY1_XY2(x1, y1, x2, y2);
235}
236
238{
239 gvf_trajectory.p[3] = wp1;
240 gvf_trajectory.p[4] = wp2;
241 gvf_p_len_wps = 2;
242
243 float x1 = WaypointX(wp1);
244 float y1 = WaypointY(wp1);
245 float x2 = WaypointX(wp2);
246 float y2 = WaypointY(wp2);
247
248 return nav_gvf_ik_segment_XY1_XY2(x1, y1, x2, y2);
249}
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
static int out_of_segment_area(float x1, float y1, float x2, float y2, float d1, float d2)
Definition nav_line.c:85
static int gvf_p_len_wps
Definition nav_line.c:57
#define GVF_IK_LINE_KE
Definition nav_line.c:30
bool nav_gvf_ik_segment_XY1_XY2(float x1, float y1, float x2, float y2)
Definition nav_line.c:215
bool nav_gvf_ik_line_XY_heading(float a, float b, float heading)
Definition nav_line.c:120
bool nav_gvf_ik_line_wp1_wp2(uint8_t wp1, uint8_t wp2)
Definition nav_line.c:161
bool nav_gvf_ik_line_XY1_XY2(float x1, float y1, float x2, float y2)
Definition nav_line.c:137
bool nav_gvf_ik_segment_loop_XY1_XY2(float x1, float y1, float x2, float y2, float d1, float d2)
Definition nav_line.c:175
#define GVF_IK_LINE_HEADING
Definition nav_line.c:40
bool nav_gvf_ik_segment_loop_wp1_wp2(uint8_t wp1, uint8_t wp2, float d1, float d2)
Definition nav_line.c:199
#define GVF_IK_SEGMENT_D2
Definition nav_line.c:50
#define GVF_IK_SEGMENT_D1
Definition nav_line.c:45
bool nav_gvf_ik_line_wp_heading(uint8_t wp, float heading)
Definition nav_line.c:127
gvf_ik_seg_par gvf_ik_segment_par
Definition nav_line.c:54
static void gvf_ik_line(float a, float b, float heading)
Definition nav_line.c:61
gvf_ik_li_par gvf_ik_line_par
Definition nav_line.c:53
bool nav_gvf_ik_segment_wp1_wp2(uint8_t wp1, uint8_t wp2)
Definition nav_line.c:237
#define GVF_IK_LINE_KN
Definition nav_line.c:35
void gvf_ik_control_2D(float ke, float kn, float phi, struct gvf_grad *grad, struct gvf_Hess *hess)
Definition gvf_ik.c:141
gvf_ik_con gvf_ik_control
Definition gvf_ik.c:35
void gvf_ik_set_direction(int8_t s)
Definition gvf_ik.c:294
float ke
Definition gvf_ik.h:61
float error
Definition gvf_ik.h:64
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