405 Documentation  9.0
encoderDriver.Encoder Class Reference

Tells where the motor is at any given time. More...

Public Member Functions

def __init__ (self, idNum, pin1, pin2, ch1, ch2, timer)
 Initialization Function. More...
 
def __repr__ (self)
 Name it. More...
 
def update (self)
 Update method. More...
 
def getPosition (self)
 Method to get the position. More...
 
def setPosition (self, pos=0)
 Saves the users desired position. More...
 
def getDelta (self)
 Change in position. More...
 

Public Attributes

 id
 
 pin1
 
 pin2
 
 timer
 
 prevPosition
 
 position
 
 maxVal
 

Detailed Description

Tells where the motor is at any given time.

Input 2 pins, 2 channels, and a timer object to run. Once given, this object will be able to read the motor position, update its position, set a desired position, compute its change in position, and compute how far it is from the users desired position. These position readings can be used to determine where the motor is at any given time relative to where it started as well as the motor speed.

Constructor & Destructor Documentation

◆ __init__()

def encoderDriver.Encoder.__init__ (   self,
  idNum,
  pin1,
  pin2,
  ch1,
  ch2,
  timer 
)

Initialization Function.

Stores the parameters input by the user when creating the class object so that they may be used later by other functions.

Parameters
idNumID number of motor
pin1pin to read encoder chA values
pin2pin to read encoder chB values
ch1encoder channel A
ch2endcoder channel B
timertimer to read encoder

Member Function Documentation

◆ __repr__()

def encoderDriver.Encoder.__repr__ (   self)

Name it.

Define how an Encoder object is represented. Basically we give it a name.

Parameters
None

◆ getDelta()

def encoderDriver.Encoder.getDelta (   self)

Change in position.

Takes the two most recent values from the update method and computes the difference between the two. If the user were timing the system and taking values at a specific interval, this could be used to compute the speed of the motor. However, the user must use the update method after this one in order to change the most recent value and replace the prevPosition value with the position value, otherwise this method will return the same value over and over.

Parameters
None

◆ getPosition()

def encoderDriver.Encoder.getPosition (   self)

Method to get the position.

This method uses the counter method of our timer object to count how many ticks have gone by since the last time we passed our zero point on the encoder. That means that it simply tells us where we are in our encoder rotation. This method returns a numerical value which represents the motor position.

Parameters
None

◆ setPosition()

def encoderDriver.Encoder.setPosition (   self,
  pos = 0 
)

Saves the users desired position.

The setPosition method allows the user to input a position which this method will then save as a value to be used at a later time. This value will most likely be zero, as the user will want to start their table off in a balanced state, otherwise the user will have no idea how far the system needs to go in order to become level.

Parameters
posAn inputed value for the user, allowing them to choose where they want to be, default 0

◆ update()

def encoderDriver.Encoder.update (   self)

Update method.

Updates the position of the motor so that the user can later tell how far the motor has traveled. It stores the current value stored in the position variable as "prevPosition", then runs the getPosision() method that will be described later to put the current value for the position into the position variable. This way the most recent position value and the one before it are both stored somewhere. Does not return a value.

Parameters
None

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