ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
encoder.EncoderDriver Class Reference

A class to interact with two encoders. More...

Public Member Functions

def __init__ (self, e1_1=pyb.Pin.board.PB6, e1_2=pyb.Pin.board.PB7, e2_1=pyb.Pin.board.PC6, e2_2=pyb.Pin.board.PC7, current_position_a=0, current_position_b=0)
 Initializes the Encoders and their respective timers. More...
 
def update (self)
 Updates the current position of each encoder. More...
 
def get_position (self)
 Returns the most recently updated positions of the encoders. More...
 
def set_position (self, a, b)
 Sets the position of the encoders to a specific value. More...
 
def get_delta (self)
 Calculates difference between the two most recent recorded positions. More...
 

Public Attributes

 p11
 
 p12
 
 p21
 
 p22
 
 tim4
 
 ch1a
 
 ch2a
 
 tim8
 
 ch1b
 
 ch2b
 
 cnt_a
 
 cnt_last_a
 
 cnt_b
 
 cnt_last_b
 
 pos_a
 
 pos_last_a
 
 pos_b
 
 pos_last_b
 

Detailed Description

A class to interact with two encoders.

This class connects with two encoders and can be used to update their current angle periodically. It can also get changes in angle, and reset the current angle to a user defined value.

Constructor & Destructor Documentation

◆ __init__()

def encoder.EncoderDriver.__init__ (   self,
  e1_1 = pyb.Pin.board.PB6,
  e1_2 = pyb.Pin.board.PB7,
  e2_1 = pyb.Pin.board.PC6,
  e2_2 = pyb.Pin.board.PC7,
  current_position_a = 0,
  current_position_b = 0 
)

Initializes the Encoders and their respective timers.

Parameters
e1_1pyb.Pin for Encoder 1, Channel 1 (default=pyb.Pin.board.PB6)
e1_2pyb.Pin for Encoder 1, Channel 2 (default=pyb.Pin.board.PB7)
e2_1pyb.Pin for Encoder 2, Channel 1 (default=pyb.Pin.board.PC6)
e2_2pyb.Pin for Encoder 2, Channel 2 (default=pyb.Pin.board.PC7)
current_position_aInitial position of Encoder 1 (default=0)
current_position_bInitial position of Encoder 2 (default=0)
Returns
Returns nothing.

Member Function Documentation

◆ get_delta()

def encoder.EncoderDriver.get_delta (   self)

Calculates difference between the two most recent recorded positions.

Returns
Returns a tuple containing the change in position for each encoder between the last two updates.

◆ get_position()

def encoder.EncoderDriver.get_position (   self)

Returns the most recently updated positions of the encoders.

Returns
Returns a tuple containing the positions of the encoders.

◆ set_position()

def encoder.EncoderDriver.set_position (   self,
  a,
  b 
)

Sets the position of the encoders to a specific value.

Parameters
aThe position for encoder 1
bThe position for encoder 2
Returns
Returns nothing.

◆ update()

def encoder.EncoderDriver.update (   self)

Updates the current position of each encoder.

Returns
Returns nothing.

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