Matthew's Portfolio
motorDriver.motorDriver Class Reference

Public Member Functions

def __init__ (self, nSLEEP_pin, nFAULT_pin, mDriverFlag=True)
 Creates a motor driver by initializing GPIO pins. More...
 
def enable (self)
 Enable the motor to allow for PWM to actuate the motor. More...
 
def disable (self)
 Disable the motor to prevent the PWM to actuate the motor. More...
 
def faultCB (self, IRQ_src)
 Callback method for fault detection. More...
 
def clearFault (self, IRQ_src)
 Callback method for clearing a fault. More...
 
def channel (self, IN1_pin, IN2_pin, IN_timer, ch1, ch2, mChFlag=False)
 Method for generation of motor channel objects. More...
 

Public Attributes

 mDriverFlag
 Debugging flag for detailed analysis while running.
 
 nSLEEP_pin
 Used to enable or disable the motor.
 
 nFAULT_pin
 Interupt triggered by fault detection in the motor driver. More...
 
 ButtonInt
 Pin attribute for blue user button. More...
 
 motorList
 List containing copies of each motor channel instantiated. More...
 
 fault
 Boolean variable for fault detection. More...
 
 ignoreFault
 Boolean variable to ignore unwanted faults. More...
 

Constructor & Destructor Documentation

◆ __init__()

def motorDriver.motorDriver.__init__ (   self,
  nSLEEP_pin,
  nFAULT_pin,
  mDriverFlag = True 
)

Creates a motor driver by initializing GPIO pins.

The user will have to input the pins for the motor and the potential timers and channels as specified in the manufacturers specifications for the specific motor. Since both motors are connected to one motor driver, the motor driver serves as a parent to the two motors, containing any details common to both motors.
Example:
self.motorDriverObj = motorDriver(Pin.cpu.A15 , Pin.cpu.B2, driverFlag = True)

Parameters
nSLEEP_pinA pyb.Pin object to use as the enable/disable pin.
nFAULT_pinA pyb.Pin object used to detect faults such as high current, a stalled shaft, or any other unwanted condition.
mDriverFlagEnables or prevents certain print statements from appearing.

Member Function Documentation

◆ channel()

def motorDriver.motorDriver.channel (   self,
  IN1_pin,
  IN2_pin,
  IN_timer,
  ch1,
  ch2,
  mChFlag = False 
)

Method for generation of motor channel objects.

To allow for the motor driver parent to have access to methods of each individual channel, a method within the motor driver class is responsible for instantiating motor objects. Each object is then "copied" into a list within this class, such that it can be refrenced by other methods.
Example:
self.motX = self.motorDriver.channel( Pin.cpu.B0, Pin.cpu.B1, Timer(3, freq=20000), 3, 4, chFlag = True)

Parameters
IN1_pinFirst pin used for PWM
IN2_pinSecond pin used for PWM
IN_timerShared timer object for both PWM pins, containing timer number and frequency information
ch1First channel of timer
ch2Second channel of timer
mChFlagDebugging flag for motor channel print statements

◆ clearFault()

def motorDriver.motorDriver.clearFault (   self,
  IRQ_src 
)

Callback method for clearing a fault.

When this callback is triggered by a falling edge on PC13 (connected to the blue user button), two boolean variables are changed. First, self.fault is set back to False to allow program operation to continue. Secondly, self.ignoreFault is set to True in order to skip the next fault incorrectly detected by the nFAULT pin.

Parameters
IRQ_srcinterupt request

◆ disable()

def motorDriver.motorDriver.disable (   self)

Disable the motor to prevent the PWM to actuate the motor.

Sets the nSLEEP pin low, as well as setting each motor duty cycle to zero.

◆ enable()

def motorDriver.motorDriver.enable (   self)

Enable the motor to allow for PWM to actuate the motor.

Sets the nSLEEP pin high, allowing all other pins related to the motor to function

◆ faultCB()

def motorDriver.motorDriver.faultCB (   self,
  IRQ_src 
)

Callback method for fault detection.

When this callback is triggered by a falling edge on PB2 (connected to the nFAULT pin), self.fault is set to True (with the exception of the "false alarm" case discussed in documentation for self.ignoreFault.

Parameters
IRQ_srcinterupt request

Member Data Documentation

◆ ButtonInt

motorDriver.motorDriver.ButtonInt

Pin attribute for blue user button.

The blue button on the board has been used to clear faults caught by the nFAULT pin. Namely, the callback function clearFault() is called.

◆ fault

motorDriver.motorDriver.fault

Boolean variable for fault detection.

Initially set to False and set to True on a falling edge of the nFault pin

◆ ignoreFault

motorDriver.motorDriver.ignoreFault

Boolean variable to ignore unwanted faults.

For reasons not yet fully understood, when a fault is cleared, the enable action triggers a fault. However, this is a false alarm, so it is desired to use logic to skip this fault. Set to 'Trueonly whenclearFault()` is called, and set back to false upon the false fault callback.

◆ motorList

motorDriver.motorDriver.motorList

List containing copies of each motor channel instantiated.

In order to keep "copies" of each motor channel created, the function channel() appends to self.motorList the channel object being returned. With these copies, the more broad motor driver can still use the methods of each motor channel.

◆ nFAULT_pin

motorDriver.motorDriver.nFAULT_pin

Interupt triggered by fault detection in the motor driver.

Upon any fault in the combined motor driver (falling edge on PB2), a callback is triggered, and self.fault is set to True. This variable is a flag for program operation to halt, and can only start back up once the fault has been cleared.


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