-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
33 lines (22 loc) · 870 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "mbed.h"
typedef struct _s_vector_float {
float x, y;
} s_vector_float;
typedef struct _s_vector_int16 {
int16_t x, y;
} s_vector_int16;
#define RAD2DEG(val) ((val)*180/M_PI)
#define DEG2RAD(val) ((val)*M_PI/180)
#define ABS(val) (((val) < 0) ? (-(val)) : (val))
#define SIGN(x) ((x) > 0 ? 1 : -1)
#define DIST(x, y) sqrt((x)*(x) + (y)*(y))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define FMOD_2PI(angle) fmod((angle)+M_PI, 2*M_PI)
// Return the angle between -pi and +pi, modulo 2*pi.
#define std_rad_angle(angle) ( \
FMOD_2PI(angle) < 0 \
? FMOD_2PI(angle)+2*M_PI-M_PI \
: FMOD_2PI(angle)-M_PI \
)
double map(double x, double in_min, double in_max, double out_min, double out_max);
double constrain(double val, double min, double max);