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_parametric_2d_bezier_splines.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Alfredo Gonzalez Calvin <alfredgo@ucm.es>
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
23
24#ifndef GVF_PARAMETRIC_2D_BEZIER_SPLINES_KX
25#define GVF_PARAMETRIC_2D_BEZIER_SPLINES_KX 2.0
26#endif
27
28#ifndef GVF_PARAMETRIC_2D_BEZIER_SPLINES_KY
29#define GVF_PARAMETRIC_2D_BEZIER_SPLINES_KY 2.0
30#endif
31
35
37
40// Bezier is just an array
41static void create_bezier_spline(bezier_t *bezier, float *px, float *py)
42{
43 int k, j;
44 j = 0;
45 for (k = 0; k < GVF_PARAMETRIC_2D_BEZIER_N_SEG; k++) {
46 bezier[k].p0[0] = px[j];
47 bezier[k].p0[1] = py[j];
48 bezier[k].p1[0] = px[j + 1];
49 bezier[k].p1[1] = py[j + 1];
50 bezier[k].p2[0] = px[j + 2];
51 bezier[k].p2[1] = py[j + 2];
52 bezier[k].p3[0] = px[j + 3];
53 bezier[k].p3[1] = py[j + 3];
54
55 // This allows for C^0 continuity (last point is init point)
56 j += 3;
57 }
58}
59
62// 2D CUBIC BEZIER CURVE
63
73
74/* @param first_wp is the first waypoint of the Bézier Spline
75 * there should be 3*GVF_PARAMETRIC_2D_BEZIER_N_SEG+1 points
76 */
78{
79 float x[3 * GVF_PARAMETRIC_2D_BEZIER_N_SEG + 1];
80 float y[3 * GVF_PARAMETRIC_2D_BEZIER_N_SEG + 1];
81 int k;
82 for (k = 0; k < 3 * GVF_PARAMETRIC_2D_BEZIER_N_SEG + 1; k++) {
83 x[k] = WaypointX(first_wp + k);
84 y[k] = WaypointY(first_wp + k);
85 }
87
88 /* Send data piecewise. Some radio modules do not allow for a big data frame.*/
89
90 // Send x points -> Indicate x with sign (+) in the first parameter
93 for (k = 0; k < 3 * GVF_PARAMETRIC_2D_BEZIER_N_SEG + 1; k++) {
95 }
96 }
97 // Send y points -> Indicate y with sign (-) in the first parameter
100 for (k = 0; k < 3 * GVF_PARAMETRIC_2D_BEZIER_N_SEG + 1; k++) {
102 }
103 }
104 // Send kx, ky, beta and anything else needed..
105 else {
110 }
111
113
114 // Restart the spline
117 } else if (gvf_parametric_control.w < 0) {
119 }
121 return true;
122}
123
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointY(_wp)
Definition common_nav.h:46
gvf_parametric_tra gvf_parametric_trajectory
void gvf_parametric_2d_bezier_splines_info(bezier_t *bezier, float *f1, float *f2, float *f1d, float *f2d, float *f1dd, float *f2dd, float w)
@ BEZIER_2D
#define GVF_PARAMETRIC_2D_BEZIER_N_SEG
enum trajectories_parametric type
float p0[2]
gvf_parametric_con gvf_parametric_control
void gvf_parametric_control_2D(float kx, float ky, float f1, float f2, float f1d, float f2d, float f1dd, float f2dd)
gvf_parametric_tel gvf_parametric_telemetry
Guiding vector field algorithm for 2D and 3D parametric trajectories.
uint16_t foo
Definition main_demo5.c:58
bool nav_gvf_parametric_2D_bezier_run(void)
bool nav_gvf_parametric_2D_bezier_wp(uint8_t first_wp)
#define GVF_PARAMETRIC_2D_BEZIER_SPLINES_KY
gvf_par_2d_bezier_par gvf_parametric_2d_bezier_par
bezier_t gvf_bezier_2D[GVF_PARAMETRIC_2D_BEZIER_N_SEG]
static void create_bezier_spline(bezier_t *bezier, float *px, float *py)
#define GVF_PARAMETRIC_2D_BEZIER_SPLINES_KX
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.