Encoder Driver Class More...
Public Member Functions | |
def | __init__ (self, pinA, pinB, timer, PPC, CPR, gearRatio) |
Encoder class constructor More... | |
def | update (self) |
Update encoder position More... | |
def | getPosition (self) |
Return encoder position More... | |
def | getAngle (self) |
Return encoder angle More... | |
def | setPosition (self, newPosition) |
Set current relative encoder position More... | |
def | getDelta (self) |
Calculate delta between encoder updates More... | |
def | tick2rad (self, ticks) |
Convert encoder ticks to degrees More... | |
def | getSpeed (self, interval) |
Convert encoder delta to degrees per second More... | |
Public Attributes | |
pinA | |
Translates the encoder pin A input into Encoder object. | |
pinB | |
Translates the encoder pin B input into Encoder object. | |
tim | |
Defines the timer which applies to pins A and B. | |
curr_count | |
Constructs channel for pin A within timer. More... | |
prev_count | |
Creates a variable to hold the previous position count of the encoder. | |
position | |
Creates a local variable to hold the total position of the encoder. | |
delta | |
Creates a local variable to hold value representing difference between current and previous position. | |
PPC | |
Define the pulses per cycle for this encoder object via user input into constructor. | |
CPR | |
Define the cycles per revolution for this encoder object via user input into constructor. | |
gearRatio | |
Define the gear ratio (motor:encoder) reduced to an integer via user input into the constructor. | |
overflow | |
Defines total number of counter values before overflow. | |
Encoder Driver Class
def EncoderDriver.EncoderDriver.__init__ | ( | self, | |
pinA, | |||
pinB, | |||
timer, | |||
PPC, | |||
CPR, | |||
gearRatio | |||
) |
Encoder class constructor
This method constructs the Encoder object by assigning pin and timer input parameters and defining initial states of pins
pinA | The pin location for + encoder terminal. must be properly defined as a pin object before being input into an encoder class. Use pinA = pyb.Pin.cpu. [pin letter(s) and number] |
pinB | The pin location for GND encoder terminal. must follow same format for pinA |
timer | The timer number which applies to both pins, which can be found using Table 17 of the Nucleo datasheet |
PPC | The pulses per rotation of the encoder |
CPR | The cycles per rotation of the encoder |
gearRatio | The gear ratio between the motor and the output shaft on which the encoder is mounted |
def EncoderDriver.EncoderDriver.getAngle | ( | self | ) |
Return encoder angle
def EncoderDriver.EncoderDriver.getDelta | ( | self | ) |
Calculate delta between encoder updates
Calculates the difference between the current and previous position counts
def EncoderDriver.EncoderDriver.getPosition | ( | self | ) |
Return encoder position
def EncoderDriver.EncoderDriver.getSpeed | ( | self, | |
interval | |||
) |
Convert encoder delta to degrees per second
Determines the angular velocity of the motor according to the encoder PPC (pulses per cycle), CPR (cycles per revolution), and gear ratio which were input into the object constructor, as well as the time interval over which the encoder delta was calculated.
interval | The interval of time over which delta occurs, which must be in seconds |
def EncoderDriver.EncoderDriver.setPosition | ( | self, | |
newPosition | |||
) |
Set current relative encoder position
Sets the encoder position according to the desired user input parameter 'angle'
newPosition | The angle to which the encoder will be set. must be an integer |
def EncoderDriver.EncoderDriver.tick2rad | ( | self, | |
ticks | |||
) |
Convert encoder ticks to degrees
Converts the position of the encoder from ticks to degrees
ticks | The position or delta of the encoder in ticks. This is most easily obtained from the self.position attribute for position or self.getDelta() method for position delta |
def EncoderDriver.EncoderDriver.update | ( | self | ) |
Update encoder position
Updates the encoder position after a set time interval
EncoderDriver.EncoderDriver.curr_count |
Constructs channel for pin A within timer.
Constructs channel for pin B within timer
Creates a variable to hold the current position count of the encoder