Matthew's Portfolio
encoder.encoder 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...
 
def getDelta (self)
 Get the delta of the encoder. More...
 

Public Attributes

 debugFlag
 Debugging flag for detailed analysis while running.
 
 period
 The period of the counter (maximum, 0xFFFF)
 
 pin1
 Create an object for the attribute pin1.
 
 pin2
 Create an object for the attribute pin2.
 
 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 degrees (PPR = 4000)
 
 deltaTick
 Variable to find the difference in ticks.
 
 speed
 Variable to hold motor speed.
 
 encCurrentTime
 Current time for the encoder.
 
 encLastTime
 Previous time for the encoder.
 
 encPeriod
 Find the elapsed time since the last computation.
 

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 encoder.encoder.__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

◆ getDelta()

def encoder.encoder.getDelta (   self)

Get the delta of the encoder.

When called, this function will output the current delta of the encoder in ticks.

Returns
The current deslta of the encoder.

◆ getPosition()

def encoder.encoder.getPosition (   self)

Get the position of the encoder.

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

Returns
The current position of the encoder.

◆ getSpeed()

def encoder.encoder.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 encoder.encoder.setPosition (   self,
  newPosition 
)

Zero the encoder.

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

Returns
The new angle for the encoder.

◆ update()

def encoder.encoder.update (   self)

Update the position and velocity of the encoders.

This method updates the position (in ticks and degrees) as well as the speed of the motor whenever called. It will be called by the controller task whenever the the p/P key is pressed, or data is being collected.


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