Motor driver class More...
Public Member Functions | |
def | __init__ (self, motorNum, pinSleep, pinFault, pinIN1, channel1, pinIN2, channel2, timNum) |
Motor driver constructor More... | |
def | enable (self) |
Enable Motor More... | |
def | disable (self) |
Disable Motor More... | |
def | setDuty (self, duty) |
Set Motor Duty Cycle More... | |
def | brake (self) |
Brake Motor More... | |
def | faultInterrupt (self, faultPin) |
Fault Pin External Interrupt More... | |
Public Attributes | |
motorNum | |
Identifier for the motor object. | |
pinSleep | |
Defines local object for enable pin. | |
pinFault | |
Defines local fault pin object for fault pin. | |
extint | |
Create external interrupt object connected to fault pin. | |
pinIN1 | |
Defines local object for IN1 pin. | |
pinIN2 | |
Defines local object for IN2 pin. | |
timer | |
Defines local variable for the timer. | |
timch1 | |
Defines timer channel for pinIN1 PWM function. | |
timch2 | |
Defines the timer channel for pinIN2 PWM function. | |
faultFlag | |
Flag used to signal if fault external interrupt has been triggered. More... | |
Motor driver class
def MotorDriver.MotorDriver.__init__ | ( | self, | |
motorNum, | |||
pinSleep, | |||
pinFault, | |||
pinIN1, | |||
channel1, | |||
pinIN2, | |||
channel2, | |||
timNum | |||
) |
Motor driver constructor
This constructor creates a motor driver by initializing GPIO pins and turning the motor off for safety.
motorNum | A number identifier for the motor object. |
pinSleep | A pyb.Pin object to use as the enable pin. |
pinFault | A pyb.Pin object to use with an external interrupt to sense current overloads from the motor. |
pinIN1 | A pyb.Pin object to use as the input to half bridge 1. |
channel1 | A number identifier for the timer channel for pinIN1. |
pinIN2 | A pyb.Pin object to use as the input to half bridge 2. |
channel2 | A number identifier for the timer channel for pinIN2 |
timNum | A number identifier for the timer used in PWM generation on pinIN1 and pinIN2. |
def MotorDriver.MotorDriver.brake | ( | self | ) |
Brake Motor
Sets duty cycles to both PWM channels low, causing the motor to brake rapidly
def MotorDriver.MotorDriver.disable | ( | self | ) |
Disable Motor
Turns the enable pin low, disabling motor movement
def MotorDriver.MotorDriver.enable | ( | self | ) |
Enable Motor
Turns the enable pin high, allowing the motor to move
def MotorDriver.MotorDriver.faultInterrupt | ( | self, | |
faultPin | |||
) |
Fault Pin External Interrupt
External interrupt method which is triggered when the motor H-bridge fault pin goes low.
faultPin | The pin on the hardware which is used to trigger the external interrupt method. |
def MotorDriver.MotorDriver.setDuty | ( | self, | |
duty | |||
) |
Set Motor Duty Cycle
Sets the motor duty cycle according to user input. For forward (CCW) motion when the duty is positive, the duty is assigned to channel 1. For reverse (CW) motion when duty is negatvive, the duty is assigned to channel 2. Duty is clamped between 100 and -100 percent.
duty | The desired duty cycle, either positive for forward movement or negative for reverse movement |
MotorDriver.MotorDriver.faultFlag |
Flag used to signal if fault external interrupt has been triggered.
It is set to false upon initialization.