Ryan McLaughlin | Mechatronics Portfolio
encoder.encoder Class Reference

Encoder driver class. More...

Public Member Functions

def __init__ (self, pin1, pin2, timerNum, debugFlag=False)
 Constructor for class encoder More...
 
def update (self)
 Updates encoder position. More...
 
def get_position (self)
 Retrieves the current encoder position. More...
 
def set_position (self, newPosition)
 Sets the encoder position. More...
 
def get_delta (self)
 Retrieves the last change in encoder position (in ticks, not angle) More...
 
def get_speed (self)
 Gets the current encoder speed in rpm. More...
 

Public Attributes

 debugFlag
 Debugging flag for print statements to be shown in Putty.
 
 timerNum
 Timer number on Nucleo board for encoder.
 
 pin1
 Pin 1 for encoder.
 
 pin2
 Pin 2 for encoder.
 
 tim
 definition of timer More...
 
 tim_ch1
 First encoder timer channel.
 
 tim_ch2
 Second encoder timer channel.
 
 lastTime
 Previous time, used for determining speed.
 
 currentTime
 Current absolute time in microseconds.
 
 lastPos
 Last position, updated at the end of each encoder update.
 
 theta
 Current angle (in degrees) of encoder.
 
 speed
 Current speed (in rpm) of encoder.
 
 realPeriod
 Time between updates, used for determining speed.
 
 currentPos
 Current encoder count.
 
 deltaTicks
 Difference in encoder count since last update. More...
 

Detailed Description

Encoder driver class.

Class for implementing methods related to encoders, such as getting the most recent position or speed or updating the count.

Constructor & Destructor Documentation

◆ __init__()

def encoder.encoder.__init__ (   self,
  pin1,
  pin2,
  timerNum,
  debugFlag = False 
)

Constructor for class encoder

Parameters
pin1Encoder pin # 1
pin2Encoder pin # 2
timerNumCorresponding timer based on datasheet
debugFlagDebugging flag set to True or False

Member Function Documentation

◆ get_delta()

def encoder.encoder.get_delta (   self)

Retrieves the last change in encoder position (in ticks, not angle)

Can be called from the PC side script

Returns
Delta, last adjusted change in enooder count

◆ get_position()

def encoder.encoder.get_position (   self)

Retrieves the current encoder position.

Used by the controller task, as well as being callable by key press from the PC script

Returns
Theta, current encoder position

◆ get_speed()

def encoder.encoder.get_speed (   self)

Gets the current encoder speed in rpm.

Used by the controller task, as well as being callable by key press from the PC script

Returns
Omega, current speed measured by encoder

◆ set_position()

def encoder.encoder.set_position (   self,
  newPosition 
)

Sets the encoder position.

Can be called from the front end to zero an encoder position

Parameters
newPositionTakes in the new desired encoder position value

◆ update()

def encoder.encoder.update (   self)

Updates encoder position.

This method implements an alogrithm developed in lecture for interpreting tick count changes into correct changes in encoder angular displacement. The encoder count can overflow or underflow, so these values are not enough on their own.

Member Data Documentation

◆ deltaTicks

encoder.encoder.deltaTicks

Difference in encoder count since last update.

This value will be adjusted based on algorithm

◆ tim

encoder.encoder.tim

definition of timer

Period of 35535 (encoder count before overflow occurs), prescaler of 0


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