RomiCoder module

Houses RomiCoder class and test code.

class RomiCoder.RomiCoder(encoderChannelAPin, encoderChannelBPin, AR, PS, encoderTimerNumber)

Bases: object

Controls quadrature encoder.

Each instance of an encoder takes two timers to operate. one timer is already determined by the pins used for the particular encoder. This timer is set up in the constructor. The second timer is used to set an interrupt. for the encoder to recalculate its position.

Parameters:
  • encoderChannelAPin (pyb.Pin) – Corresponds to channel 1 of the encoder timer.

  • encoderChannelBPin (pyb.Pin) – Corresponds to channel 2 of the encoder timer.

  • AR (int) – The auto reload value of the encoder timer.

  • PS (int) – The timer prescaler.

  • encoderTimerNumber (int) – The number of the timer that is to be used for the encoder (eg TIM1).

get_delta()

This returns a delta not a rate.

Takes the encoder delta between the previous true encoder reading and the most recent one.

Returns:

True delta value

Return type:

int

get_position()

returns total encoder position

the encoder will be updating at the rate specified by the frequency of the timer input when an encoder instance is created. This function only needs to be called when a position is desired.

Returns:

total encoder position

Return type:

int

get_rate()

Returns a rate per milliseconds.

Takes the encoder delta between the previous true encoder reading and the most recent one, divides it by the difference between current time and previous time.

Returns:

Rate unit/ms value.

Return type:

float

get_time()

Returns the last update() time.

Takes the time_ms of the most recent update() call.

Returns:

Time in ms.

Return type:

float

get_timeDelta()

Returns a delta of time.

Takes the time_ms of the most recent .update() call, ticks_diff() from previous .update() call.

Returns:

Time delta in ms.

Return type:

float

update()

Updates true known encoder position

This is different from the raw encoder position, since that value overflows according to the auto-reload value. takes difference between current and prior raw encoder values, then determines based on the delta whether to count that as an overflow or not This means that the sample rate for calling this function needs to be sufficiently fast to avoid mis-classifying deltas as overflowed when they are not. This does not return any position

Returns:

None

zero()

Sets the encoder position back to 0

This does not reset the delta values. Raw readings stay intact

Returns:

None