Skip to content

Commit 33b879a

Browse files
committed
Updated math library
1 parent e00b358 commit 33b879a

File tree

9 files changed

+38
-278
lines changed

9 files changed

+38
-278
lines changed

libraries/math/butterworth.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Butterworth low pass filter
6-
* @{
7-
*
8-
* @file butterworth.c
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
10-
* @brief Direct form two of a second order Butterworth low pass filter
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
31-
#include "openpilot.h"
32-
#include "math.h"
1+
#include <math.h>
2+
#include <uvos_math.h>
333
#include "butterworth.h"
344

355
/**

libraries/math/butterworth.h

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Butterworth low pass filter
6-
* @{
7-
*
8-
* @file butterworth.h
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
10-
* @brief Direct form two of a second order Butterworth low pass filter
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
311
#ifndef BUTTERWORTH_H
322
#define BUTTERWORTH_H
333

@@ -38,9 +8,17 @@ struct ButterWorthDF2Filter {
388
float a2;
399
};
4010

11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif // __cplusplus
14+
4115
// Function declarations
4216
void InitButterWorthDF2Filter(const float ff, struct ButterWorthDF2Filter *filterPtr);
4317
void InitButterWorthDF2Values(const float x0, const struct ButterWorthDF2Filter *filterPtr, float *wn1Ptr, float *wn2Ptr);
4418
float FilterButterWorthDF2(const float xn, const struct ButterWorthDF2Filter *filterPtr, float *wn1Ptr, float *wn2Ptr);
4519

20+
#ifdef __cplusplus
21+
} // extern "C"
22+
#endif // __cplusplus
23+
4624
#endif

libraries/math/mathmisc.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Reuseable math functions
6-
* @{
7-
*
8-
* @file mathmisc.c
9-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
10-
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11-
* @brief Reuseable math functions
12-
*
13-
* @see The GNU Public License (GPL) Version 3
14-
*
15-
*****************************************************************************/
16-
/*
17-
* This program is free software; you can redistribute it and/or modify
18-
* it under the terms of the GNU General Public License as published by
19-
* the Free Software Foundation; either version 3 of the License, or
20-
* (at your option) any later version.
21-
*
22-
* This program is distributed in the hope that it will be useful, but
23-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25-
* for more details.
26-
*
27-
* You should have received a copy of the GNU General Public License along
28-
* with this program; if not, write to the Free Software Foundation, Inc.,
29-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30-
*/
31-
321
#include <mathmisc.h>
332

343
void pseudo_windowed_variance_init(pw_variance_t *variance, int32_t window_size)

libraries/math/mathmisc.h

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Reuseable math functions
6-
* @{
7-
*
8-
* @file mathmisc.h
9-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
10-
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11-
* @brief Reuseable math functions
12-
*
13-
* @see The GNU Public License (GPL) Version 3
14-
*
15-
*****************************************************************************/
16-
/*
17-
* This program is free software; you can redistribute it and/or modify
18-
* it under the terms of the GNU General Public License as published by
19-
* the Free Software Foundation; either version 3 of the License, or
20-
* (at your option) any later version.
21-
*
22-
* This program is distributed in the hope that it will be useful, but
23-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25-
* for more details.
26-
*
27-
* You should have received a copy of the GNU General Public License along
28-
* with this program; if not, write to the Free Software Foundation, Inc.,
29-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30-
*/
31-
321
#ifndef MATHMISC_H
332
#define MATHMISC_H
343

@@ -42,6 +11,10 @@ typedef struct {
4211
float new_smsa;
4312
} pw_variance_t;
4413

14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif // __cplusplus
17+
4518
/***
4619
* initialize pseudo windowed
4720
* @param variance the instance to be initialized
@@ -176,4 +149,8 @@ static inline float fastPow(float a, float b)
176149
return (float)u.d;
177150
}
178151

152+
#ifdef __cplusplus
153+
} // extern "C"
154+
#endif // __cplusplus
155+
179156
#endif /* MATHMISC_H */

libraries/math/pid.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,6 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Sine and cosine methods that use a cached lookup table
6-
* @{
7-
*
8-
* @file pid.c
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
10-
* @brief Methods to work with PID structure
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
31-
#include "openpilot.h"
321
#include "pid.h"
332
#include <mathmisc.h>
34-
#include <pios_math.h>
3+
#include <uvos_math.h>
354

365
// ! Store the shared time constant for the derivative cutoff.
376
static float deriv_tau = 7.9577e-3f;

libraries/math/pid.h

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Sine and cosine methods that use a cached lookup table
6-
* @{
7-
*
8-
* @file pid.h
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
10-
* @brief Methods to work with PID structure
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
311
#ifndef PID_H
322
#define PID_H
333

4+
#include <stdint.h>
5+
#include <stdbool.h>
346
#include "mathmisc.h"
357

368
// !
@@ -68,6 +40,10 @@ typedef struct pid_scaler_s {
6840
float d;
6941
} pid_scaler;
7042

43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif // __cplusplus
46+
7147
// ! Methods to use the pid structures
7248
float pid_apply(struct pid *pid, const float err, float dT);
7349
float pid_apply_setpoint(struct pid *pid, const pid_scaler *scaler, const float setpoint, const float measured, float dT, bool meas_based_d_term);
@@ -80,4 +56,8 @@ void pid2_configure(struct pid2 *pid, float kp, float ki, float kd, float Tf, fl
8056
void pid2_transfer(struct pid2 *pid, float u0);
8157
float pid2_apply(struct pid2 *pid, const float r, const float y, float ulow, float uhigh);
8258

59+
#ifdef __cplusplus
60+
} // extern "C"
61+
#endif // __cplusplus
62+
8363
#endif /* PID_H */

libraries/math/sin_lookup.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Sine and cosine methods that use a cached lookup table
6-
* @{
7-
*
8-
* @file sin_lookup.c
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
10-
* @brief Sine lookup table from flash with 1 degree resolution
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
31-
#include "openpilot.h"
321
#include "math.h"
332
#include "stdbool.h"
343
#include "stdint.h"
35-
#include <pios_math.h>
4+
// #include <pios_math.h>
365

376
#define FLASH_TABLE
387
#ifdef FLASH_TABLE

libraries/math/sin_lookup.h

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
1-
/**
2-
******************************************************************************
3-
* @addtogroup OpenPilot Math Utilities
4-
* @{
5-
* @addtogroup Sine and cosine methods that use a cached lookup table
6-
* @{
7-
*
8-
* @file sin_lookup.h
9-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
10-
* @brief Sine lookup table from flash with 1 degree resolution
11-
*
12-
* @see The GNU Public License (GPL) Version 3
13-
*
14-
*****************************************************************************/
15-
/*
16-
* This program is free software; you can redistribute it and/or modify
17-
* it under the terms of the GNU General Public License as published by
18-
* the Free Software Foundation; either version 3 of the License, or
19-
* (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but
22-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23-
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24-
* for more details.
25-
*
26-
* You should have received a copy of the GNU General Public License along
27-
* with this program; if not, write to the Free Software Foundation, Inc.,
28-
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29-
*/
30-
311
#ifndef SIN_LOOKUP_H
322
#define SIN_LOOKUP_H
333

4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif // __cplusplus
7+
348
int sin_lookup_initalize();
359
float sin_lookup_deg(float angle);
3610
float cos_lookup_deg(float angle);
3711
float sin_lookup_rad(float angle);
3812
float cos_lookup_rad(float angle);
3913

14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus
17+
4018
#endif

0 commit comments

Comments
 (0)