ME 305 Group 6 Documentation
|
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 sample_freq, int period=65535, int prescaler=1, bool flipVelDirection=False) |
Creates encoder object. More... | |
def | update (self) |
Saves encoder value. More... | |
def | get_position (self) |
Returns position in radians. More... | |
def | get_velocity (self) |
Returns angular velocity. 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... | |
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
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.
def encoder_04.Encoder_04.__init__ | ( | self, | |
int | channel, | ||
pyb.Pin | pin1, | ||
pyb.Pin | pin2, | ||
int | sample_freq, | ||
int | period = 65535 , |
||
int | prescaler = 1 , |
||
bool | flipVelDirection = False |
||
) |
Creates encoder object.
You must ensure you are using a valid combination of pins and timer, found in the STM32 documentation.
channel | Which channel is used on the timer of choice. This is often simply 1. |
pin1 | The first of the encoder's data pins. |
pin2 | The second of the encoder's data pins. |
period | The maximum number of ticks before rollover. By default, this is set to the maximum 16-bit number. |
prescaler | How many encoder ticks before the clock triggers. Increasing this can reduce rollover error at high speeds. |
def encoder_04.Encoder_04.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.
def encoder_04.Encoder_04.get_position | ( | self | ) |
Returns position in radians.
Returns currently saved position of the encoder (in ticks) from self.abs_position.
def encoder_04.Encoder_04.get_velocity | ( | self | ) |
Returns angular velocity.
Returns current angular velocity from the saved delta.
def encoder_04.Encoder_04.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)
def encoder_04.Encoder_04.zero | ( | self, | |
position = 0 |
|||
) |
Zeros the encoder.
Set the current absolute position to the value passed in; zero by default.
position | The current absolute position is set to this value. |
encoder_04.Encoder_04.abs_position |
Encoder position.
Stores the position of the encoder (in ticks)
encoder_04.Encoder_04.delta_cutoff |
Cutoff for detecting rollover.
Set to 1/2 the period.
encoder_04.Encoder_04.encoder_channel |
Channel object.
Holds the channel setup for the timer used in the encoder.
encoder_04.Encoder_04.encoder_timer |
Timer object.
Holds the timer setup for the timer used in the encoder
encoder_04.Encoder_04.last_pos |
Last encoder position.
Position of the encoder (in ticks) from the last update
encoder_04.Encoder_04.period |
Encoder counter max.
The maximum number of ticks before rollover.
encoder_04.Encoder_04.pin_1 |
First encoder pin.
Signal pin from the first of the two sensors on the encoder.
encoder_04.Encoder_04.pin_2 |
Second encoder pin.
Signal pin from the second of the two sensors on the encoder.
encoder_04.Encoder_04.prev_delta |
Change in position.
Difference (in ticks) since the last update