TeensyNanoExoCode
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
Utilities.cpp File Reference
#include "Utilities.h"
#include "Logger.h"
Include dependency graph for Utilities.cpp:

Classes

union  utils::FloatByteUnion
 
union  utils::ShortIntByteUnion
 

Namespaces

namespace  utils
 contains general utility functions for the exo
 

Functions

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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
uint8_t utils::update_bit (uint8_t original, bool val, uint8_t loc)
 sets/clears the specified bit in a unit8_t.
 
uint16_t utils::update_bit (uint16_t original, bool val, uint8_t loc)
 sets/clears the specified bit in a unit16_t.
 
bool utils::get_bit (uint8_t original, uint8_t loc)
 Returns the bit in a specific location in a uint8_t.
 
bool utils::get_bit (uint16_t original, uint8_t loc)
 Returns the bit in a specific location in a uint16.
 
float utils::degrees_to_radians (float)
 converts from degrees to radians
 
float utils::radians_to_degrees (float)
 converts from radians to degrees
 
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.
 
String utils::remove_all_chars (char *arr, char rmv)
 
int utils::get_char_length (int ofInt)
 given and integer, return the number of characters in it todo: Chance update comments
 
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.
 
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.
 
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.
 
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.

 
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
 
float utils::ewma (float new_value, float filter_value, float alpha)
 Exponential Weighted Moving Average. Used to smooth out noisy data.
 
uint8_t utils::ff_to_fe (uint8_t val)
 
void utils::spin_on_error_with (String message)
 Never returns from this function, used for critical errors.
 
bool utils::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 > utils::online_std_dev (std::queue< float > set)
 Given a set of data and maximum size. Returns the new mean and standard deviation.
 
bool utils::is_outside_range (float val, float min, float max)
 Checks if a value is outside of a range.