QPIDfirmware
v0.1
Object oriented firmware for autonomous motor drivers with encoder based PID controller and flexible interface
|
(derived from QPID_MotorDriver) Implement a QPID_MotorDriver for DC motors hooked up to Adafruit's MotorShield V2. Control of this shield is via I2C, so it might be less responsive than other motor drivers using direct pin control. More...
#include <QPID_MotorDriver_AdafruitMotorShieldV2.h>
Public Member Functions | |
void | setPower (int16_t pow) override |
Start motor with given power and direction. More... | |
void | coast (void) override |
Stop motor in fast decay mode by cutting power to it. More... | |
void | brake (void) override |
The AdafruitMotorShieldV2 provides no braking, so brake() and coast() are the same. More... | |
void | setDecay (decayModeType mode) override |
Does nothing. Not supported by AdafruitMotorShieldV2. | |
void | setFrequency (uint8_t onoff) override |
Does nothing. Though the AdafruitMotorShieldV2 library has a public function for setting PWM, the documentation says it's internal only. So you'll have to use init() to set the PWM frequency. | |
void | enable (void) override |
Does nothing. Not supported by AdafruitMotorShieldV2. | |
void | disable (void) override |
Does nothing. Not supported by AdafruitMotorShieldV2. | |
int8_t | hasFault () override |
Not supported by AdafruitMotorShieldV2. More... | |
void | init (uint8_t motorNum, uint16_t freq, int8_t i2cAddress, int8_t i2cBus, int8_t sda, int8_t scl) |
Get and initialize motor. As the shield is a I2C slave, devices with more than one hardware I2C bus (e.g. ESP32) can use a different bus to be able to act as I2C slave on the other bus. More... | |
Public Member Functions inherited from QPID_Object | |
virtual void | update () |
(abstract) Can be overridden by QPID subsystems which need to do their own polling. Will be called by QPID_Unit::update() for subsystems, and by firmware/client for QPID_Unit itself. | |
void | throwError (const char *invokedBy, const char *errorMessage) |
Writes error message and error invoking class to Serial. More... | |
void | log (const char *logEntry) |
Puts timestamped string into the system log (atm: writes it out to Serial). More... | |
Protected Member Functions | |
bool | processMessage (uint8_t *m) override |
(abstract) Interprets message handed down from QPID_Unit locally. Must be overridden in derived classes | |
Protected Member Functions inherited from QPID_Object | |
QPID_Object () | |
Constructor. Begins Serial with 115200 baud for logging and error reporting, if not done previously. | |
Additional Inherited Members | |
Public Types inherited from QPID_MotorDriver | |
enum | decayModeType : uint8_t { decayModeFast = 0, decayModeSlow = 1 } |
Symbolic names for decay modes that should be used during inactive part of PWM phase, if the driver supports that functionality. | |
Protected Attributes inherited from QPID_MotorDriver | |
decayModeType | decayMode = decayModeSlow |
int16_t | currentPWM = 0 |
int16_t | maxPower |
int16_t | alwaysOnPWM |
(derived from QPID_MotorDriver) Implement a QPID_MotorDriver for DC motors hooked up to Adafruit's MotorShield V2. Control of this shield is via I2C, so it might be less responsive than other motor drivers using direct pin control.
mostly untested yet.
Access to the master I2C bus should be regulated, in case other subsystems use I2C too (e.g. endstops on an I2C extender). So, for the moment, watch out for possible problems yourself.
(done?) Can only use the system's default I2C bus (Wire). The library supports providing your own Wire interfaces which would make it possible to use an alternate bus, e.g. if the default bis is used for slave access to the device.
|
overridevirtual |
Start motor with given power and direction.
pow | PWM value, sign indicates direction. |
Reimplemented from QPID_MotorDriver.
|
overridevirtual |
Stop motor in fast decay mode by cutting power to it.
Reimplemented from QPID_MotorDriver.
|
overridevirtual |
The AdafruitMotorShieldV2 provides no braking, so brake() and coast() are the same.
Reimplemented from QPID_MotorDriver.
|
overridevirtual |
Not supported by AdafruitMotorShieldV2.
Reimplemented from QPID_MotorDriver.
void QPID_MotorDriver_AdafruitMotorShieldV2::init | ( | uint8_t | motorNum, |
uint16_t | freq = -1 , |
||
int8_t | i2cAddress = -1 , |
||
int8_t | i2cBus = -1 , |
||
int8_t | sda = -1 , |
||
int8_t | scl = -1 |
||
) |
Get and initialize motor. As the shield is a I2C slave, devices with more than one hardware I2C bus (e.g. ESP32) can use a different bus to be able to act as I2C slave on the other bus.
motorNum | Number of motor shield's motor output (1 to 4) |
freq | PWM frequency. Use -1 for default (1600 Hz) |
i2cAddress | I2C slave address of shield. Use -1 for default (0x60) |
i2cBus | I2C Bus, for systems with more than one bus. Use -1 for default (wire library) |
sda,scl | SDA and SCL pins. Only specify if i2cBus is non default. Use -1 for default in both cases. |