Lots of useful board independent functions for use in any module, such as conversions from float to int (bits, not number), and fixed point number functions. More...
Go to the source code of this file.
Functions | |
fixed | fixed_abs (fixed f) |
Returns the absolute value of the given fixed point number. | |
fixed | fixed_mult (fixed a, fixed b) |
Multiplies two fixed point numbers. | |
long long int | fixed_mult_to_long (fixed a, fixed b) |
Multiplies two fixed point numbers as a long long int to hold the overflow. | |
float | fixed_to_float (fixed m) |
Changes from fixed point to a floating point number. | |
int | fixed_to_int (fixed m) |
Changes from fixed point to integer. | |
fixed | float_to_fixed (float m) |
Changes from floating point to fixed point number. | |
float | floatvoid (void) |
A dummy function with void inputs that returns a float . | |
float | floatvoid_noerror (void) |
Doesn't throw an error if called. | |
fixed | int_to_fixed (int m) |
Changes from an int to fixed point number. | |
int | intvoid (void) |
A dummy function with void inputs that returns a int . | |
int | intvoid_noerror (void) |
Doesn't throw an error if called. | |
fixed | linear_to_fixed (int offset, float coeff, int value) |
Calculates the result of plugging in value into the linear equation described by the offset and coeff as a fixed point value. | |
void | tic (void) |
Starts the clock. | |
void | tic_toc_init (VOID_INT_F print_f) |
Initializes the TicToc functionality. | |
void | toc (void) |
Stops the clock and prints out the execution time. | |
void | voidint (int a) |
A dummy function with an int input that returns void . | |
void | voidint_noerror (int a) |
Doesn't throw an error if called. | |
void | voidvoid (void) |
A dummy function with void inputs that returns void . | |
void | voidvoid_noerror (void) |
Doesn't throw an error if called. | |
Variables | |
VOID_INT_F | tt_print = voidint |
A print or transmit function for the execution time. | |
int | tt_time = 0 |
The time it took for the last code block to execute. |
Lots of useful board independent functions for use in any module, such as conversions from float to int (bits, not number), and fixed point number functions.
Definition in file utility.c.
fixed fixed_abs | ( | fixed | f | ) |
fixed fixed_mult | ( | fixed | a, | |
fixed | b | |||
) |
Multiplies two fixed point numbers.
a | The first fixed point number. | |
b | The second fixed point number. |
Definition at line 60 of file utility.c.
Referenced by linear_to_fixed(), mc_compliant_control(), mc_get_thermal_limiter(), mc_init(), mc_pid_current(), and mc_smart_check_current().
long long int fixed_mult_to_long | ( | fixed | a, | |
fixed | b | |||
) |
Multiplies two fixed point numbers as a long
long
int
to hold the overflow.
a | The first fixed point number. | |
b | The second fixed point number. |
Definition at line 71 of file utility.c.
Referenced by mc_pid_current().
float fixed_to_float | ( | fixed | m | ) |
Changes from fixed point to a floating point number.
m | A fixed point number. |
Definition at line 42 of file utility.c.
Referenced by mc_init(), and mc_smart_check_current().
int fixed_to_int | ( | fixed | m | ) |
Changes from fixed point to integer.
Doesn't round, only drops the decimal.
m | A fixed point number. |
Definition at line 51 of file utility.c.
Referenced by mc_pid_current().
fixed float_to_fixed | ( | float | m | ) |
Changes from floating point to fixed point number.
m | A floating point number. |
Definition at line 26 of file utility.c.
Referenced by linear_to_fixed(), mc_compliant_control(), mc_init(), mc_set_command_current(), mc_set_dampness(), mc_set_stiffness(), mc_set_target_current(), and mc_set_unsafe_target_current().
float floatvoid | ( | void | ) |
A dummy function with void
inputs that returns a float
.
Use this as the default for function pointers.
Definition at line 124 of file utility.c.
References error_occurred().
00124 {error_occurred(ERROR_UTIL_DUMMY);return 0.0;}
float floatvoid_noerror | ( | void | ) |
fixed int_to_fixed | ( | int | m | ) |
Changes from an int to fixed point number.
m | An integer. |
int
. Definition at line 34 of file utility.c.
Referenced by hs_look4hup(), and linear_to_fixed().
int intvoid | ( | void | ) |
A dummy function with void
inputs that returns a int
.
Use this as the default for function pointers.
Definition at line 131 of file utility.c.
References error_occurred().
00131 {error_occurred(ERROR_UTIL_DUMMY);return 0;}
int intvoid_noerror | ( | void | ) |
fixed linear_to_fixed | ( | int | offset, | |
float | coeff, | |||
int | value | |||
) |
Calculates the result of plugging in value
into the linear equation described by the offset
and coeff
as a fixed point value.
Used in converting between units.
retval = (coeff * value) + offset
offset | The offset of the linear equation. Often called b . | |
coeff | The coefficient of the linear equation. Often called m . | |
value | The value to be plugged into the linear equation. Often called x . |
value
into the linear equation. Definition at line 84 of file utility.c.
References fixed_mult(), float_to_fixed(), and int_to_fixed().
00084 { 00085 int a, b, c, d, e; 00086 a = value; 00087 b = a - offset; //subtract the offset 00088 c = -1 * int_to_fixed(b); //convert to fixed point 00089 d = float_to_fixed(coeff); //convert coefficient to fixed point 00090 e = fixed_mult(c,d); //multiply gain to get amps in fixed point 00091 return e; 00092 }
void tic | ( | void | ) |
void tic_toc_init | ( | VOID_INT_F | print_f | ) |
void toc | ( | void | ) |
void voidint | ( | int | a | ) |
A dummy function with an int
input that returns void
.
Use this as the default for function pointers.
a | Dummy integer. |
Definition at line 117 of file utility.c.
References error_occurred().
00117 {error_occurred(ERROR_UTIL_DUMMY);}
void voidint_noerror | ( | int | a | ) |
void voidvoid | ( | void | ) |
A dummy function with void
inputs that returns void
.
Use this as the default for function pointers.
Definition at line 109 of file utility.c.
References error_occurred().
00109 {error_occurred(ERROR_UTIL_DUMMY);}
void voidvoid_noerror | ( | void | ) |
VOID_INT_F tt_print = voidint |
A print or transmit function for the execution time.
Definition at line 137 of file utility.c.
Referenced by tic_toc_init(), and toc().