Encoder module

class Encoder.Encoder(timer_channel, encoder_pin_a, encoder_pin_b, ar, ps)

Bases: object

An encoder class for our motor encoders.

Objects of this class can be used to determine the current and change in position of a DC motor on one channel.

Parameters:
  • timer_channel – timer channel used by the encoder to determine position.

  • encoder_pin_a – one of the pins for the encoder to determine position

  • encoder_pin_b – the other pin for the encoder to determine position

  • ar – auto reload value for the motor (set to 65535 for this lab)

  • ps – used if larger steps are needed (set to zero for this lab)

get_delta()

A function to output the current delta of the motor

Function uses the attribute of the encoder class. :returns: Returns the delta of the motor.

get_position()

A function to output the current position of the motor

Function uses the attribute of the encoder class.

Returns:

Returns the position of the motor.

update()

A function to update the current position and delta of the motor.

Function uses the timer counter to determine the delta of the motor and then calculates the new position of the motor

zero()

A function to reset the position in the encoder.

Function sets the position to zero.