Update actions to ubuntu-latest (#14114)
[betaflight.git] / src / main / common / pwl.h
blob9a767d50d85e708385a8df0838a1729c8584f0d4
1 /*
2 * This file is part of Betaflight.
4 * Betaflight is free software. You can redistribute this software
5 * and/or modify this software under the terms of the GNU General
6 * Public License as published by the Free Software Foundation,
7 * either version 3 of the License, or (at your option) any later
8 * version.
10 * Betaflight is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this software.
19 * If not, see <http://www.gnu.org/licenses/>.
22 #pragma once
24 #include "utils.h"
26 #define PWL_DECLARE(name, size, xMinV, xMaxV) \
27 STATIC_ASSERT((xMinV) < (xMaxV), "xMinV must be less than xMaxV"); \
28 STATIC_ASSERT((size) > 1, "size must be more than 1"); \
29 STATIC_ASSERT((size) < 33, "size must be less than 33"); \
30 float name##_yValues[(size)]; \
31 pwl_t name = { \
32 .yValues = name##_yValues, \
33 .numPoints = (size), \
34 .xMin = (xMinV), \
35 .xMax = (xMaxV), \
36 .dx = ((xMaxV) - (xMinV)) / ((size) - 1) \
39 typedef struct pwl_s {
40 float *yValues;
41 int numPoints;
42 float xMin;
43 float xMax;
44 float dx;
45 } pwl_t;
47 void pwlInitialize(pwl_t *pwl, float *yValues, int numPoints, float xMin, float xMax);
48 void pwlFill(pwl_t *pwl, float (*function)(float, void*), void *arg);
49 float pwlInterpolate(const pwl_t *pwl, float x);