43 #if PERIODIC_TELEMETRY
45 static void send_gvf(
struct transport_tx *trans,
struct link_device *
dev)
51 switch (gvf_trajectory.
type) {
68 pprz_msg_send_GVF(trans, dev, AC_ID, &gvf_control.
error, &traj_type,
69 &gvf_control.
s, &gvf_control.
ke, plen, gvf_trajectory.
p);
75 (gvf_trajectory.
p[2] == gvf_trajectory.
p[3])) {
76 pprz_msg_send_CIRCLE(trans, dev, AC_ID,
77 &gvf_trajectory.
p[0], &gvf_trajectory.
p[1],
78 &gvf_trajectory.
p[2]);
84 if (gvf_trajectory.
type ==
LINE && gvf_segment.
seg == 1) {
85 pprz_msg_send_SEGMENT(trans, dev, AC_ID,
86 &gvf_segment.
x1, &gvf_segment.
y1,
87 &gvf_segment.
x2, &gvf_segment.
y2);
101 float alpha = atan2f(zy, zx);
103 float cosa = cosf(-alpha);
104 float sina = sinf(-alpha);
106 float pxr = px * cosa - py * sina;
107 float zxr = zx * cosa - zy * sina;
113 }
else if (pxr > (zxr + d2)) {
131 #if PERIODIC_TELEMETRY
145 float px_dot = ground_speed * sinf(course);
146 float py_dot = ground_speed * cosf(course);
147 int s = gvf_control.
s;
154 float tx = s * grad->
ny;
155 float ty = -s * grad->
nx;
158 float H11 = hess->
H11;
159 float H12 = hess->
H12;
160 float H21 = hess->
H21;
161 float H22 = hess->
H22;
164 float pdx_dot = tx - ke * e * nx;
165 float pdy_dot = ty - ke * e * ny;
167 float norm_pd_dot = sqrtf(pdx_dot * pdx_dot + pdy_dot * pdy_dot);
168 float md_x = pdx_dot / norm_pd_dot;
169 float md_y = pdy_dot / norm_pd_dot;
171 float Apd_dot_dot_x = -ke * (nx * px_dot + ny * py_dot) * nx;
172 float Apd_dot_dot_y = -ke * (nx * px_dot + ny * py_dot) * ny;
174 float Bpd_dot_dot_x = ((-ke * e * H11) + s * H21) * px_dot
175 + ((-ke * e * H12) + s * H22) * py_dot;
176 float Bpd_dot_dot_y = -(s * H11 + (ke * e * H21)) * px_dot
177 - (s * H12 + (ke * e * H22)) * py_dot;
179 float pd_dot_dot_x = Apd_dot_dot_x + Bpd_dot_dot_x;
180 float pd_dot_dot_y = Apd_dot_dot_y + Bpd_dot_dot_y;
182 float md_dot_const = -(md_x * pd_dot_dot_y - md_y * pd_dot_dot_x)
185 float md_dot_x = md_y * md_dot_const;
186 float md_dot_y = -md_x * md_dot_const;
188 float omega_d = -(md_dot_x * md_y - md_dot_y * md_x);
190 float mr_x = sinf(course);
191 float mr_y = cosf(course);
193 float omega = omega_d + kn * (mr_x * md_y - mr_y * md_x);
218 gvf_trajectory.
type = 0;
219 gvf_trajectory.
p[0] = a;
220 gvf_trajectory.
p[1] = b;
227 gvf_control.
error = e;
245 float alpha = atanf(zx / zy);
247 float beta = atan2f(zy, zx);
248 float cosb = cosf(-beta);
249 float sinb = sinf(-beta);
250 float zxr = zx * cosb - zy * sinb;
251 if((zxr > 0 && zy > 0) || (zxr < 0 && zy < 0)) {
288 float alpha = atanf(zx / zy);
315 float px = p->
x - x1;
316 float py = p->
y - y1;
321 float beta = atan2f(zy, zx);
322 float cosb = cosf(-beta);
323 float sinb = sinf(-beta);
324 float zxr = zx * cosb - zy * sinb;
325 float pxr = px * cosb - py * sinb;
327 if((zxr > 0 && pxr > zxr) || (zxr < 0 && pxr < zxr)) {
346 heading = heading * M_PI / 180;
362 gvf_trajectory.
type = 1;
363 gvf_trajectory.
p[0] = x;
364 gvf_trajectory.
p[1] = y;
365 gvf_trajectory.
p[2] = a;
366 gvf_trajectory.
p[3] = b;
367 gvf_trajectory.
p[4] =
alpha;
370 if (a < 1 || b < 1) {
371 gvf_trajectory.
p[2] = 60;
372 gvf_trajectory.
p[3] = 60;
375 if (gvf_trajectory.
p[2] == gvf_trajectory.
p[3]) {
384 e, &grad_ellipse, &Hess_ellipse);
386 gvf_control.
error = e;
406 gvf_trajectory.
type = 2;
407 gvf_trajectory.
p[0] = a;
408 gvf_trajectory.
p[1] = b;
409 gvf_trajectory.
p[2] =
alpha;
410 gvf_trajectory.
p[3] = w;
411 gvf_trajectory.
p[4] = off;
412 gvf_trajectory.
p[5] =
A;
418 gvf_control.
error = e;
435 float alpha = atanf(zy / zx);
445 alpha = alpha * M_PI / 180;
static void send_segment(struct transport_tx *trans, struct link_device *dev)
bool gvf_sin_wp_alpha(uint8_t wp, float alpha, float w, float off, float A)
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
bool gvf_line_XY_heading(float a, float b, float heading)
Periodic telemetry system header (includes downlink utility and generated code).
Guidance algorithm based on vector fields 2D sinusoidal trajectory.
vector in East North Up coordinates Units: meters
bool gvf_sin_wp1_wp2(uint8_t wp1, uint8_t wp2, float w, float off, float A)
bool gvf_segment_loop_XY1_XY2(float x1, float y1, float x2, float y2, float d1, float d2)
bool gvf_ellipse_XY(float x, float y, float a, float b, float alpha)
#define HORIZONTAL_MODE_CIRCLE
Guidance algorithm based on vector fields 2D straight line trajectory.
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
bool gvf_segment_XY1_XY2(float x1, float y1, float x2, float y2)
void gvf_line_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
bool gvf_sin_XY_alpha(float a, float b, float alpha, float w, float off, float A)
Fixed wing horizontal control.
static int out_of_segment_area(float x1, float y1, float x2, float y2, float d1, float d2)
void gvf_sin_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
static void send_gvf(struct transport_tx *trans, struct link_device *dev)
Guidance algorithm based on vector fields.
#define DefaultPeriodic
Set default periodic telemetry.
#define HORIZONTAL_MODE_ROUTE
static void gvf_line(float a, float b, float heading)
void gvf_set_direction(int8_t s)
Guidance algorithm based on vector fields 2D Ellipse trajectory.
float h_ctl_roll_max_setpoint
void gvf_control_2D(float ke, float kn, float e, struct gvf_grad *grad, struct gvf_Hess *hess)
static const struct usb_device_descriptor dev
gvf_ell_par gvf_ellipse_par
bool gvf_ellipse_wp(uint8_t wp, float a, float b, float alpha)
Core autopilot interface common to all firmwares.
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
bool gvf_line_wp_heading(uint8_t wp, float heading)
#define LATERAL_MODE_ROLL
float h_ctl_roll_setpoint
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
bool gvf_segment_wp1_wp2(uint8_t wp1, uint8_t wp2)
bool gvf_line_XY1_XY2(float x1, float y1, float x2, float y2)
Fixedwing Navigation library.
bool gvf_segment_loop_wp1_wp2(uint8_t wp1, uint8_t wp2, float d1, float d2)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
#define HORIZONTAL_MODE_WAYPOINT
uint8_t autopilot_get_mode(void)
get autopilot mode
static void send_circle(struct transport_tx *trans, struct link_device *dev)
void gvf_ellipse_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
bool gvf_line_wp1_wp2(uint8_t wp1, uint8_t wp2)