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... | |
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.
| 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.
| nSLEEP_pin | A pyb.Pin object to use as the enable pin. |
| nfault_pin | A pyb.Pin object used to connect to the motor fault pin, must be configured as an input |
| IN1_pin | A pyb.Pin object to use as the input to half bridge 1. |
| IN1_ch | The timer channel number to be used for IN1_pin. |
| IN2_pin | A pyb.Pin object to use as the input to half bridge 2. |
| IN2_ch | The timer channel number to be used for IN2_pin. |
| timer | A pyb.Timer object to use for PWM generation on IN1_pin and IN2_pin. |
| dead_band | A tuple representing the motor's deadband, leave as (0,0) if no dead band compensation is desired |
| new_db | A number representing a new symetrical dead band around zero used to stabalize control signal |
| debug | A boolean used to enable debug messages |
| primary | A boolean used to set if an external interrupt should be created to listen for a fault. |
| def m_driver.MotorDriver.catch_fault | ( | self, | |
| ISR_SOURCE | |||
| ) |
A callback fuction that triggers on a motor fault condition.
| ISR_SOURCE | The line that triggered the ISR |
| 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.
| def m_driver.MotorDriver.disable | ( | self | ) |
disables the motors by setting the enable pin to low
| def m_driver.MotorDriver.enable | ( | self | ) |
enables the motors by setting the enable pin to high
| 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.
| duty | A signed integer holding the duty cycle of the PWM signal sent to the motor |
| 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
| m_driver.MotorDriver.debug |
A boolean used to enable debug messages.
| m_driver.MotorDriver.enable_pin |
The pin used to enable / disable the motor.
| m_driver.MotorDriver.fault_pin |
The pin used to detect a fault in motor operations.
| m_driver.MotorDriver.mot_fault |
A Boolean indicating if the motor driver chip is asserting a fault.
| m_driver.MotorDriver.MotFault |
Motor fault ISR object.
| m_driver.MotorDriver.new_db |
A value used to create an artificial deadband about zero.
| 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.
| 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.