ME 405
enc_driver.EncDriver Class Reference

An encoder driver object. More...

Public Member Functions

def __init__ (self, ID, Pin1, Ch1, Pin2, Ch2, tim_no, CPR, debug)
 Creates an encoder object. More...
 
def update (self)
 Updates the encoder. More...
 
def get_position (self, units)
 Returns the encoder position in desired units. More...
 
def set_position (self)
 Sets the encoder position to a specified value in ticks. More...
 
def get_delta (self, units)
 Returns the current encoder delta in desired units. More...
 
def get_ddelta (self)
 Returns the current encoder delta delta in ticks. More...
 
def convert (self)
 Uses the raw encoder count values to calculate encoder position & delta in other units. More...
 
def trace (self)
 Prints a trace output when called. More...
 

Public Attributes

 ID
 The unique ID string for the object, used for trace output. More...
 
 debug
 A boolean that toggles the trace output to the command line. More...
 
 tim
 The timer objct that is used to read the encoder. More...
 
 conv_deg
 Conversion factor ticks -> degrees. More...
 
 conv_rad
 Conversion factor ticks -> radians. More...
 
 pos
 The current position of the encoder. More...
 
 prev_pos
 The previous position of the encoder. More...
 
 delta
 The difference between the current position and the previous position. More...
 
 prev_delta
 The previous delta of the encoder. More...
 
 ddelta
 The difference between the current delta and the previous delta. More...
 
 last_count
 Previous encoder count. More...
 
 t1
 Ticks value 1. More...
 
 t2
 Ticks value 2 from counter. More...
 
 pos_deg
 Encoder position in degrees. More...
 
 pos_rad
 Encoder position in radians. More...
 
 delta_deg
 Encoder delta in degrees. More...
 
 delta_rad
 Encoder delta in radians. More...
 

Detailed Description

An encoder driver object.

This class configures hardware, to monitor an encoder's position. The encoder ticks are counted using a timer object, and the timer is queried to get updated position values. The diver class corrects timer overflow errors, and is able to handle encoder rotation CW and CCW.

Constructor & Destructor Documentation

◆ __init__()

def enc_driver.EncDriver.__init__ (   self,
  ID,
  Pin1,
  Ch1,
  Pin2,
  Ch2,
  tim_no,
  CPR,
  debug 
)

Creates an encoder object.

Parameters
IDA string identifying the object for traceing output.
Pin1The pin object that will be bound to encoder channel A
Ch1The timer channel for the first pin
Pin2The pin object that will be bound to encoder channel B
Ch2The timer channel for the second pin
tim_noThe timer number that will be used to read the encoder
CPREncoder's cycles per revolution
debugA boolean that toggles the trace output on or off

Member Function Documentation

◆ convert()

def enc_driver.EncDriver.convert (   self)

Uses the raw encoder count values to calculate encoder position & delta in other units.

◆ get_ddelta()

def enc_driver.EncDriver.get_ddelta (   self)

Returns the current encoder delta delta in ticks.

◆ get_delta()

def enc_driver.EncDriver.get_delta (   self,
  units 
)

Returns the current encoder delta in desired units.

◆ get_position()

def enc_driver.EncDriver.get_position (   self,
  units 
)

Returns the encoder position in desired units.

◆ set_position()

def enc_driver.EncDriver.set_position (   self)

Sets the encoder position to a specified value in ticks.

◆ trace()

def enc_driver.EncDriver.trace (   self)

Prints a trace output when called.

◆ update()

def enc_driver.EncDriver.update (   self)

Updates the encoder.

This function passes the position from the last call to the prev_pos atribute, calculates a new delta value, corrects the delta value, and updates the encoder position.

Member Data Documentation

◆ conv_deg

enc_driver.EncDriver.conv_deg

Conversion factor ticks -> degrees.

◆ conv_rad

enc_driver.EncDriver.conv_rad

Conversion factor ticks -> radians.

◆ ddelta

enc_driver.EncDriver.ddelta

The difference between the current delta and the previous delta.

◆ debug

enc_driver.EncDriver.debug

A boolean that toggles the trace output to the command line.

◆ delta

enc_driver.EncDriver.delta

The difference between the current position and the previous position.

◆ delta_deg

enc_driver.EncDriver.delta_deg

Encoder delta in degrees.

◆ delta_rad

enc_driver.EncDriver.delta_rad

Encoder delta in radians.

◆ ID

enc_driver.EncDriver.ID

The unique ID string for the object, used for trace output.

◆ last_count

enc_driver.EncDriver.last_count

Previous encoder count.

◆ pos

enc_driver.EncDriver.pos

The current position of the encoder.

◆ pos_deg

enc_driver.EncDriver.pos_deg

Encoder position in degrees.

◆ pos_rad

enc_driver.EncDriver.pos_rad

Encoder position in radians.

◆ prev_delta

enc_driver.EncDriver.prev_delta

The previous delta of the encoder.

◆ prev_pos

enc_driver.EncDriver.prev_pos

The previous position of the encoder.

◆ t1

enc_driver.EncDriver.t1

Ticks value 1.

◆ t2

enc_driver.EncDriver.t2

Ticks value 2 from counter.

◆ tim

enc_driver.EncDriver.tim

The timer objct that is used to read the encoder.

The prescaler is set to zero and the period is set to 0xFFFF or 65535


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