ME 405: Mechatronics Portfolio
EncoderDriver.EncoderDriver Class Reference

Encoder Driver Class More...

Public Member Functions

def __init__ (self, pinA, pinB, timer, PPC, CPR, gearRatio)
  Encoder class constructor More...
 
def update (self)
  Update encoder position More...
 
def getPosition (self)
  Return encoder position More...
 
def getAngle (self)
  Return encoder angle More...
 
def setPosition (self, newPosition)
  Set current relative encoder position More...
 
def getDelta (self)
  Calculate delta between encoder updates More...
 
def tick2rad (self, ticks)
  Convert encoder ticks to degrees More...
 
def getSpeed (self, interval)
  Convert encoder delta to degrees per second More...
 

Public Attributes

 pinA
 Translates the encoder pin A input into Encoder object.
 
 pinB
 Translates the encoder pin B input into Encoder object.
 
 tim
 Defines the timer which applies to pins A and B.
 
 curr_count
 Constructs channel for pin A within timer. More...
 
 prev_count
 Creates a variable to hold the previous position count of the encoder.
 
 position
 Creates a local variable to hold the total position of the encoder.
 
 delta
 Creates a local variable to hold value representing difference between current and previous position.
 
 PPC
 Define the pulses per cycle for this encoder object via user input into constructor.
 
 CPR
 Define the cycles per revolution for this encoder object via user input into constructor.
 
 gearRatio
 Define the gear ratio (motor:encoder) reduced to an integer via user input into the constructor.
 
 overflow
 Defines total number of counter values before overflow.
 

Detailed Description

Encoder Driver Class

Constructor & Destructor Documentation

◆ __init__()

def EncoderDriver.EncoderDriver.__init__ (   self,
  pinA,
  pinB,
  timer,
  PPC,
  CPR,
  gearRatio 
)

Encoder class constructor

This method constructs the Encoder object by assigning pin and timer input parameters and defining initial states of pins

Parameters
pinAThe pin location for + encoder terminal. must be properly defined as a pin object before being input into an encoder class. Use pinA = pyb.Pin.cpu. [pin letter(s) and number]
pinBThe pin location for GND encoder terminal. must follow same format for pinA
timerThe timer number which applies to both pins, which can be found using Table 17 of the Nucleo datasheet
PPCThe pulses per rotation of the encoder
CPRThe cycles per rotation of the encoder
gearRatioThe gear ratio between the motor and the output shaft on which the encoder is mounted

Member Function Documentation

◆ getAngle()

def EncoderDriver.EncoderDriver.getAngle (   self)

Return encoder angle

Returns
angle Returns the current angular position of the encoder in radians

◆ getDelta()

def EncoderDriver.EncoderDriver.getDelta (   self)

Calculate delta between encoder updates

Calculates the difference between the current and previous position counts

Returns
delta Returns the correct difference between current and previous encoder positions in ticks

◆ getPosition()

def EncoderDriver.EncoderDriver.getPosition (   self)

Return encoder position

Returns
position Returns the current position of encoder in encoder ticks

◆ getSpeed()

def EncoderDriver.EncoderDriver.getSpeed (   self,
  interval 
)

Convert encoder delta to degrees per second

Determines the angular velocity of the motor according to the encoder PPC (pulses per cycle), CPR (cycles per revolution), and gear ratio which were input into the object constructor, as well as the time interval over which the encoder delta was calculated.

Parameters
intervalThe interval of time over which delta occurs, which must be in seconds
Returns
speed Returns the speed of the encoder in deg/s

◆ setPosition()

def EncoderDriver.EncoderDriver.setPosition (   self,
  newPosition 
)

Set current relative encoder position

Sets the encoder position according to the desired user input parameter 'angle'

Parameters
newPositionThe angle to which the encoder will be set. must be an integer

◆ tick2rad()

def EncoderDriver.EncoderDriver.tick2rad (   self,
  ticks 
)

Convert encoder ticks to degrees

Converts the position of the encoder from ticks to degrees

Parameters
ticksThe position or delta of the encoder in ticks. This is most easily obtained from the self.position attribute for position or self.getDelta() method for position delta
Returns
rad Returns the position or delta in radians

◆ update()

def EncoderDriver.EncoderDriver.update (   self)

Update encoder position

Updates the encoder position after a set time interval

Member Data Documentation

◆ curr_count

EncoderDriver.EncoderDriver.curr_count

Constructs channel for pin A within timer.

Constructs channel for pin B within timer

Creates a variable to hold the current position count of the encoder


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