Kyle Chuang | ME405 Mechatronics Portfolio
m_driver.MotorDriver Class Reference

This class implements a motor driver for the ME405 board. More...

Public Member Functions

def __init__ (self, motor, nSLEEP_pin, nFAULT_pin, IN1_pin, ch1, IN2_pin, ch2, timer)
 
def enable (self)
 Sets the nSLEEP pin to high which enables the motors.
 
def disable (self)
 Sets the nSLEEP pin to low which disables the motors.
 
def set_duty (self, duty)
 Sets the duty cycle of the motor. More...
 
def CheckFault (self)
 Checks pin PB2 to see if there is a fault present. More...
 
def myCallback (self, IQR_source)
 Callback function. More...
 

Public Attributes

 pinA15
 nSLEEP pin setup
 
 pin1
 Initialize timer and pins.
 
 pin2
 
 tim
 
 tchA
 
 tchB
 
 pinPB2
 nFAULT pin setup
 
 fault_state
 Initialize nFAULT pin self.fault_state = self.pinPB2.value()
 
 motor
 Initializes the motor object.
 
 extint
 Detects when the the nFAULT pin is set to LOW and the callback function is called.
 
 inpt
 

Detailed Description

This class implements a motor driver for the ME405 board.

Constructor & Destructor Documentation

◆ __init__()

def m_driver.MotorDriver.__init__ (   self,
  motor,
  nSLEEP_pin,
  nFAULT_pin,
  IN1_pin,
  ch1,
  IN2_pin,
  ch2,
  timer 
)

Creates a motor driver by initializing GP10 pins and turning the motor off for safety.

Parameters
motorA boolean object which represents whether the motor object being created is the primary motor.
nSLEEP_pinA pyb.Pin object to use as the enable pin.
nFAULT_pinA pyb.Pin object to use as the fault pin.
IN1_pinA pyb.Pin object to use as the input to half bridge 1.
ch1A pyb.Timer.Channel object that selects the first channel
IN2_pinA pyb.Pin object to use as the input to half bridge 2.
ch2A pyb.Timer.Channel object that tselects the second channel
timerA pyb.Timer object to use for PWM generation on IN1_pin and IN2_pin

Member Function Documentation

◆ CheckFault()

def m_driver.MotorDriver.CheckFault (   self)

Checks pin PB2 to see if there is a fault present.

This method checks the nFAULT pin for its value. If it is high, then it will enable the motors and resume operation. If it is low, then it will print an error message and continuously check the pin until it is set to high.

◆ myCallback()

def m_driver.MotorDriver.myCallback (   self,
  IQR_source 
)

Callback function.

This is the callback function that is used when the nFAULT pin is set to low. It checks the instance of the motor for the primary motor and will disable the motors accordingly.

◆ set_duty()

def m_driver.MotorDriver.set_duty (   self,
  duty 
)

Sets the duty cycle of the motor.

This method sets the duty cycle to be sent to the motor to the given motor to the given level. Positive values cause effort in one direction, negative values in the opposite direction.

Parameters
dutyA signed integer holding the duty cycle of the PWM signal sent to the motor.

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