QPIDfirmware  v0.1
Object oriented firmware for autonomous motor drivers with encoder based PID controller and flexible interface
QPID_MotorDriver_AdafruitMotorShieldV2 Class Reference

(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>

Inheritance diagram for QPID_MotorDriver_AdafruitMotorShieldV2:

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
 

Detailed Description

(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.

Note
The shield does provide neither sleep/enable, decay mode, nor fault signaling, so none of them are implemented here.
Todo:

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.

Member Function Documentation

◆ setPower()

void QPID_MotorDriver_AdafruitMotorShieldV2::setPower ( int16_t  pow)
overridevirtual

Start motor with given power and direction.

Parameters
powPWM value, sign indicates direction.
Note
Preferably use brake() or coast() instead of setPower(0) to stop.

Reimplemented from QPID_MotorDriver.

◆ coast()

void QPID_MotorDriver_AdafruitMotorShieldV2::coast ( void  )
overridevirtual

Stop motor in fast decay mode by cutting power to it.

Note
AdafruitMotorShieldV2 only supports coasting, no breaking.

Reimplemented from QPID_MotorDriver.

◆ brake()

void QPID_MotorDriver_AdafruitMotorShieldV2::brake ( void  )
overridevirtual

The AdafruitMotorShieldV2 provides no braking, so brake() and coast() are the same.

See also
coast()

Reimplemented from QPID_MotorDriver.

◆ hasFault()

int8_t QPID_MotorDriver_AdafruitMotorShieldV2::hasFault ( )
overridevirtual

Not supported by AdafruitMotorShieldV2.

Returns
alway false (no fault)

Reimplemented from QPID_MotorDriver.

◆ init()

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.

Parameters
motorNumNumber of motor shield's motor output (1 to 4)
freqPWM frequency. Use -1 for default (1600 Hz)
i2cAddressI2C slave address of shield. Use -1 for default (0x60)
i2cBusI2C Bus, for systems with more than one bus. Use -1 for default (wire library)
sda,sclSDA and SCL pins. Only specify if i2cBus is non default. Use -1 for default in both cases.

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