My Project
encoder3.Encoder Class Reference

Public Member Functions

def __init__ (self, timerNum, pin1, pin2, Period, Prescaler)
 An encoder driver that reads timer outputs from connected pins. More...
 
def update (self)
 updates the recorded position of the encoder More...
 
def get_position (self)
 returns the most recently updated position of the encoder More...
 
def set_position (self, newPosition)
 resets the position to a specified value More...
 
def get_delta (self)
 returns difference between the last two recorded position More...
 

Public Attributes

 timerNum
 Timer for the set of encoder pins.
 
 pin1
 first pin for Encoder
 
 pin2
 second pin for Encoder
 
 Period
 period for running the timer object
 
 Prescaler
 prescaler for the timer object
 
 TIM
 Timer object for Encoder.
 
 currPosition
 Channel 1 for Timer object. More...
 
 prevPosition
 Previous position.
 
 delta
 difference between last two recorded positions
 
 newPosition
 new position
 

Constructor & Destructor Documentation

◆ __init__()

def encoder3.Encoder.__init__ (   self,
  timerNum,
  pin1,
  pin2,
  Period,
  Prescaler 
)

An encoder driver that reads timer outputs from connected pins.

The driver takes the timer channels, 2 pin numbers, period and prescaler that will be utilized to count an encoder channel. The driver accounts for timer overflow and is used to control a motor's position.

Parameters
timerNumthe timer channel for the set of pins
pin1the first pin the encoder is connected to
pin2the second pin the encoder is connected to
Periodthe largest number that can stored in timer
Prescalerthe frequency dividier or period multiplier

Member Function Documentation

◆ get_delta()

def encoder3.Encoder.get_delta (   self)

returns difference between the last two recorded position

Returns
the difference of the last two updated positions

◆ get_position()

def encoder3.Encoder.get_position (   self)

returns the most recently updated position of the encoder

Returns
the most recent updated position value

◆ set_position()

def encoder3.Encoder.set_position (   self,
  newPosition 
)

resets the position to a specified value

this function takes in a new position value and replaces it with the current value. The previous current value is stored in a previous position variable.

Parameters
newPositiona new position set by the user
Returns
new set current position

◆ update()

def encoder3.Encoder.update (   self)

updates the recorded position of the encoder

This update counts the position of the motor, and fixes the delta readings by adjusting depending on what the defined period is. This function stores the previous counter value and creates a new counter value each time the function is ran.

Member Data Documentation

◆ currPosition

encoder3.Encoder.currPosition

Channel 1 for Timer object.

Channel 2 for Timer object

Current position


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