ME 405
m_driver.MotorDriver Class Reference

A motor driver designed to work with an H-bridge connected to a Nucleo L476RG running Micropython. More...

Public Member Functions

def __init__ (self, nSLEEP_pin, nfault_pin, IN1_pin, IN1_ch, IN2_pin, IN2_ch, timer, dead_band=(0, 0), new_db=0, debug=False, primary=False)
 Creates a motor driver by initializing GPIO pins and turning the motor off for safety. More...
 
def enable (self)
 enables the motors by setting the enable pin to high More...
 
def disable (self)
 disables the motors by setting the enable pin to low More...
 
def set_duty (self, duty)
 Sets the duty for the motor. More...
 
def check_fault (self)
 This tests a fault state in the driver. More...
 
def catch_fault (self, ISR_SOURCE)
 A callback fuction that triggers on a motor fault condition. More...
 

Public Attributes

 debug
 A boolean used to enable debug messages. More...
 
 enable_pin
 The pin used to enable / disable the motor. More...
 
 fault_pin
 The pin used to detect a fault in motor operations. More...
 
 mot_fault
 A Boolean indicating if the motor driver chip is asserting a fault. More...
 
 MotFault
 Motor fault ISR object. More...
 
 tch1
 A pyb.Timer.channel object configured to drive half bridge 1 with PWM using the given pyb.Timer, pyb.Pin, and channel number. More...
 
 tch2
 A pyb.Timer.channel object configured to drive half bridge 2 with PWM using the given pyb.Timer, pyb.Pin, and channel number. More...
 
 new_db
 A value used to create an artificial deadband about zero. More...
 
 db
 A tuple representing the deadband of the BDC motor being used. More...
 

Detailed Description

A motor driver designed to work with an H-bridge connected to a Nucleo L476RG running Micropython.

This motor driver takes four pyb.Pin objects, two timer channel variables, and a pyb.Timer object. It uses these to configure a sleep pin, a fault pin and two PWM signal generators. The H-Bridge motor driver is controlled using a Pulse 1 Side PWM scheme. The driver software uses logic to interporate the given duty command into the correct PWM percentage and direction. The init parameters dead_band and new_db are used to set up dead compensation. If used, this driver will scale any requested duty to avoid falling into the motor's natural friction dead_band. To avoid oscilations when using deadband compensation in closed loop control, the new_db parameter can be used to set up a new, smaller dead_band that allows the control system to settle out. The driver also has the ability to enable and disable motor motion.

Constructor & Destructor Documentation

◆ __init__()

def m_driver.MotorDriver.__init__ (   self,
  nSLEEP_pin,
  nfault_pin,
  IN1_pin,
  IN1_ch,
  IN2_pin,
  IN2_ch,
  timer,
  dead_band = (0,0),
  new_db = 0,
  debug = False,
  primary = False 
)

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

Parameters
nSLEEP_pinA pyb.Pin object to use as the enable pin.
nfault_pinA pyb.Pin object used to connect to the motor fault pin, must be configured as an input
IN1_pinA pyb.Pin object to use as the input to half bridge 1.
IN1_chThe timer channel number to be used for IN1_pin.
IN2_pinA pyb.Pin object to use as the input to half bridge 2.
IN2_chThe timer channel number to be used for IN2_pin.
timerA pyb.Timer object to use for PWM generation on IN1_pin and IN2_pin.
dead_bandA tuple representing the motor's deadband, leave as (0,0) if no dead band compensation is desired
new_dbA number representing a new symetrical dead band around zero used to stabalize control signal
debugA boolean used to enable debug messages
primaryA boolean used to set if an external interrupt should be created to listen for a fault.

Member Function Documentation

◆ catch_fault()

def m_driver.MotorDriver.catch_fault (   self,
  ISR_SOURCE 
)

A callback fuction that triggers on a motor fault condition.

Parameters
ISR_SOURCEThe line that triggered the ISR

◆ check_fault()

def m_driver.MotorDriver.check_fault (   self)

This tests a fault state in the driver.

When the driver fault attribute is set to True, trying to either enable the motor or set its duty will trigger a fault check. Here the value of the nfault pin is checked, if the fault has cleared, the driver is unlocked, if it has not, the user is prompted to act. To prevent the software latch from sticking, the fault ISR is disabled to allow the motor to power on without triggering another momentary fault.

◆ disable()

def m_driver.MotorDriver.disable (   self)

disables the motors by setting the enable pin to low

◆ enable()

def m_driver.MotorDriver.enable (   self)

enables the motors by setting the enable pin to high

◆ set_duty()

def m_driver.MotorDriver.set_duty (   self,
  duty 
)

Sets the duty for the motor.

This method sets the duty cycle to be sent to the 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

Member Data Documentation

◆ db

m_driver.MotorDriver.db

A tuple representing the deadband of the BDC motor being used.

This must be tested and set acordingly Leaving db as (0,0) turns off dead band compensation

◆ debug

m_driver.MotorDriver.debug

A boolean used to enable debug messages.

◆ enable_pin

m_driver.MotorDriver.enable_pin

The pin used to enable / disable the motor.

◆ fault_pin

m_driver.MotorDriver.fault_pin

The pin used to detect a fault in motor operations.

◆ mot_fault

m_driver.MotorDriver.mot_fault

A Boolean indicating if the motor driver chip is asserting a fault.

◆ MotFault

m_driver.MotorDriver.MotFault

Motor fault ISR object.

◆ new_db

m_driver.MotorDriver.new_db

A value used to create an artificial deadband about zero.

◆ tch1

m_driver.MotorDriver.tch1

A pyb.Timer.channel object configured to drive half bridge 1 with PWM using the given pyb.Timer, pyb.Pin, and channel number.

◆ tch2

m_driver.MotorDriver.tch2

A pyb.Timer.channel object configured to drive half bridge 2 with PWM using the given pyb.Timer, pyb.Pin, and channel number.


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