CALPOLY MECHATRONICS
Documentation for all Mechatronics Labs
encoderDriver.Encoder Class Reference

The Encoder class reads ticks from a quadrature encoder and converts them to the shaft position in rotations. More...

Public Member Functions

def __init__ (self, IN1_pin, IN2_pin, timer, ticksPerRev=4000)
 Method to initialise an Encoder object. More...
 
def update (self)
 Method to update the current position of the encoder.
 
def get_position (self)
 Method to get the last read position of the encoder. More...
 
def get_radians (self)
 Method to get the last read position of the encoder. More...
 
def get_degrees (self)
 Method to get the last read position of the encoder. More...
 
def set_position (self, pos=0)
 Method to reset the position of the encoder to a given value. More...
 
def get_delta (self)
 Method to get the difference between the last two position readings. More...
 

Public Attributes

 timer
 the pyb.Timer object to read from the input pins
 
 ticksPerRev
 The total number of timer ticks in a revolution. More...
 
 CH1
 The first channel of the encoder.
 
 CH2
 The seccond channel of the encoder.
 
 position
 The current recorded position of the encoder, in rotations from initialization.
 
 prevPosition
 The previous position of the encoder, in rotations from initialization.
 
 prevTick1
 The previous tick count of encoder channel 1, self.CH1.
 
 prevTick2
 The previous tick count of encoder channel 2, self.CH2.
 
 lastPrintedPostion
 The last position printed to the console for debugging.
 

Detailed Description

The Encoder class reads ticks from a quadrature encoder and converts them to the shaft position in rotations.

Constructor & Destructor Documentation

◆ __init__()

def encoderDriver.Encoder.__init__ (   self,
  IN1_pin,
  IN2_pin,
  timer,
  ticksPerRev = 4000 
)

Method to initialise an Encoder object.

Parameters
IN1_pinThe pyb.Pin object connected to channel one of the encoder.
IN2_pinThe pyb.Pin object connected to channel two of the encoder.
timerThe pyb.Timer object to read from the input pins.
ticksPerRevThe total number of timer ticks in a revolution. Include both channels' rising and falling edges.

Member Function Documentation

◆ get_degrees()

def encoderDriver.Encoder.get_degrees (   self)

Method to get the last read position of the encoder.

Returns
The last read position of the encoder, in degrees.

◆ get_delta()

def encoderDriver.Encoder.get_delta (   self)

Method to get the difference between the last two position readings.

Returns
The difference of the last two position readings, in rotations.

◆ get_position()

def encoderDriver.Encoder.get_position (   self)

Method to get the last read position of the encoder.

Returns
The last read position of the encoder, in rotations.

◆ get_radians()

def encoderDriver.Encoder.get_radians (   self)

Method to get the last read position of the encoder.

Returns
The last read position of the encoder, in radians.

◆ set_position()

def encoderDriver.Encoder.set_position (   self,
  pos = 0 
)

Method to reset the position of the encoder to a given value.

Parameters
posThe position to set the encoder position to, in rotations.

Member Data Documentation

◆ ticksPerRev

encoderDriver.Encoder.ticksPerRev

The total number of timer ticks in a revolution.

Include both channels' rising and falling edges.


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