ME 305
Public Member Functions | Public Attributes | List of all members
encoder.Encoder Class Reference

Encoder Class. More...

Public Member Functions

def __init__ (self, pin_one, pin_two, TimerNum)
 Initializes object in Encoder class. More...
 
def zero (self)
 Sets the current position to zero. More...
 
def update (self)
 Updates position. More...
 
def get_position (self)
 Returns position. More...
 
def get_deltatime (self)
 Returns delta time. More...
 
def get_delta (self)
 Returns delta. More...
 

Public Attributes

 timer
 pyb.Timer class setting prescaler to 0 and specifying the auto-reload value ot 65535 encoder ticks More...
 
 ch1
 pyb.Timer channel 1 object created. More...
 
 ch2
 pyb.Timer channel 2 object created. More...
 
 old
 The position at the beginning of the iteration. More...
 
 new
 The position after the time has ended. More...
 
 position
 Position of the encoder. More...
 
 deltatimeold
 Old time reading of the encoder.
 
 delta
 Auto-reload value of STM 32 Nucleo MPU. More...
 
 deltatimenew
 Most recent instance of time of encoder.
 
 deltatime
 Difference in time readings of the encoder.
 

Detailed Description

Encoder Class.

Consists of methods and variables to calculate rotational position and delta (speed) of a rotating object. Combined with main.py, it outputs the position of the object from a selected zero point.

Constructor & Destructor Documentation

◆ __init__()

def encoder.Encoder.__init__ (   self,
  pin_one,
  pin_two,
  TimerNum 
)

Initializes object in Encoder class.

Takes input and creates an object with configured settings to appropriately interact with ESP32 and motor

Parameters
pin_one
pin_two
TimerNum
Returns
Encoder object with EncoderName, Text relaying an encoder has been created

Member Function Documentation

◆ get_delta()

def encoder.Encoder.get_delta (   self)

Returns delta.

Return current change in position from an encoder

Returns
delta

◆ get_deltatime()

def encoder.Encoder.get_deltatime (   self)

Returns delta time.

Returns delta time used to calculate velocity

Returns
deltatime

◆ get_position()

def encoder.Encoder.get_position (   self)

Returns position.

Returns current position from an encoder

Returns
position

◆ update()

def encoder.Encoder.update (   self)

Updates position.

Works with 2^16 timers, if first run, the first 'if' loop runs , initializing the run. At the end of the first run, the position value is stored as the 'past' encoder value, and the '-' in the 'A' list is replaced. The second run records the new count of the encoder but replaces index 1 of 'A'. The difference between these indeces is then calculated. Logic is implemented to account for overflow/underflow and the position is updated.

Returns
None

◆ zero()

def encoder.Encoder.zero (   self)

Sets the current position to zero.

Primes update() function by setting 'A' list index 0 to '-' and index 1 to zero. Resets encoder position reading to zero.

Returns
Text relaying that the current location is zero

Member Data Documentation

◆ ch1

encoder.Encoder.ch1

pyb.Timer channel 1 object created.

Configures channel to Encoder mode. The counter will now change when ch1 changes.

◆ ch2

encoder.Encoder.ch2

pyb.Timer channel 2 object created.

Configures channel to Encoder mode. The counter will now change when ch2 changes.

◆ delta

encoder.Encoder.delta

Auto-reload value of STM 32 Nucleo MPU.

Difference between encoder update() iterations

The difference between update iterations are what is added over time to compute position. Once an overflow/underflow condition is reached, the delta is corrected based on the auto reload value that the Nucleo would normally reset at.

◆ new

encoder.Encoder.new

The position after the time has ended.

Position that is used to calculate delta of the two positions. This holds the most recent tick reading of the Nucleo. Once position is calculated, self.old is assigned with self.new, allowing the Nucleo to continually update position with each iteration.

◆ old

encoder.Encoder.old

The position at the beginning of the iteration.

Position that is used to calculate delta of the two positions by storing a tick count from a previous update.

◆ position

encoder.Encoder.position

Position of the encoder.

Stores counter values.

Determined by adding each delta to it to output the overall distance the encoder has traveled in the time since the encoder was initialized

Initially defined with a string as the first element, the this list is used to store counter values each time the class is called. This list is updated with each call, where the difference of its 0th and 1st index is used for encoder postion calculations.

Position of encoder

◆ timer

encoder.Encoder.timer

pyb.Timer class setting prescaler to 0 and specifying the auto-reload value ot 65535 encoder ticks

This sets whatever timer number is selected to count every tick outputted from the encoder (prescale = 0) and the auto-reload value (period) to 65535. This value is inherent to the STM32 Nucleo used for this program


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