![]() |
Mechatronics Portfolio
Logan Williamson's Mechatronics Portfolio and Documentation Repository
|
Interface with quadrature encoders. More...
Public Member Functions | |
def | __init__ (self, chA_pin, chB_pin, timNum) |
Constructs an encoder object. More... | |
def | update (self) |
Updates encoder position and delta. More... | |
def | get_position (self) |
Returns encoder position. More... | |
def | zero (self) |
Resets the encoder position to zero. More... | |
def | get_delta (self) |
Returns encoder delta. More... | |
Public Attributes | |
tim | |
tim creates new timer object for storing the encoder position. More... | |
ch1 | |
creates channel 1 and channel 2 objects connected to the two pins input in the init function More... | |
ch2 | |
prevCount | |
Sets base object of prevCount (previous position) to 0. More... | |
position | |
position is the absolute position of the encoder. More... | |
count | |
delta | |
delta is the difference between the current and previous positions More... | |
Interface with quadrature encoders.
When called, this class generates an encoder object and assigns the desired timer and pins to it such that the position and change in position since the last update of the encoder position can be determined and returned as outputs.
def Lab0x02_encoder.Encoder.__init__ | ( | self, | |
chA_pin, | |||
chB_pin, | |||
timNum | |||
) |
Constructs an encoder object.
Upon calling the Encoder.py class, the init function will run automatically. To run properly, this requires three inputs to the Encoder.py class call. There are: one input for each of the desired pins you wish to associate with the two encoder sensor channels. Additionally, the timer number to be used for the encoder position count must be defined as the third input when calling this class. This function will then instanciate an encoder object with the above parameters.
chA_pin | creates empty object for an input of pin position. In this case we are using PB6 on the nucleo |
chB_pin | creates empty object for an input of pin position. In this case we are using PB7 on the nucleo |
timNum | creates an empty object for input timer. We will be using timer 4 |
def Lab0x02_encoder.Encoder.get_delta | ( | self | ) |
Returns encoder delta.
if user asks for delta to be returned, this function will return delta value calculated from update funciton
def Lab0x02_encoder.Encoder.get_position | ( | self | ) |
Returns encoder position.
If the user asks for the position, after position is calculated using update function, this function returns the calculated value
def Lab0x02_encoder.Encoder.update | ( | self | ) |
Updates encoder position and delta.
When called, this function will read and update the variable containing the encoder position, as well as the delta value of the encoder. This delta value will be analyzed for magnitude and direction to determine whether an overflow or underflow in the encoder position count has occurred since the last update. In the event that the encoder position count has overflowed or underflowed, this update function will add or subtract the appropriate value from the encoder position count to reflect the true position of the encoder relative to its home position.
self |
def Lab0x02_encoder.Encoder.zero | ( | self | ) |
Resets the encoder position to zero.
If user inputs the desire to reset the counter to zero, this function resets the encoder position to zero
Lab0x02_encoder.Encoder.ch1 |
creates channel 1 and channel 2 objects connected to the two pins input in the init function
ch1 and ch2 correspond to the inputs that will cause the encoder position to increment. This uses ENC_AB configuration which puts the timer in encoder mode: The counter changes when CH1 or CH2 changes. The order in which they change determines whether the encoder position increments or decrements.
Lab0x02_encoder.Encoder.delta |
delta is the difference between the current and previous positions
delta is used to test whether the counter has overflowed or not. It represents the change in count since the last time update() was called
Lab0x02_encoder.Encoder.position |
position is the absolute position of the encoder.
position is initially set to zero and will be updated when update() runs to reflect the absolute position of the encoder.
Lab0x02_encoder.Encoder.prevCount |
Sets base object of prevCount (previous position) to 0.
This will be used in further calculations of delta, change in encoder position since the last update() call.
Lab0x02_encoder.Encoder.tim |
tim creates new timer object for storing the encoder position.
Runs timer 4 on the nucleo with a period of 2^16-1 and a prescaler of 0