Mechatronics
Documentation for ME 405 labs
drivers.Encoder.Encoder Class Reference

A Quadrature Encoder class to be used with the ME 405 test bench. More...

Public Member Functions

def __init__ (self, ch_A, ch_B, Timer timer, position=0)
 Constructor for the Encoder object. More...
 
def update (self)
 Update the current position and the last position. More...
 
def get_position (self, units="pulses")
 Get the current encoder position. More...
 
def set_position (self, position, units="pulses")
 Set the current encoder position. More...
 
def get_delta (self)
 Get the change in encoder position (in pulses) since last update.
 

Public Attributes

 ch_A
 Channel A.
 
 ch_B
 Channel B.
 
 enc
 The timer channel to poll which collects encoder counts.
 
 timer
 The Timer that tracks the encoder.
 
 last_count
 The previous pulse count.
 
 position
 The current absolute position as a count of pulses.
 
 PPR
 The pulse rate (Pulses Per Revolution).
 

Detailed Description

A Quadrature Encoder class to be used with the ME 405 test bench.

Supports encoder polling at a frequency of up to 65536pps

Constructor & Destructor Documentation

◆ __init__()

def drivers.Encoder.Encoder.__init__ (   self,
  ch_A,
  ch_B,
Timer  timer,
  position = 0 
)

Constructor for the Encoder object.

Parameters
ch_APin on channel A
ch_BPin on channel B
timerA Timer that will be used to track the encoder
positionAn optional initial position

Member Function Documentation

◆ get_position()

def drivers.Encoder.Encoder.get_position (   self,
  units = "pulses" 
)

Get the current encoder position.

Returns
Return the current position in the specified units. If none are specified (or they are unrecognized) return the current position in pulses.
Parameters
unitsThe units to return. Supported units:
  • pules - The number of edges (timer counts)
  • cycles - The number of cycles for a quadrature encoder (cycles = pulses / 4)
  • degrees - The total angle in degrees
  • radians - The total angle in degrees
  • revolutions - The total number of revolutions

◆ set_position()

def drivers.Encoder.Encoder.set_position (   self,
  position,
  units = "pulses" 
)

Set the current encoder position.

Returns
Return the current position in the specified units. If none are specified (or they are unrecognized) return the current position in pulses.
Parameters
positionThe new value of the encoder position.
unitsThe units to return. Supported units:
  • pules - The number of edges (timer counts)
  • cycles - The number of cycles for a quadrature encoder (cycles = pulses / 4)
  • degrees - The total angle in degrees
  • radians - The total angle in degrees
  • revolutions - The total number of revolutions

◆ update()

def drivers.Encoder.Encoder.update (   self)

Update the current position and the last position.

Update the current position and the last position. Assumes that the encoder is updated at least once every half period of the timer and handles the overflow associated. Thus any counter value above half the period is assumed to be a backwards rotation.


The documentation for this class was generated from the following file: