Kyle Chuang | ME405 Mechatronics Portfolio
enc.EncoderDriver Class Reference

Encoder driver class. More...

Public Member Functions

def __init__ (self, pin1, pin2, timer)
 
def update (self)
 Updates the position of the encoder. More...
 
def get_position (self)
 Returns the current position of the encoder.
 
def set_position (self, pos)
 Resets the position of the encoder to the specified value "pos". More...
 
def get_delta (self)
 Returns the "good" deltas.
 

Public Attributes

 position
 
 old_count
 
 period
 
 tim
 
 new_count
 
 raw_delta
 
 delta
 

Detailed Description

Encoder driver class.

Parameters
pin1Object creating the first pin of the encoder
pin2Object creating the second pin of the encoder
timA user input which initializes the timer object.

Member Function Documentation

◆ set_position()

def enc.EncoderDriver.set_position (   self,
  pos 
)

Resets the position of the encoder to the specified value "pos".

Parameters
posA user input whose value is used to reset the position of the encoder

◆ update()

def enc.EncoderDriver.update (   self)

Updates the position of the encoder.

This function updates the position of the encoder whenever it is called. This is done by taking the differnce of the last two positions (represented by "delta" variables) and checking for the validity of the deltas. A "bad" delta, is defined when the two positions being referenced in the delta span across the encoder period (going from 0 to 0XFFFF or 0XFFFF to 0). The code then adjusts the "bad" delta by adding the period to the delta.

The position is then updated, by continuously adding "good" deltas.


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