Macros | Functions
utils.h File Reference

Go to the source code of this file.

Macros

#define SIGN(x)   ((x<0)?-1:1)
 
#define UTILS_AGE_S(x)   ((float)chTimeElapsedSince(x) / (float)CH_FREQUENCY)
 

Functions

void utils_step_towards (float *value, float goal, float step)
 
float utils_calc_ratio (float low, float high, float val)
 
void utils_norm_angle (float *angle)
 
int utils_truncate_number (float *number, float min, float max)
 
float utils_map (float x, float in_min, float in_max, float out_min, float out_max)
 
int utils_map_int (int x, int in_min, int in_max, int out_min, int out_max)
 
void utils_deadband (float *value, float tres, float max)
 
float utils_angle_difference (float angle1, float angle2)
 
float utils_middle_of_3 (float a, float b, float c)
 
int utils_middle_of_3_int (int a, int b, int c)
 
void utils_sys_lock_cnt (void)
 
void utils_sys_unlock_cnt (void)
 

Macro Definition Documentation

#define SIGN (   x)    ((x<0)?-1:1)
#define UTILS_AGE_S (   x)    ((float)chTimeElapsedSince(x) / (float)CH_FREQUENCY)

Function Documentation

float utils_angle_difference ( float  angle1,
float  angle2 
)

Get the difference between two angles. Will always be between -180 and +180 degrees.

Parameters
angle1The first angle
angle2The second angle
Returns
The difference between the angles
float utils_calc_ratio ( float  low,
float  high,
float  val 
)
void utils_deadband ( float *  value,
float  tres,
float  max 
)

Truncate absolute values less than tres to zero. The value tres will be mapped to 0 and the value max to max.

float utils_map ( float  x,
float  in_min,
float  in_max,
float  out_min,
float  out_max 
)
int utils_map_int ( int  x,
int  in_min,
int  in_max,
int  out_min,
int  out_max 
)
float utils_middle_of_3 ( float  a,
float  b,
float  c 
)

Get the middle value of three values

Parameters
aFirst value
bSecond value
cThird value
Returns
The middle value
int utils_middle_of_3_int ( int  a,
int  b,
int  c 
)

Get the middle value of three values

Parameters
aFirst value
bSecond value
cThird value
Returns
The middle value
void utils_norm_angle ( float *  angle)

Make sure that 0 <= angle < 360

Parameters
angleThe angle to normalize.
void utils_step_towards ( float *  value,
float  goal,
float  step 
)
void utils_sys_lock_cnt ( void  )

A system locking function with a counter. For every lock, a corresponding unlock must exist to unlock the system. That means, if lock is called five times, unlock has to be called five times as well. Note that chSysLock and chSysLockFromIsr are the same for this port.

void utils_sys_unlock_cnt ( void  )

A system unlocking function with a counter. For every lock, a corresponding unlock must exist to unlock the system. That means, if lock is called five times, unlock has to be called five times as well. Note that chSysUnlock and chSysUnlockFromIsr are the same for this port.

int utils_truncate_number ( float *  number,
float  min,
float  max 
)