ME 405: Mechatronics Portfolio
MotorDriver.MotorDriver Class Reference

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...
 

Detailed Description

Motor driver class

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
motorNumA number identifier for the motor object.
pinSleepA pyb.Pin object to use as the enable pin.
pinFaultA pyb.Pin object to use with an external interrupt to sense current overloads from the motor.
pinIN1A pyb.Pin object to use as the input to half bridge 1.
channel1A number identifier for the timer channel for pinIN1.
pinIN2A pyb.Pin object to use as the input to half bridge 2.
channel2A number identifier for the timer channel for pinIN2
timNumA number identifier for the timer used in PWM generation on pinIN1 and pinIN2.

Member Function Documentation

◆ brake()

def MotorDriver.MotorDriver.brake (   self)

Brake Motor

Sets duty cycles to both PWM channels low, causing the motor to brake rapidly

◆ disable()

def MotorDriver.MotorDriver.disable (   self)

Disable Motor

Turns the enable pin low, disabling motor movement

◆ enable()

def MotorDriver.MotorDriver.enable (   self)

Enable Motor

Turns the enable pin high, allowing the motor to move

◆ faultInterrupt()

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.

Parameters
faultPinThe pin on the hardware which is used to trigger the external interrupt method.

◆ setDuty()

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.

Parameters
dutyThe desired duty cycle, either positive for forward movement or negative for reverse movement

Member Data Documentation

◆ faultFlag

MotorDriver.MotorDriver.faultFlag

Flag used to signal if fault external interrupt has been triggered.

It is set to false upon initialization.


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