The encoder driver drv/encoder.c should be extended to support computing theta and omega values. These values are based on the number of pulses per revolution of the connected encoder.
The desired functions are simply for convenience; they store no state and are rather simple, but are common actions which anyone who uses an encoder will have to do. If we have these, then the user application does not have to worry about the particular encoder pulses per rev. Instead, they just configure the driver at boot and then it keeps track of it.
// Compute the current speed in mechanical rad/s
//
// This function will subtract the previous position from the current position and divide by delta time.
// Finally, it will use the steps per rev to get the answer in a standardized mechanical rad/s
double encoder_calc_speed(double dt, uint32_t pos_prev);
// Compute the current position in mechanical rad/s
//
// This function simply uses the steps per rev to get the answer in a standardized mechanical radians
double encoder_get_theta(void);
// Compute resolution in mechanical rads
//
// This function returns the resolution of the encoder output in mechanical radians
double encoder_get_theta_resolution(void);
The encoder driver
drv/encoder.cshould be extended to support computing theta and omega values. These values are based on the number of pulses per revolution of the connected encoder.The desired functions are simply for convenience; they store no state and are rather simple, but are common actions which anyone who uses an encoder will have to do. If we have these, then the user application does not have to worry about the particular encoder pulses per rev. Instead, they just configure the driver at boot and then it keeps track of it.