utils.h
Go to the documentation of this file.
1 /*
2  Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * utils.h
20  *
21  * Created on: 16 maj 2013
22  * Author: benjamin
23  */
24 
25 #ifndef UTILS_H_
26 #define UTILS_H_
27 
28 void utils_step_towards(float *value, float goal, float step);
29 float utils_calc_ratio(float low, float high, float val);
30 void utils_norm_angle(float *angle);
31 int utils_truncate_number(float *number, float min, float max);
32 float utils_map(float x, float in_min, float in_max, float out_min, float out_max);
33 int utils_map_int(int x, int in_min, int in_max, int out_min, int out_max);
34 void utils_deadband(float *value, float tres, float max);
35 float utils_angle_difference(float angle1, float angle2);
36 float utils_middle_of_3(float a, float b, float c);
37 int utils_middle_of_3_int(int a, int b, int c);
38 void utils_sys_lock_cnt(void);
39 void utils_sys_unlock_cnt(void);
40 
41 // Return the sign of the argument. -1 if negative, 1 if zero or positive.
42 #define SIGN(x) ((x<0)?-1:1)
43 
44 // Return the age of a timestamp in seconds
45 #define UTILS_AGE_S(x) ((float)chTimeElapsedSince(x) / (float)CH_FREQUENCY)
46 
47 #endif /* UTILS_H_ */
void utils_sys_lock_cnt(void)
Definition: utils.c:192
float utils_map(float x, float in_min, float in_max, float out_min, float out_max)
Definition: utils.c:80
float utils_middle_of_3(float a, float b, float c)
Definition: utils.c:145
float utils_calc_ratio(float low, float high, float val)
Definition: utils.c:49
void utils_norm_angle(float *angle)
Definition: utils.c:58
float utils_angle_difference(float angle1, float angle2)
Definition: utils.c:115
void utils_deadband(float *value, float tres, float max)
Definition: utils.c:92
void utils_step_towards(float *value, float goal, float step)
Definition: utils.c:33
void utils_sys_unlock_cnt(void)
Definition: utils.c:205
int utils_map_int(int x, int in_min, int in_max, int out_min, int out_max)
Definition: utils.c:84
int utils_middle_of_3_int(int a, int b, int c)
Definition: utils.c:173
int utils_truncate_number(float *number, float min, float max)
Definition: utils.c:66