ME 305 Website by Cole Sheedy
encoderDriverW2.encoder Class Reference

Used to effectively read encoders and relevent information. More...

Public Member Functions

def __init__ (self, pinA, pinB, timerNumber)
 Initialization for a specific encoder. More...
 
def update (self)
 Updates absolute position of encoder. More...
 
def get_position (self)
 Simply returns the instantaneous position of the motor.
 
def get_delta (self)
 Simply returns the most recent corrected delta value calculated.
 
def set_position (self)
 Zeros the position of the rotor.
 
def get_timeDif (self)
 Returns the time difference between the two most recent encoder values.
 
def get_omega (self)
 Returns the most recently tracked "instantaneous" speed [rad/s] of the rotor.
 

Public Attributes

 pinA
 Object for input 1 of encoder to be referenced.
 
 pinB
 Object for input 2 of encoder to be referenced.
 
 tim
 Clock object that is used to read ChA and ChB from encoder.
 
 tim_ChA
 Channel object for input 1 for encoder 1.
 
 tim_ChB
 Channel object cor input 2 for encoder 1.
 
 deltaValuesList
 Array to carry the two most recent count values to determine delta.
 
 absolutePosition
 Initial position of motor in ticks.
 
 timestampValuesList
 Array of timestamps to carry the two most recent count values to determine speed.
 
 delta
 Initializing the delta value.
 
 count
 Timer value read from the encoder.
 
 timeDif
 
 correctedDelta
 Corrected delta that can be used for capturing absolute poistion.
 

Detailed Description

Used to effectively read encoders and relevent information.

This encoder class is used to constantly read quadrature encoders to determine absolute position by the update() method. Also, the initialization allows for simultaneous running of other encoders. Other methods allow for easy instantaneous data collection.

Constructor & Destructor Documentation

◆ __init__()

def encoderDriverW2.encoder.__init__ (   self,
  pinA,
  pinB,
  timerNumber 
)

Initialization for a specific encoder.

This initialization method accepts two pins. PinA and PinB represent the pins at which the encoder is connected to the Nucleo. Lastly, timerNumber represents the timer which will collect values from the A & B channels.

Parameters
pinApyb.Pin.cpu.### for input 1 of encoder to be referenced.
pinBpyb.Pin.cpu.### for input 2 of encoder to be referenced.
timerNumberNumber of timer which runs for the specific pins.

Member Function Documentation

◆ update()

def encoderDriverW2.encoder.update (   self)

Updates absolute position of encoder.

This method reads the count from the timer to determine the relative position of the encoder. Then, the method compares the updated count to the previous count, to determine a delta value. If the delta value is greater than half the period, case A, we need to correct the delta by subtracting the period. If the delta value is less than half the negative period, case B, we need to correct the delta by adding the period. If the delta is anything else, we can say no correction is needed. Once the method has the corrected delta, it adds it to the previous absolute position.

Returns
absolutePosition A continuous stream of returning the updated absolute position.

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