ME 405 Documentation for Joshua Clemens, Cal Poly SLO 06/09/20
encoder.Encoder Class Reference

This class implements encoder functionality into the ME 405 board. More...

Public Member Functions

def __init__ (self, ENC_A, ENC_B, Timer_Num)
 Defines Encoder class. More...
 
def update (self)
 This method updates the encoder to its new position based on the amount of ticks.
 
def get_position (self)
 This method returns the most recently updated position. More...
 
def set_position (self, new_pos)
 This method sets the position to a specified value within the 16 bit range of valid values. More...
 
def get_delta (self)
 This method calculates the difference between the last recorded encoder reading and the current encoder reading. More...
 
def get_tot_pos (self)
 This method simply returns the net displacement value of the motor WRT the arbitrarily declared start position. More...
 

Public Attributes

 rec_position
 rec_position stores the recorded 16 bit unsigned number position of the motor as read by the encoder More...
 
 delta
 delta stores the change in position from the last stored encoder reading in rec_position More...
 
 tot_position
 tot_position stores the current position of the motor as referenced by some arbitrary datum More...
 

Detailed Description

This class implements encoder functionality into the ME 405 board.

This is important because it is going to be used to measure the position of the motor in a unit corresponding to fraction of a revolution. This can and will be used to implement position control in the motor, but first it is important that the encoder can read the motor position, store it in a boundless variable, and account for underflow and overflow error since the encoder timer has a range limited by a 16 bit unsigned number.

Constructor & Destructor Documentation

◆ __init__()

def encoder.Encoder.__init__ (   self,
  ENC_A,
  ENC_B,
  Timer_Num 
)

Defines Encoder class.

Creates encoder object by initializing PCB pinsets and enabling the proper timer in encoder counter mode.

Parameters
ENC_AThe pyb.pin object associated with encoder phase A
ENC_BThe pyb.pin object associated with encoder phase B
timerThe pyb.pin object associated with the timer channel

Member Function Documentation

◆ get_delta()

def encoder.Encoder.get_delta (   self)

This method calculates the difference between the last recorded encoder reading and the current encoder reading.

It returns this delta value as the difference and keeps a running total of net displacement

Returns
delta - Change in position of the motor from the last recorded position
tot_position - The current position of the model, calculated by totaling up all the delta values

◆ get_position()

def encoder.Encoder.get_position (   self)

This method returns the most recently updated position.

Note: This may not be the physical current position

◆ get_tot_pos()

def encoder.Encoder.get_tot_pos (   self)

This method simply returns the net displacement value of the motor WRT the arbitrarily declared start position.

This origin value is 0 be default, until manually changed by the use

◆ set_position()

def encoder.Encoder.set_position (   self,
  new_pos 
)

This method sets the position to a specified value within the 16 bit range of valid values.

Also clears total displacement (tot_position) and current displacement (delta), since a new arbitrary starting position has been declared. This method requires the user to input the desired position as an argument.

Parameters
new_posThe users desired position to set the motor to

Member Data Documentation

◆ delta

encoder.Encoder.delta

delta stores the change in position from the last stored encoder reading in rec_position

delta is meant to store the change in position from the encoder. This serves the dual purpose function of knowing which way the motor is turning, and adding up these changes to account for the motors current position at any instant

◆ rec_position

encoder.Encoder.rec_position

rec_position stores the recorded 16 bit unsigned number position of the motor as read by the encoder

rec_position is a 16 bit unsigned number because it ranges from 0-65535. This is the value used to actually calculate delta because it will account for underflow or overflow in the timer counter.

◆ tot_position

encoder.Encoder.tot_position

tot_position stores the current position of the motor as referenced by some arbitrary datum

tot_position gets its name from the fact that it is the result of totaling up all the delta values of time. In a way it measures the total change in position of the motor, but only if the reference datum is 0. Furthermore, it would only measure net change in position.


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