ME 305 Group 6 Documentation
Public Member Functions | Public Attributes | List of all members
encoder_02.Encoder_02 Class Reference

Class to represent encoder object to handle encoder functions. More...

Public Member Functions

def __init__ (self, int channel, pyb.Pin pin1, pyb.Pin pin2, int period=65535, int prescaler=1)
 Creates encoder object. More...
 
def update (self)
 Saves encoder value. More...
 
def get_position (self)
 Returns position. More...
 
def zero (self, position=0)
 Zeros the encoder. More...
 
def get_delta (self)
 Returns the latest saved difference in position. More...
 

Public Attributes

 pin_1
 First encoder pin. More...
 
 pin_2
 Second encoder pin. More...
 
 encoder_timer
 Timer object. More...
 
 encoder_channel
 Channel object. More...
 
 delta_cutoff
 Cutoff for detecting rollover. More...
 
 period
 Encoder counter max. More...
 
 abs_position
 Encoder position. More...
 
 last_pos
 Last encoder position. More...
 
 prev_delta
 Change in position. More...
 

Detailed Description

Class to represent encoder object to handle encoder functions.

Class to represent an encoder connected to two pins on board. Pins and channels may be specified through init arguments, but the user must confirm that the desired Pin and channel combination are allowed by the hardware specifications.

At very high speeds, the counter may fill too much between updates for this driver to handle. The minimum update speed is given by

Equation minimum update frequency

where ω is the motor speed, CPR is the number of ticks per revolution, and Δ is the rollover cutoff, 1/2 the 'period' from the init method.

Constructor & Destructor Documentation

◆ __init__()

def encoder_02.Encoder_02.__init__ (   self,
int  channel,
pyb.Pin  pin1,
pyb.Pin  pin2,
int   period = 65535,
int   prescaler = 1 
)

Creates encoder object.

You must ensure you are using a valid combination of pins and timer, found in the STM32 documentation.

Parameters
channelWhich channel is used on the timer of choice. This is often simply 1.
pin1The first of the encoder's data pins.
pin2The second of the encoder's data pins.
periodThe maximum number of ticks before rollover. By default, this is set to the maximum 16-bit number.
prescalerHow many encoder ticks before the clock triggers. Increasing this can reduce rollover error at high speeds.

Member Function Documentation

◆ get_delta()

def encoder_02.Encoder_02.get_delta (   self)

Returns the latest saved difference in position.

Getting the delta can act as a velocity measurement when combined with the sample frequency.

◆ get_position()

def encoder_02.Encoder_02.get_position (   self)

Returns position.

Returns currently saved position of the encoder (in ticks) from self.abs_position.

◆ update()

def encoder_02.Encoder_02.update (   self)

Saves encoder value.

Saves the current position of the encoder (in ticks) to self.abs_position. Will handle rollover in direction unless the encoder is spinning too quickly (see class description for details)

◆ zero()

def encoder_02.Encoder_02.zero (   self,
  position = 0 
)

Zeros the encoder.

Set the current absolute position to the value passed in; zero by default.

Parameters
positionThe current absolute position is set to this value.

Member Data Documentation

◆ abs_position

encoder_02.Encoder_02.abs_position

Encoder position.

Stores the position of the encoder (in ticks)

◆ delta_cutoff

encoder_02.Encoder_02.delta_cutoff

Cutoff for detecting rollover.

Set to 1/2 the period.

◆ encoder_channel

encoder_02.Encoder_02.encoder_channel

Channel object.

Holds the channel setup for the timer used in the encoder.

◆ encoder_timer

encoder_02.Encoder_02.encoder_timer

Timer object.

Holds the timer setup for the timer used in the encoder

◆ last_pos

encoder_02.Encoder_02.last_pos

Last encoder position.

Position of the encoder (in ticks) from the last update

◆ period

encoder_02.Encoder_02.period

Encoder counter max.

The maximum number of ticks before rollover.

◆ pin_1

encoder_02.Encoder_02.pin_1

First encoder pin.

Signal pin from the first of the two sensors on the encoder.

◆ pin_2

encoder_02.Encoder_02.pin_2

Second encoder pin.

Signal pin from the second of the two sensors on the encoder.

◆ prev_delta

encoder_02.Encoder_02.prev_delta

Change in position.

Difference (in ticks) since the last update


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