Matthew's Portfolio
encoderDriver.encoderDriver Class Reference

Encoder class to allow for several encoders to be used. More...

Public Member Functions

def __init__ (self, debugFlag=True, pin1=Pin.cpu.B6, pin2=Pin.cpu.B7, encTimer=4)
 Create an encoder object to find position and speeds. More...
 
def update (self)
 Update the position and velocity of the encoders. More...
 
def getPosition (self)
 Get the position of the encoder. More...
 
def setPosition (self, newPosition)
 Zero the encoder. More...
 
def getSpeed (self)
 Get the speed of the encoder. More...
 

Public Attributes

 debugFlag
 Debugging flag for detailed analysis while running.
 
 period
 The period of the counter (maximum, 0xFFFF)
 
 TIM4
 Create a timer object.
 
 tim4ch1
 The first channel for the timer.
 
 tim4ch2
 The second channel for the timer.
 
 currentTick
 Use the timer to get the current count for the tick.
 
 previousTick
 Create a variable for the previous tick.
 
 theta
 Converts ticks into radians (PPR = 4000)
 

Detailed Description

Encoder class to allow for several encoders to be used.

This class will allow for the position, delta, and speed of the encoders to be tracked.

Constructor & Destructor Documentation

◆ __init__()

def encoderDriver.encoderDriver.__init__ (   self,
  debugFlag = True,
  pin1 = Pin.cpu.B6,
  pin2 = Pin.cpu.B7,
  encTimer = 4 
)

Create an encoder object to find position and speeds.

This object will be called in order to find the current positions, deltas, speeds, or to reset the encoder back to zero.

Parameters
pin1Input pin to use for the first channel. User must input the exact pin name, for example, Pin.cpu.B6 for encoder 1 or Pin.cpu.C6 for encoder 2.
pin2Input pin to use for the second channel. User must input the exact pin name, for example, Pin.cpu.B7 for encoder 1 or Pin.cpu.C7 for encoder 2.
encTimerTimer number that will be used for the encoder. Possible options include timer 4 and 8.
debugFlagEnables or prevents certain print statements from appearing.

Member Function Documentation

◆ getPosition()

def encoderDriver.encoderDriver.getPosition (   self)

Get the position of the encoder.

When called, this function will output the current angle of the encoder in radians.

Returns
The current position of the encoder.

◆ getSpeed()

def encoderDriver.encoderDriver.getSpeed (   self)

Get the speed of the encoder.

When called, this function will output the current speed of the encoder in rpm.

Returns
The current speed of the encoder.

◆ setPosition()

def encoderDriver.encoderDriver.setPosition (   self,
  newPosition 
)

Zero the encoder.

When called, this will set theta to 0, thus resetting the encoder.

Parameters
newPositionThe specified position to zero the encoder to.
Returns
The new angle for the encoder.

◆ update()

def encoderDriver.encoderDriver.update (   self)

Update the position and velocity of the encoders.

This method updates the position (in ticks and radians) as well as the speed of the motor whenever called. It will return the angle in radians and speed in rad/s.


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