32 #include "../gvf_common.h"
52 #if PERIODIC_TELEMETRY
54 static void send_gvf(
struct transport_tx *trans,
struct link_device *
dev)
68 pprz_msg_send_CIRCLE(trans,
dev, AC_ID,
74 pprz_msg_send_SEGMENT(trans,
dev, AC_ID,
93 float alpha = atan2f(zy, zx);
95 float cosa = cosf(-
alpha);
96 float sina = sinf(-
alpha);
98 float pxr = px * cosa - py * sina;
99 float zxr = zx * cosa - zy * sina;
105 }
else if (pxr > (zxr +
d2)) {
125 #if PERIODIC_TELEMETRY
148 float tx =
s * grad->
ny;
149 float ty = -
s * grad->
nx;
152 float H11 = hess->
H11;
153 float H12 = hess->
H12;
154 float H21 = hess->
H21;
155 float H22 = hess->
H22;
158 float pdx_dot = tx - ke * e * nx;
159 float pdy_dot = ty - ke * e * ny;
161 float Apd_dot_dot_x = -ke * (nx * px_dot + ny * py_dot) * nx;
162 float Apd_dot_dot_y = -ke * (nx * px_dot + ny * py_dot) * ny;
164 float Bpd_dot_dot_x = ((-ke * e * H11) +
s * H21) * px_dot
165 + ((-ke * e * H12) +
s * H22) * py_dot;
166 float Bpd_dot_dot_y = -(
s * H11 + (ke * e * H21)) * px_dot
167 - (
s * H12 + (ke * e * H22)) * py_dot;
169 float pd_dot_dot_x = Apd_dot_dot_x + Bpd_dot_dot_x;
170 float pd_dot_dot_y = Apd_dot_dot_y + Bpd_dot_dot_y;
172 float norm_pd_dot = sqrtf(pdx_dot * pdx_dot + pdy_dot * pdy_dot);
173 float md_x = pdx_dot / norm_pd_dot;
174 float md_y = pdy_dot / norm_pd_dot;
176 float md_dot_const = -(md_x * pd_dot_dot_y - md_y * pd_dot_dot_x)
179 float md_dot_x __attribute__((unused)) = md_y * md_dot_const;
180 float md_dot_y __attribute__((unused))= -md_x * md_dot_const;
182 #if defined(ROTORCRAFT_FIRMWARE)
185 #if defined(GVF_ROTORCRAFT_USE_ACCEL)
193 #warning "Using GVF for rotorcraft is still experimental, proceed with caution"
194 float n_norm = sqrtf(nx*nx+ny*ny);
195 float hess_px_dot = px_dot * H11 + py_dot * H12;
196 float hess_py_dot = px_dot * H21 + py_dot * H22;
198 float hess_pdx_dot = pdx_dot * H11 + pdy_dot * H12;
199 float hess_pdy_dot = pdx_dot * H21 + pdy_dot * H22;
201 float curvature_correction = tx * hess_px_dot + ty * hess_py_dot / (n_norm * n_norm);
202 float accel_correction_x = kn * hess_py_dot / n_norm;
203 float accel_correction_y = - kn * hess_px_dot / n_norm;
204 float accel_cmd_x = accel_correction_x + px_dot * curvature_correction;
205 float accel_cmd_y = accel_correction_y + py_dot * curvature_correction;
207 float speed_cmd_x = kn*tx / n_norm - ke * e * nx / (n_norm);
208 float speed_cmd_y = kn*ty / n_norm - ke * e * ny / (n_norm);
211 nav.
accel.
x = accel_cmd_x + (speed_cmd_x - px_dot);
212 nav.
accel.
y = accel_cmd_y + (speed_cmd_y - py_dot);
233 float omega_d = -(md_dot_x * md_y - md_dot_y * md_x);
235 float mr_x = sinf(
course);
236 float mr_y = cosf(
course);
238 float omega = omega_d + kn * (mr_x * md_y - mr_y * md_x);
244 gvf_c_info.
kappa = (nx*(H12*ny - nx*H22) + ny*(H21*nx - H11*ny))/powf(nx*nx + ny*ny,1.5);
255 if (speed < 0.0) speed = 0.0;
292 gvf_setNavMode(GVF_MODE_WAYPOINT);
318 gvf_setNavMode(GVF_MODE_ROUTE);
351 float alpha = atanf(zx / zy);
355 gvf_setNavMode(GVF_MODE_ROUTE);
385 float px =
p->x - x1;
386 float py =
p->y - y1;
391 float beta = atan2f(zy, zx);
392 float cosb = cosf(-beta);
393 float sinb = sinf(-beta);
394 float zxr = zx * cosb - zy * sinb;
395 float pxr = px * cosb - py * sinb;
397 if ((zxr > 0 && pxr > zxr) || (zxr < 0 && pxr < zxr)) {
449 if (a < 1 ||
b < 1) {
455 gvf_setNavMode(GVF_MODE_CIRCLE);
458 gvf_setNavMode(GVF_MODE_WAYPOINT);
464 e, &grad_ellipse, &Hess_ellipse);
524 float alpha = atanf(zy / zx);
Core autopilot interface common to all firmwares.
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
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)
bool gvf_sin_XY_alpha(float a, float b, float alpha, 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_wp(uint8_t wp, float a, float b, float alpha)
void gvf_set_align(bool align)
bool gvf_line_wp1_wp2(uint8_t wp1, uint8_t wp2)
bool gvf_sin_wp1_wp2(uint8_t wp1, uint8_t wp2, float w, float off, float A)
bool gvf_segment_wp1_wp2(uint8_t wp1, uint8_t wp2)
static int out_of_segment_area(float x1, float y1, float x2, float y2, float d1, float d2)
bool gvf_sin_wp_alpha(uint8_t wp, float alpha, float w, float off, float A)
void gvf_control_2D(float ke, float kn, float e, struct gvf_grad *grad, struct gvf_Hess *hess)
static void send_gvf(struct transport_tx *trans, struct link_device *dev)
void gvf_set_speed(float speed)
void gvf_set_direction(int8_t s)
bool gvf_segment_loop_wp1_wp2(uint8_t wp1, uint8_t wp2, float d1, float d2)
static void gvf_line(float a, float b, float heading)
bool gvf_ellipse_XY(float x, float y, float a, float b, float alpha)
bool gvf_line_XY_heading(float a, float b, float heading)
bool gvf_line_wp_heading(uint8_t wp, float heading)
bool gvf_line_XY1_XY2(float x1, float y1, float x2, float y2)
Guidance algorithm based on vector fields.
gvf_common_omega gvf_c_omega
gvf_common_params gvf_c_info
void gvf_ellipse_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
gvf_ell_par gvf_ellipse_par
Guidance algorithm based on vector fields 2D Ellipse trajectory.
void gvf_line_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
Guidance algorithm based on vector fields 2D straight line trajectory.
void gvf_low_level_control_2D(float omega)
void gvf_low_level_getState(void)
Firmware dependent file for the guiding vector field algorithm for 2D trajectories.
void gvf_sin_info(float *phi, struct gvf_grad *grad, struct gvf_Hess *hess)
Guidance algorithm based on vector fields 2D sinusoidal trajectory.
vector in East North Up coordinates Units: meters
struct RotorcraftNavigation nav
struct EnuCoor_f speed
speed setpoint (in m/s)
#define NAV_SETPOINT_MODE_SPEED
struct EnuCoor_f accel
accel setpoint (in m/s)
float heading
heading setpoint (in radians)
static const struct usb_device_descriptor dev
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.