TeensyNanoExoCode
Loading...
Searching...
No Matches
Classes | Functions
utils Namespace Reference

contains general utility functions for the exo More...

Classes

union  FloatByteUnion
 
union  ShortIntByteUnion
 
class  SpeedCheck
 Class used to check the loop speed without serial prints, by toggling a pin after initialized, toggle will need to be called each loop. More...
 

Functions

bool get_is_left (config_defs::joint_id id)
 Takes in the joint id and returns if the left indicator bit is set as a bool.
 
bool get_is_left (uint8_t id)
 Takes in the joint id and returns if the left indicator bit is set as a bool.
 
uint8_t get_joint_type (config_defs::joint_id id)
 Takes in the joint id and returns the id with the left/right bits masked out. Returning uint8_t rather than joint_id type since we have to typecast to do logical stuff anyways.
 
uint8_t get_joint_type (uint8_t id)
 Takes in the joint id and returns the id with the left/right bits masked out. Returning uint8_t rather than joint_id type since we have to typecast to do logical stuff anyways.
 
bool schmitt_trigger (float value, bool is_high, float lower_threshold, float upper_threshold)
 Returns the new state of the system based on the value and past state. Takes in the current value, if the state is currently high, and the lower and upper threshold Floats are used so that ints will be promoted but it will still work with floats. May cause issues with very large ints. Templates could be used in the future but seemed to have issues if all types were not present in the template, e.g. is_high is always a bool. A schmitt trigger is a way of tracking if a noisy signal is high or low When it is low it must go above the upper threshold before it is high When it is high it must go below the lower threshold before it is low. This way if the signal crosses one threshold multiple times it won't register as changing multiple times.
 
int rate_limit (int setpoint, int last_value, int *last_time, int rate_per_ms)
 Limits the rate at which a value can change.
This is useful when you would like a variable to gradually come on.
 
uint8_t update_bit (uint8_t original, bool val, uint8_t loc)
 sets/clears the specified bit in a unit8_t.
 
uint16_t update_bit (uint16_t original, bool val, uint8_t loc)
 sets/clears the specified bit in a unit16_t.
 
bool get_bit (uint8_t original, uint8_t loc)
 Returns the bit in a specific location in a uint8_t.
 
bool get_bit (uint16_t original, uint8_t loc)
 Returns the bit in a specific location in a uint16.
 
float degrees_to_radians (float)
 converts from degrees to radians
 
float radians_to_degrees (float)
 converts from radians to degrees
 
String remove_all_chars (String str, char rmv)
 Searches str for 'rmv characters and deletes them all, returns new string todo: Chance update comments.
 
String remove_all_chars (char *arr, char rmv)
 
int get_char_length (int ofInt)
 given and integer, return the number of characters in it todo: Chance update comments
 
bool is_little_endian ()
 Returns 1 if system uses little endian floating points. This confirms that the floating points match if not the byte order needs to be flipped. Not tested with big endian or 64 bit systems.
 
void float_to_uint8 (float num_to_convert, uint8_t *converted_bytes)
 Takes in a float and a byte array reference Puts the bytes of the float into the array in little endian Not tested with big endian or 64 bit systems.
 
void uint8_to_float (uint8_t *bytes_to_convert, float *converted_float)
 Takes in a byte array address in little endian form containing a broken up float Returns a reconstituted float from the bytes in the form (endianess) the system uses. Not tested with big endian or 64 bit systems.
 
void float_to_short_fixed_point_bytes (float num_to_convert, uint8_t *converted_bytes, uint8_t factor)
 converts float into individual bytes of a fixed point short.

 
void short_fixed_point_bytes_to_float (uint8_t *bytes_to_convert, float *converted_val, uint8_t factor)
 converts a set of bytes in a fixed point short int into a float
 
float ewma (float new_value, float filter_value, float alpha)
 Exponential Weighted Moving Average. Used to smooth out noisy data.
 
uint8_t ff_to_fe (uint8_t val)
 
void spin_on_error_with (String message)
 Never returns from this function, used for critical errors.
 
bool is_close_to (float val1, float val2, float tolerance)
 Checks if two floats are close to each other within a tolerance.
 
std::pair< float, float > online_std_dev (std::queue< float > set)
 Given a set of data and maximum size. Returns the new mean and standard deviation.
 
bool is_outside_range (float val, float min, float max)
 Checks if a value is outside of a range.
 
String remove_all_chars (char *arr, int len, char rmv)
 
template<typename T >
int elements_are_equal (T arr1, T arr2, int length)
 Checks if all elements of the array are equal. Arrays must be the same length and type todo: Chance update comments.
 
template<typename T >
void set_elements_equal (T arr1, T arr2, int length)
 Sets arr2 elements equal to arr1 elements. Arrays must be the same length and type todo: Chance update comments.
 

Detailed Description

contains general utility functions for the exo

Function Documentation

◆ degrees_to_radians()

float utils::degrees_to_radians ( float  )

converts from degrees to radians

Parameters
adegree value
Returns
the value converted to radians

◆ elements_are_equal()

template<typename T >
int utils::elements_are_equal ( arr1,
arr2,
int  length 
)

Checks if all elements of the array are equal. Arrays must be the same length and type todo: Chance update comments.

◆ ewma()

float utils::ewma ( float  new_value,
float  filter_value,
float  alpha 
)

Exponential Weighted Moving Average. Used to smooth out noisy data.

Parameters
new_valueNew value to add to the filter
filter_valuePrevious value of the filter
alphaTuning parameter, 0.0 < alpha < 1.0
Returns
float

◆ ff_to_fe()

uint8_t utils::ff_to_fe ( uint8_t  val)

◆ float_to_short_fixed_point_bytes()

void utils::float_to_short_fixed_point_bytes ( float  num_to_convert,
uint8_t *  converted_bytes,
uint8_t  factor 
)

converts float into individual bytes of a fixed point short.

Parameters
floatto convert
arrayof sizeof(short int) to store the individual bytes
Here is the call graph for this function:

◆ float_to_uint8()

void utils::float_to_uint8 ( float  num_to_convert,
uint8_t *  converted_bytes 
)

Takes in a float and a byte array reference Puts the bytes of the float into the array in little endian Not tested with big endian or 64 bit systems.

Parameters
floatto convert
arrayof sizeof(float) to store the individual bytes
Here is the call graph for this function:

◆ get_bit() [1/2]

bool utils::get_bit ( uint16_t  original,
uint8_t  loc 
)

Returns the bit in a specific location in a uint16.

Parameters
theuint16_t to read
thelocation of the bit to read
Returns
the value at the bit location

◆ get_bit() [2/2]

bool utils::get_bit ( uint8_t  original,
uint8_t  loc 
)

Returns the bit in a specific location in a uint8_t.

Parameters
theuint8_t to read
thelocation of the bit to read
Returns
the value at the bit location

◆ get_char_length()

int utils::get_char_length ( int  ofInt)

given and integer, return the number of characters in it todo: Chance update comments

◆ get_is_left() [1/2]

bool utils::get_is_left ( config_defs::joint_id  id)

Takes in the joint id and returns if the left indicator bit is set as a bool.

Parameters
jointid
Returns
1 if the id is for the left side
Here is the call graph for this function:

◆ get_is_left() [2/2]

bool utils::get_is_left ( uint8_t  id)

Takes in the joint id and returns if the left indicator bit is set as a bool.

Parameters
jointid
Returns
1 if the id is for the left side

◆ get_joint_type() [1/2]

uint8_t utils::get_joint_type ( config_defs::joint_id  id)

Takes in the joint id and returns the id with the left/right bits masked out. Returning uint8_t rather than joint_id type since we have to typecast to do logical stuff anyways.

Parameters
jointid
Returns
joint id with the side bits masked out
Here is the call graph for this function:

◆ get_joint_type() [2/2]

uint8_t utils::get_joint_type ( uint8_t  id)

Takes in the joint id and returns the id with the left/right bits masked out. Returning uint8_t rather than joint_id type since we have to typecast to do logical stuff anyways.

Parameters
jointid
Returns
joint id with the side bits masked out

◆ is_close_to()

bool utils::is_close_to ( float  val1,
float  val2,
float  tolerance 
)

Checks if two floats are close to each other within a tolerance.

Parameters
val1
val2
tolerance
Returns
true
false

◆ is_little_endian()

bool utils::is_little_endian ( )

Returns 1 if system uses little endian floating points. This confirms that the floating points match if not the byte order needs to be flipped. Not tested with big endian or 64 bit systems.

Returns
1 if system is little endian

◆ is_outside_range()

bool utils::is_outside_range ( float  val,
float  min,
float  max 
)

Checks if a value is outside of a range.

Parameters
val
min
max
Returns
true
false

◆ online_std_dev()

std::pair< float, float > utils::online_std_dev ( std::queue< float >  set)

Given a set of data and maximum size. Returns the new mean and standard deviation.

Parameters
setQueue of data to calculate the mean and standard deviation of
Returns
std::pair<float, float> Mean and standard deviation, respectively

◆ radians_to_degrees()

float utils::radians_to_degrees ( float  )

converts from radians to degrees

Parameters
aradian value
Returns
the value converted to degrees

◆ rate_limit()

int utils::rate_limit ( int  setpoint,
int  last_value,
int *  last_time,
int  rate_per_ms 
)

Limits the rate at which a value can change.
This is useful when you would like a variable to gradually come on.

Parameters
currentvalue the system is moving towards
theprevious value the system was at
pointerto the last time the output value was set
ratethe value can change per ms
Returns
the next value to the system can be at based on the rate limit.

◆ remove_all_chars() [1/3]

String utils::remove_all_chars ( char *  arr,
char  rmv 
)
Here is the call graph for this function:

◆ remove_all_chars() [2/3]

String utils::remove_all_chars ( char *  arr,
int  len,
char  rmv 
)

◆ remove_all_chars() [3/3]

String utils::remove_all_chars ( String  str,
char  rmv 
)

Searches str for 'rmv characters and deletes them all, returns new string todo: Chance update comments.

◆ schmitt_trigger()

bool utils::schmitt_trigger ( float  value,
bool  is_high,
float  lower_threshold,
float  upper_threshold 
)

Returns the new state of the system based on the value and past state. Takes in the current value, if the state is currently high, and the lower and upper threshold Floats are used so that ints will be promoted but it will still work with floats. May cause issues with very large ints. Templates could be used in the future but seemed to have issues if all types were not present in the template, e.g. is_high is always a bool. A schmitt trigger is a way of tracking if a noisy signal is high or low When it is low it must go above the upper threshold before it is high When it is high it must go below the lower threshold before it is low. This way if the signal crosses one threshold multiple times it won't register as changing multiple times.

Parameters
Thecurrent signal reading
Thecurrent state of the trigger
Thelower threshold a high signal must pass to go low
Theupper threshold a low signal must pass to go high
Returns
the state of the trigger.

◆ set_elements_equal()

template<typename T >
void utils::set_elements_equal ( arr1,
arr2,
int  length 
)

Sets arr2 elements equal to arr1 elements. Arrays must be the same length and type todo: Chance update comments.

◆ short_fixed_point_bytes_to_float()

void utils::short_fixed_point_bytes_to_float ( uint8_t *  bytes_to_convert,
float *  converted_val,
uint8_t  factor 
)

converts a set of bytes in a fixed point short int into a float

Parameters
arrayof size sizeof(short int) containing the bytes to convert
pointerto place the converted value into
Here is the call graph for this function:

◆ spin_on_error_with()

void utils::spin_on_error_with ( String  message)

Never returns from this function, used for critical errors.

Parameters
message

◆ uint8_to_float()

void utils::uint8_to_float ( uint8_t *  bytes_to_convert,
float *  converted_float 
)

Takes in a byte array address in little endian form containing a broken up float Returns a reconstituted float from the bytes in the form (endianess) the system uses. Not tested with big endian or 64 bit systems.

Parameters
arrayof size sizeof(float) containing the bytes to convert
pointerto place the converted value into
Here is the call graph for this function:

◆ update_bit() [1/2]

uint16_t utils::update_bit ( uint16_t  original,
bool  val,
uint8_t  loc 
)

sets/clears the specified bit in a unit16_t.

Parameters
Theoriginal uint16_t
Thebit value you would like to use
Thelocation you are placing that bit.
Returns
The uint16_t with the bit updated

◆ update_bit() [2/2]

uint8_t utils::update_bit ( uint8_t  original,
bool  val,
uint8_t  loc 
)

sets/clears the specified bit in a unit8_t.

Parameters
Theoriginal uint8_t
Thebit value you would like to use
Thelocation you are placing that bit.
Returns
The uint8_t with the bit updated