Motoron Motor Controller library for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MotoronBase Class Referenceabstract

#include <Motoron.h>

Inheritance diagram for MotoronBase:
MotoronI2C MotoronSerial

Public Member Functions

uint8_t getLastError ()
 
void getFirmwareVersion (uint16_t *productId, uint16_t *firmwareVersion)
 
void setProtocolOptions (uint8_t options)
 
void setProtocolOptionsLocally (uint8_t options)
 
uint8_t getProtocolOptionsLocally ()
 
void enableCrc ()
 
void disableCrc ()
 
void enableCrcForCommands ()
 
void disableCrcForCommands ()
 
void enableCrcForResponses ()
 
void disableCrcForResponses ()
 
void enableI2cGeneralCall ()
 
void disableI2cGeneralCall ()
 
void readEeprom (uint8_t offset, uint8_t length, uint8_t *buffer)
 
uint8_t readEepromDeviceNumber ()
 
void writeEeprom (uint8_t offset, uint8_t value)
 
void writeEeprom16 (uint8_t offset, uint16_t value)
 
void writeEepromDeviceNumber (uint16_t number)
 
void writeEepromAlternativeDeviceNumber (uint16_t number)
 
void writeEepromDisableAlternativeDeviceNumber ()
 
void writeEepromCommunicationOptions (uint8_t options)
 
void writeEepromBaudRate (uint32_t baud)
 
void writeEepromResponseDelay (uint8_t delay)
 
void reinitialize ()
 
void reset ()
 
void getVariables (uint8_t motor, uint8_t offset, uint8_t length, uint8_t *buffer)
 
uint8_t getVar8 (uint8_t motor, uint8_t offset)
 
uint16_t getVar16 (uint8_t motor, uint8_t offset)
 
uint16_t getStatusFlags ()
 
bool getProtocolErrorFlag ()
 
bool getCrcErrorFlag ()
 
bool getCommandTimeoutLatchedFlag ()
 
bool getMotorFaultLatchedFlag ()
 
bool getNoPowerLatchedFlag ()
 
bool getUARTErrorFlag ()
 
bool getResetFlag ()
 
bool getMotorFaultingFlag ()
 
bool getNoPowerFlag ()
 
bool getErrorActiveFlag ()
 
bool getMotorOutputEnabledFlag ()
 
bool getMotorDrivingFlag ()
 
uint8_t getUARTFaults ()
 
uint16_t getVinVoltage ()
 
uint32_t getVinVoltageMv (uint16_t referenceMv, MotoronVinSenseType type=MotoronVinSenseType::Motoron256)
 
uint16_t getCommandTimeoutMilliseconds ()
 
uint8_t getErrorResponse ()
 
uint16_t getErrorMask ()
 
uint8_t getJumperState ()
 
int16_t getTargetSpeed (uint8_t motor)
 
uint16_t getTargetBrakeAmount (uint8_t motor)
 
int16_t getCurrentSpeed (uint8_t motor)
 
int16_t getBufferedSpeed (uint8_t motor)
 
uint8_t getPwmMode (uint8_t motor)
 
uint16_t getMaxAccelerationForward (uint8_t motor)
 
uint16_t getMaxAccelerationReverse (uint8_t motor)
 
uint16_t getMaxDecelerationForward (uint8_t motor)
 
uint16_t getMaxDecelerationReverse (uint8_t motor)
 
uint16_t getStartingSpeedForward (uint8_t motor)
 
uint16_t getStartingSpeedReverse (uint8_t motor)
 
uint8_t getDirectionChangeDelayForward (uint8_t motor)
 
uint8_t getDirectionChangeDelayReverse (uint8_t motor)
 
uint16_t getCurrentLimit (uint8_t motor)
 
MotoronCurrentSenseReading getCurrentSenseReading (uint8_t motor)
 
MotoronCurrentSenseReading getCurrentSenseRawAndSpeed (uint8_t motor)
 
MotoronCurrentSenseReading getCurrentSenseProcessedAndSpeed (uint8_t motor)
 
uint16_t getCurrentSenseRaw (uint8_t motor)
 
uint16_t getCurrentSenseProcessed (uint8_t motor)
 
uint8_t getCurrentSenseOffset (uint8_t motor)
 
uint16_t getCurrentSenseMinimumDivisor (uint8_t motor)
 
void setVariable (uint8_t motor, uint8_t offset, uint16_t value)
 
void setCommandTimeoutMilliseconds (uint16_t ms)
 
void setErrorResponse (uint8_t response)
 
void setErrorMask (uint16_t mask)
 
void disableCommandTimeout ()
 
void clearUARTFaults (uint8_t flags)
 
void setPwmMode (uint8_t motor, uint8_t mode)
 
void setMaxAccelerationForward (uint8_t motor, uint16_t accel)
 
void setMaxAccelerationReverse (uint8_t motor, uint16_t accel)
 
void setMaxAcceleration (uint8_t motor, uint16_t accel)
 
void setMaxDecelerationForward (uint8_t motor, uint16_t decel)
 
void setMaxDecelerationReverse (uint8_t motor, uint16_t decel)
 
void setMaxDeceleration (uint8_t motor, uint16_t decel)
 
void setStartingSpeedForward (uint8_t motor, uint16_t speed)
 
void setStartingSpeedReverse (uint8_t motor, uint16_t speed)
 
void setStartingSpeed (uint8_t motor, uint16_t speed)
 
void setDirectionChangeDelayForward (uint8_t motor, uint8_t duration)
 
void setDirectionChangeDelayReverse (uint8_t motor, uint8_t duration)
 
void setDirectionChangeDelay (uint8_t motor, uint8_t duration)
 
void setCurrentLimit (uint8_t motor, uint16_t limit)
 
void setCurrentSenseOffset (uint8_t motor, uint8_t offset)
 
void setCurrentSenseMinimumDivisor (uint8_t motor, uint16_t speed)
 
void coastNow ()
 
void clearMotorFault (uint8_t flags=0)
 
void clearMotorFaultUnconditional ()
 
void clearLatchedStatusFlags (uint16_t flags)
 
void clearResetFlag ()
 
void setLatchedStatusFlags (uint16_t flags)
 
void setSpeed (uint8_t motor, int16_t speed)
 
void setSpeedNow (uint8_t motor, int16_t speed)
 
void setBufferedSpeed (uint8_t motor, int16_t speed)
 
void setAllSpeeds (int16_t speed1, int16_t speed2, int16_t speed3)
 
void setAllSpeeds (int16_t speed1, int16_t speed2)
 
void setAllSpeeds (int16_t speed1)
 
void setAllSpeedsNow (int16_t speed1, int16_t speed2, int16_t speed3)
 
void setAllSpeedsNow (int16_t speed1, int16_t speed2)
 
void setAllSpeedsNow (int16_t speed1)
 
void setAllBufferedSpeeds (int16_t speed1, int16_t speed2, int16_t speed3)
 
void setAllBufferedSpeeds (int16_t speed1, int16_t speed2)
 
void setAllBufferedSpeeds (int16_t speed1)
 
void setAllSpeedsUsingBuffers ()
 
void setAllSpeedsNowUsingBuffers ()
 
void setBraking (uint8_t motor, uint16_t amount)
 
void setBrakingNow (uint8_t motor, uint16_t amount)
 
void resetCommandTimeout ()
 

Static Public Member Functions

static uint8_t calculateCrc (uint8_t length, const uint8_t *buffer, uint8_t init=0)
 
static uint16_t calculateCurrentLimit (uint32_t milliamps, MotoronCurrentSenseType type, uint16_t referenceMv, uint16_t offset)
 
static constexpr uint16_t currentSenseUnitsMilliamps (MotoronCurrentSenseType type, uint16_t referenceMv)
 

Protected Member Functions

void sendCommand (uint8_t length, const uint8_t *cmd)
 
void sendCommandAndReadResponse (uint8_t cmdLength, const uint8_t *cmd, uint8_t responseLength, uint8_t *response)
 

Protected Attributes

uint8_t lastError
 
uint8_t protocolOptions
 

Detailed Description

This is a base class used to represent a connection to a Motoron. This class provides high-level functions for sending commands to the Motoron and reading data from it.

See also
MotoronSerial, MotoronI2C

Definition at line 60 of file Motoron.h.

Constructor & Destructor Documentation

◆ MotoronBase()

MotoronBase::MotoronBase ( )
inline

Definition at line 63 of file Motoron.h.

Member Function Documentation

◆ calculateCrc()

static uint8_t MotoronBase::calculateCrc ( uint8_t  length,
const uint8_t *  buffer,
uint8_t  init = 0 
)
inlinestatic

This static method calculates the 7-bit CRC needed for a Motoron command or response. Most users will not need to use this, since most methods in this library automatically append a CRC byte or check received CRC bytes when appropriate.

Definition at line 1781 of file Motoron.h.

◆ calculateCurrentLimit()

static uint16_t MotoronBase::calculateCurrentLimit ( uint32_t  milliamps,
MotoronCurrentSenseType  type,
uint16_t  referenceMv,
uint16_t  offset 
)
inlinestatic

Calculates a current limit value that can be passed to the Motoron using setCurrentLimit().

Parameters
milliampsThe desired current limit, in units of mA.
typeSpecifies what type of Motoron you are using.
referenceMvThe reference voltage (IOREF), in millivolts. For example, use 3300 for a 3.3 V system or 5000 for a 5 V system.
offsetThe offset of the raw current sense signal for the Motoron channel. This is the same measurement that you would put into the Motoron's "Current sense offset" variable using setCurrentSenseOffset(), so see the documentation of that function for more info. The offset is typically 10 for 5 V systems and 15 for 3.3 V systems, (50*1024/referenceMv) but it can vary widely.

Definition at line 1815 of file Motoron.h.

◆ clearLatchedStatusFlags()

void MotoronBase::clearLatchedStatusFlags ( uint16_t  flags)
inline

Clears the specified flags in getStatusFlags().

For each bit in the flags argument that is 1, this command clears the corresponding bit in the "Status flags" variable, setting it to 0.

For more information, see the "Clear latched status flags" command in the Motoron user's guide.

See also
getStatusFlags(), setLatchedStatusFlags()

Definition at line 1394 of file Motoron.h.

◆ clearMotorFault()

void MotoronBase::clearMotorFault ( uint8_t  flags = 0)
inline

Sends a "Clear motor fault" command to the Motoron.

If any of the Motoron's motors chips are currently experiencing a fault (error), or bit 0 of the flags argument is 1, this command makes the Motoron attempt to recover from the faults.

For more information, see the "Clear motor fault" command in the Motoron user's guide.

See also
clearMotorFaultUnconditional(), getMotorFaultingFlag()

Definition at line 1369 of file Motoron.h.

◆ clearMotorFaultUnconditional()

void MotoronBase::clearMotorFaultUnconditional ( )
inline

Sends a "Clear motor fault" command to the Motoron with the "unconditional" flag set, so the Motoron will attempt to recover from any motor faults even if no fault is currently occurring.

This is a more robust version of clearMotorFault().

Definition at line 1380 of file Motoron.h.

◆ clearResetFlag()

void MotoronBase::clearResetFlag ( )
inline

Clears the Motoron's reset flag.

The reset flag is a latched status flag in getStatusFlags() that is particularly important to clear: it gets set to 1 after the Motoron powers on or experiences a reset, and it is considered to be an error by default, so it prevents the motors from running. Therefore, it is necessary to call this function (or clearLatchedStatusFlags()) to clear the Reset flag before you can get the motors running. We recommend that immediately after you clear the reset flag. you should configure the Motoron's motor settings and error response settings. That way, if the Motoron experiences an unexpected reset while your system is running, it will stop running its motors and it will not start them again until all the important settings have been configured.

See also
clearLatchedStatusFlags()

Definition at line 1419 of file Motoron.h.

◆ clearUARTFaults()

void MotoronBase::clearUARTFaults ( uint8_t  flags)
inline

Sends a "Set variable" command that clears the specified flags in getUARTFaults().

For each bit in the flags argument that is 1, this command clears the corresponding bit in the "UART faults" variable, setting it to 0.

For more information, see the "UART faults" variable in the Motoron user's guide.

Definition at line 1120 of file Motoron.h.

◆ coastNow()

void MotoronBase::coastNow ( )
inline

Sends a "Coast now" command to the Motoron, causing all of the motors to immediately start coasting.

For more information, see the "Coast now" command in the Motoron user's guide.

Definition at line 1353 of file Motoron.h.

◆ currentSenseUnitsMilliamps()

static constexpr uint16_t MotoronBase::currentSenseUnitsMilliamps ( MotoronCurrentSenseType  type,
uint16_t  referenceMv 
)
inlinestaticconstexpr

Calculates the units for the Motoron's current sense reading returned by getCurrentSenseProcessed(), in milliamps.

To convert a reading from getCurrentSenseProcessed() to milliamps multiply it by the value returned from this function using 32-bit multiplication. For example:

uint32_t ma = (uint32_t)processed * units;
Parameters
typeSpecifies what type of Motoron you are using.
referenceMvThe reference voltage (IOREF), in millivolts. For example, use 3300 for a 3.3 V system or 5000 for a 5 V system.

Definition at line 1837 of file Motoron.h.

◆ disableCommandTimeout()

void MotoronBase::disableCommandTimeout ( )
inline

This disables the Motoron's command timeout feature by resetting the the "Error mask" variable to its default value but with the command timeout bit cleared.

By default, the Motoron's command timeout will occur if no valid commands are received in 1500 milliseconds, and the command timeout is treated as an error, so the motors will shut down. You can use this function if you want to disable that feature.

Note that this function overrides any previous values you set in the "Error mask" variable, so if you are using setErrorMask() in your program to configure which status flags are treated as errors, you do not need to use this function and you probably should not use this function.

See also
setCommandTimeoutMilliseconds(), setErrorMask()

Definition at line 1107 of file Motoron.h.

◆ disableCrc()

void MotoronBase::disableCrc ( )
inline

Disables CRC for commands and responses. See setProtocolOptions().

Definition at line 175 of file Motoron.h.

◆ disableCrcForCommands()

void MotoronBase::disableCrcForCommands ( )
inline

Disables CRC for commands. See setProtocolOptions().

Definition at line 190 of file Motoron.h.

◆ disableCrcForResponses()

void MotoronBase::disableCrcForResponses ( )
inline

Disables CRC for responses. See setProtocolOptions().

Definition at line 204 of file Motoron.h.

◆ disableI2cGeneralCall()

void MotoronBase::disableI2cGeneralCall ( )
inline

Disables the I2C general call address. See setProtocolOptions().

Definition at line 218 of file Motoron.h.

◆ enableCrc()

void MotoronBase::enableCrc ( )
inline

Enables CRC for commands and responses. See setProtocolOptions().

Definition at line 167 of file Motoron.h.

◆ enableCrcForCommands()

void MotoronBase::enableCrcForCommands ( )
inline

Enables CRC for commands. See setProtocolOptions().

Definition at line 183 of file Motoron.h.

◆ enableCrcForResponses()

void MotoronBase::enableCrcForResponses ( )
inline

Enables CRC for responses. See setProtocolOptions().

Definition at line 197 of file Motoron.h.

◆ enableI2cGeneralCall()

void MotoronBase::enableI2cGeneralCall ( )
inline

Enables the I2C general call address. See setProtocolOptions().

Definition at line 211 of file Motoron.h.

◆ getBufferedSpeed()

int16_t MotoronBase::getBufferedSpeed ( uint8_t  motor)
inline

Reads the buffered speed of the specified motor.

For more information, see the "Buffered speed" variable in the Motoron user's guide.

See also
setBufferedSpeed(), setAllBufferedSpeeds()

Definition at line 773 of file Motoron.h.

◆ getCommandTimeoutLatchedFlag()

bool MotoronBase::getCommandTimeoutLatchedFlag ( )
inline

Returns the "Command timeout latched" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 536 of file Motoron.h.

◆ getCommandTimeoutMilliseconds()

uint16_t MotoronBase::getCommandTimeoutMilliseconds ( )
inline

Reads the "Command timeout" variable and converts it to milliseconds.

For more information, see the "Command timeout" variable in the Motoron user's guide.

See also
setCommandTimeoutMilliseconds()

Definition at line 694 of file Motoron.h.

◆ getCrcErrorFlag()

bool MotoronBase::getCrcErrorFlag ( )
inline

Returns the "CRC error" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 527 of file Motoron.h.

◆ getCurrentLimit()

uint16_t MotoronBase::getCurrentLimit ( uint8_t  motor)
inline

Reads the current limit for the specified motor.

This only works for the high-power Motorons.

For more information, see the "Current limit" variable in the Motoron user's guide.

See also
setCurrentLimit()

Definition at line 901 of file Motoron.h.

◆ getCurrentSenseMinimumDivisor()

uint16_t MotoronBase::getCurrentSenseMinimumDivisor ( uint8_t  motor)
inline

Reads the current sense minimum divisor setting and returns it as a speed between 0 and 800.

This only works for the high-power Motorons.

For more information, see the "Current sense minimum divisor" variable in the Motoron user's guide.

See also
setCurrentSenseMinimumDivisor()

Definition at line 1017 of file Motoron.h.

◆ getCurrentSenseOffset()

uint8_t MotoronBase::getCurrentSenseOffset ( uint8_t  motor)
inline

Reads the current sense offset setting.

This only works for the high-power Motorons.

For more information, see the "Current sense offset" variable in the Motoron user's guide.

See also
setCurrentSenseOffset()

Definition at line 1003 of file Motoron.h.

◆ getCurrentSenseProcessed()

uint16_t MotoronBase::getCurrentSenseProcessed ( uint8_t  motor)
inline

Reads the processed current sense reading for the specified motor.

This only works for the high-power Motorons.

The units of this reading depend on the logic voltage of the Motoron and on the specific model of Motoron that you have, and you can use MotoronI2C::currentSenseUnitsMilliamps() to calculate the units.

The accuracy of this reading can be improved by measuring the current sense offset and setting it with setCurrentSenseOffset(). See the "Current sense processed" variable in the Motoron user's guide for or the CurrentSenseCalibrate example for more information.

Note that this reading will be 0xFFFF if an overflow happens during the calculation due to very high current.

See also
getCurrentSenseProcessedAndSpeed()

Definition at line 990 of file Motoron.h.

◆ getCurrentSenseProcessedAndSpeed()

MotoronCurrentSenseReading MotoronBase::getCurrentSenseProcessedAndSpeed ( uint8_t  motor)
inline

This is like getCurrentSenseReading() but it only reads the processed current sense measurement and the speed.

The 'raw' member of the returned structure will be 0.

This only works for the high-power Motorons.

Definition at line 950 of file Motoron.h.

◆ getCurrentSenseRaw()

uint16_t MotoronBase::getCurrentSenseRaw ( uint8_t  motor)
inline

Reads the raw current sense measurement for the specified motor.

This only works for the high-power Motorons.

For more information, see the "Current sense raw" variable in the Motoron user's guide.

See also
getCurrentSenseReading()

Definition at line 968 of file Motoron.h.

◆ getCurrentSenseRawAndSpeed()

MotoronCurrentSenseReading MotoronBase::getCurrentSenseRawAndSpeed ( uint8_t  motor)
inline

This is like getCurrentSenseReading() but it only reads the raw current sense measurement and the speed.

The 'processed' member of the returned structure will be 0.

This only works for the high-power Motorons.

Definition at line 934 of file Motoron.h.

◆ getCurrentSenseReading()

MotoronCurrentSenseReading MotoronBase::getCurrentSenseReading ( uint8_t  motor)
inline

Reads all the results from the last current sense measurement for the specified motor.

This function reads the "Current sense raw", "Current sense speed", and "Current sense processed" variables from the Motoron using a single command, so the values returned are all guaranteed to be part of the same measurement.

This only works for the high-power Motorons.

See also
getCurrentSenseRawAndSpeed(), getCurrentSenseProcessedAndSpeed()

Definition at line 917 of file Motoron.h.

◆ getCurrentSpeed()

int16_t MotoronBase::getCurrentSpeed ( uint8_t  motor)
inline

Reads the current speed of the specified motor, which is the speed that the Motoron is currently trying to apply to the motor.

For more information, see the "Target speed" variable in the Motoron user's guide.

See also
setSpeedNow(), setAllSpeedsNow(), setAllSpeedsNowUsingBuffers()

Definition at line 762 of file Motoron.h.

◆ getDirectionChangeDelayForward()

uint8_t MotoronBase::getDirectionChangeDelayForward ( uint8_t  motor)
inline

Reads the direction change delay for the specified motor in the forward direction.

For more information, see the "Direction change delay forward" variable in the Motoron user's guide.

See also
setDirectionChangeDelay(), setDirectionChangeDelayForward()

Definition at line 876 of file Motoron.h.

◆ getDirectionChangeDelayReverse()

uint8_t MotoronBase::getDirectionChangeDelayReverse ( uint8_t  motor)
inline

Reads the direction change delay for the specified motor in the reverse direction.

For more information, see the "Direction change delay reverse" variable in the Motoron user's guide.

See also
setDirectionChangeDelay(), setDirectionChangeDelayReverse()

Definition at line 888 of file Motoron.h.

◆ getErrorActiveFlag()

bool MotoronBase::getErrorActiveFlag ( )
inline

Returns the "Error active" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 612 of file Motoron.h.

◆ getErrorMask()

uint16_t MotoronBase::getErrorMask ( )
inline

Reads the "Error mask" variable, which defines which status flags are considered to be errors.

For more information, see the "Error mask" variable in the Motoron user's guide.

See also
setErrorMask()

Definition at line 718 of file Motoron.h.

◆ getErrorResponse()

uint8_t MotoronBase::getErrorResponse ( )
inline

Reads the "Error response" variable, which defines how the Motoron will stop its motors when an error is happening.

For more information, see the "Error response" variable in the Motoron user's guide.

See also
setErrorResponse()

Definition at line 706 of file Motoron.h.

◆ getFirmwareVersion()

void MotoronBase::getFirmwareVersion ( uint16_t *  productId,
uint16_t *  firmwareVersion 
)
inline

Sends the "Get firmware version" command to get the device's firmware product ID and firmware version numbers.

For more information, see the "Get firmware version" command in the Motoron user's guide.

Parameters
productIdAn optional pointer used to return the product ID. Can be NULL.
firmwareVersionAn optional pointer used to return the firmware version. Can be NULL.

Definition at line 86 of file Motoron.h.

◆ getJumperState()

uint8_t MotoronBase::getJumperState ( )
inline

Reads the "Jumper state" variable.

For more information, see the "Jumper state" variable in the Motoron user's guide.

Definition at line 727 of file Motoron.h.

◆ getLastError()

uint8_t MotoronBase::getLastError ( )
inline

Returns 0 if the last communication with the device was successful, or a non-zero error code if there was an error.

Definition at line 71 of file Motoron.h.

◆ getMaxAccelerationForward()

uint16_t MotoronBase::getMaxAccelerationForward ( uint8_t  motor)
inline

Reads the maximum acceleration of the specified motor for the forward direction.

For more information, see the "Max acceleration forward" variable in the Motoron user's guide.

See also
setMaxAcceleration(), setMaxAccelerationForward()

Definition at line 796 of file Motoron.h.

◆ getMaxAccelerationReverse()

uint16_t MotoronBase::getMaxAccelerationReverse ( uint8_t  motor)
inline

Reads the maximum acceleration of the specified motor for the reverse direction.

For more information, see the "Max acceleration reverse" variable in the Motoron user's guide.

See also
setMaxAcceleration(), setMaxAccelerationReverse()

Definition at line 808 of file Motoron.h.

◆ getMaxDecelerationForward()

uint16_t MotoronBase::getMaxDecelerationForward ( uint8_t  motor)
inline

Reads the maximum deceleration of the specified motor for the forward direction.

For more information, see the "Max deceleration forward" variable in the Motoron user's guide.

See also
setMaxDeceleration(), setMaxDecelerationForward()

Definition at line 820 of file Motoron.h.

◆ getMaxDecelerationReverse()

uint16_t MotoronBase::getMaxDecelerationReverse ( uint8_t  motor)
inline

Reads the maximum deceleration of the specified motor for the reverse direction.

For more information, see the "Max deceleration reverse" variable in the Motoron user's guide.

See also
setMaxDeceleration(), setMaxDecelerationReverse()

Definition at line 832 of file Motoron.h.

◆ getMotorDrivingFlag()

bool MotoronBase::getMotorDrivingFlag ( )
inline

Returns the "Motor driving" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 630 of file Motoron.h.

◆ getMotorFaultingFlag()

bool MotoronBase::getMotorFaultingFlag ( )
inline

Returns the "Motor faulting" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 594 of file Motoron.h.

◆ getMotorFaultLatchedFlag()

bool MotoronBase::getMotorFaultLatchedFlag ( )
inline

Returns the "Motor fault latched" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 545 of file Motoron.h.

◆ getMotorOutputEnabledFlag()

bool MotoronBase::getMotorOutputEnabledFlag ( )
inline

Returns the "Motor output enabled" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 621 of file Motoron.h.

◆ getNoPowerFlag()

bool MotoronBase::getNoPowerFlag ( )
inline

Returns the "No power" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 603 of file Motoron.h.

◆ getNoPowerLatchedFlag()

bool MotoronBase::getNoPowerLatchedFlag ( )
inline

Returns the "No power latched" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 554 of file Motoron.h.

◆ getProtocolErrorFlag()

bool MotoronBase::getProtocolErrorFlag ( )
inline

Returns the "Protocol error" bit from getStatusFlags().

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 518 of file Motoron.h.

◆ getProtocolOptionsLocally()

uint8_t MotoronBase::getProtocolOptionsLocally ( )
inline

Get the protocol options that this object is currently configured to use.

See also
setProtocolOptions()

Definition at line 161 of file Motoron.h.

◆ getPwmMode()

uint8_t MotoronBase::getPwmMode ( uint8_t  motor)
inline

Reads the PWM mode of the specified motor.

For more information, see the "PWM mode" variable in the Motoron user's guide.

See also
setPwmMode()

Definition at line 784 of file Motoron.h.

◆ getResetFlag()

bool MotoronBase::getResetFlag ( )
inline

Returns the "Reset" bit from getStatusFlags().

This bit is set to 1 when the Motoron powers on, its processor is reset (e.g. by reset()), or it receives a reinitialize() command. It can be cleared using clearResetFlag() or clearLatchedStatusFlags().

By default, the Motoron is configured to treat this bit as an error, so you will need to clear it before you can turn on the motors.

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 585 of file Motoron.h.

◆ getStartingSpeedForward()

uint16_t MotoronBase::getStartingSpeedForward ( uint8_t  motor)
inline

Reads the starting speed for the specified motor in the forward direction.

For more information, see the "Starting speed forward" variable in the Motoron user's guide.

See also
setStartingSpeed(), setStartingSpeedForward()

Definition at line 853 of file Motoron.h.

◆ getStartingSpeedReverse()

uint16_t MotoronBase::getStartingSpeedReverse ( uint8_t  motor)
inline

Reads the starting speed for the specified motor in the reverse direction.

For more information, see the "Starting speed reverse" variable in the Motoron user's guide.

See also
setStartingSpeed(), setStartingSpeedReverse()

Definition at line 864 of file Motoron.h.

◆ getStatusFlags()

uint16_t MotoronBase::getStatusFlags ( )
inline

Reads the "Status flags" variable from the Motoron.

The bits in this variable are defined by the MOTORON_STATUS_FLAG_* macros:

  • MOTORON_STATUS_FLAG_PROTOCOL_ERROR
  • MOTORON_STATUS_FLAG_CRC_ERROR
  • MOTORON_STATUS_FLAG_COMMAND_TIMEOUT_LATCHED
  • MOTORON_STATUS_FLAG_MOTOR_FAULT_LATCHED
  • MOTORON_STATUS_FLAG_NO_POWER_LATCHED
  • MOTORON_STATUS_FLAG_RESET
  • MOTORON_STATUS_FLAG_COMMAND_TIMEOUT
  • MOTORON_STATUS_FLAG_MOTOR_FAULTING
  • MOTORON_STATUS_FLAG_NO_POWER
  • MOTORON_STATUS_FLAG_ERROR_ACTIVE
  • MOTORON_STATUS_FLAG_MOTOR_OUTPUT_ENABLED
  • MOTORON_STATUS_FLAG_MOTOR_DRIVING

Here is some example code that uses C++ bitwise operators to check whether there is currently a motor fault or a lack of power:

uint16_t mask = (1 << MOTORON_STATUS_FLAG_NO_POWER) |
(1 << MOTORON_STATUS_FLAG_MOTOR_FAULTING);
if (getStatusFlags() & mask) { /* do something *&zwj;/ }
uint16_t getStatusFlags()
Definition: Motoron.h:509

This library has helper methods that make it easier if you just want to read a single bit:

The clearLatchedStatusFlags() method sets the specified set of latched status flags to 0. The reinitialize() and reset() commands reset the latched status flags to their default values.

For more information, see the "Status flags" variable in the Motoron user's guide.

Definition at line 509 of file Motoron.h.

◆ getTargetBrakeAmount()

uint16_t MotoronBase::getTargetBrakeAmount ( uint8_t  motor)
inline

Reads the target brake amount for the specified motor.

For more information, see the "Target speed" variable in the Motoron user's guide.

See also
setTargetBrakeAmount()

Definition at line 750 of file Motoron.h.

◆ getTargetSpeed()

int16_t MotoronBase::getTargetSpeed ( uint8_t  motor)
inline

Reads the target speed of the specified motor, which is the speed at which the motor has been commanded to move.

For more information, see the "Target speed" variable in the Motoron user's guide.

See also
setSpeed(), setAllSpeeds(), setAllSpeedsUsingBuffers()

Definition at line 739 of file Motoron.h.

◆ getUARTErrorFlag()

bool MotoronBase::getUARTErrorFlag ( )
inline

Returns the "UART error" bit from getStatusFlags().

This bit is only relevant for the Motoron controllers with a UART serial interface.

For more information, see the "Status flags" variable in the Motoron user's guide.

If this flag is set, you might consider calling getUARTFaults() to get details about what error happened.

Definition at line 569 of file Motoron.h.

◆ getUARTFaults()

uint8_t MotoronBase::getUARTFaults ( )
inline

Returns the "UART faults" variable.

Every time the Motoron sets the "UART error" bit in the status flags register (see getUARTErrorFlag()) it also sets one of the bits in this variable to indicate the cause of the error.

The bits in this variable are defined by the MOTORON_UART_FAULT_* macros:

  • MOTORON_UART_FAULT_FRAMING
  • MOTORON_UART_FAULT_NOISE
  • MOTORON_UART_FAULT_HARDWARE_OVERRUN
  • MOTORON_UART_FAULT_SOFTWARE_OVERRUN

This function is only useful for Motorons with a UART serial interface.

For more information, see the "UART faults" variable in the Motoron user's guide.

See also
clearUARTFaults())

Definition at line 655 of file Motoron.h.

◆ getVar16()

uint16_t MotoronBase::getVar16 ( uint8_t  motor,
uint8_t  offset 
)
inline

Reads two bytes from the Motoron using a "Get variables" command.

Parameters
motor0 to read general variables, or a motor number to read motor-specific variables.
offsetThe location of the first byte to read.

Definition at line 454 of file Motoron.h.

◆ getVar8()

uint8_t MotoronBase::getVar8 ( uint8_t  motor,
uint8_t  offset 
)
inline

Reads one byte from the Motoron using a "Get variables" command.

Parameters
motor0 to read a general variable, or a motor number to read a motor-specific variable.
offsetThe location of the byte to read.

Definition at line 442 of file Motoron.h.

◆ getVariables()

void MotoronBase::getVariables ( uint8_t  motor,
uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
)
inline

Reads information from the Motoron using a "Get variables" command.

This library has helper methods to read every variable, but this method is useful if you want to get the raw bytes, or if you want to read multiple consecutive variables at the same time for efficiency.

Parameters
motor0 to read general variables, or a motor number to read motor-specific variables.
offsetThe location of the first byte to read.
lengthHow many bytes to read.
bufferA pointer to an array to store the bytes read from the controller.

Definition at line 426 of file Motoron.h.

◆ getVinVoltage()

uint16_t MotoronBase::getVinVoltage ( )
inline

Reads voltage on the Motoron's VIN pin, in raw device units.

For more information, see the "VIN voltage" variable in the Motoron user's guide.

See also
getVinVoltageMv()

Definition at line 666 of file Motoron.h.

◆ getVinVoltageMv()

uint32_t MotoronBase::getVinVoltageMv ( uint16_t  referenceMv,
MotoronVinSenseType  type = MotoronVinSenseType::Motoron256 
)
inline

Reads the voltage on the Motoron's VIN pin and converts it to millivolts.

For more information, see the "VIN voltage" variable in the Motoron user's guide.

Parameters
referenceMvThe reference voltage (IOREF), in millivolts. For example, use 3300 for a 3.3 V system or 5000 for a 5 V system.
typeSpecifies what type of Motoron you are using.
See also
getVinVoltage()

Definition at line 681 of file Motoron.h.

◆ readEeprom()

void MotoronBase::readEeprom ( uint8_t  offset,
uint8_t  length,
uint8_t *  buffer 
)
inline

Reads the specified bytes from the Motoron's EEPROM memory.

For more information, see the "Read EEPROM" command in the Motoron user's guide.

Definition at line 228 of file Motoron.h.

◆ readEepromDeviceNumber()

uint8_t MotoronBase::readEepromDeviceNumber ( )
inline

Reads the EEPROM device number from the device. This is the I2C address that the device uses if it detects that JMP1 is shorted to GND when it starts up. It is stored in non-volatile EEPROM memory.

Definition at line 242 of file Motoron.h.

◆ reinitialize()

void MotoronBase::reinitialize ( )
inline

Sends a "Reinitialize" command to the Motoron, which resets most of the Motoron's variables to their default state.

For more information, see the "Reinitialize" command in the Motoron user's guide.

See also
reset()

Definition at line 388 of file Motoron.h.

◆ reset()

void MotoronBase::reset ( )
inline

Sends a "Reset" command to the Motoron, which does a full hardware reset.

This command is equivalent to briefly driving the Motoron's RST pin low. The Motoron's RST is briefly driven low by the Motoron itself as a result of this command.

After running this command, we recommend waiting for at least 5 milliseconds before you try to communicate with the Motoron.

See also
reinitialize()

Definition at line 406 of file Motoron.h.

◆ resetCommandTimeout()

void MotoronBase::resetCommandTimeout ( )
inline

Resets the command timeout.

This prevents the command timeout status flags from getting set for some time. (The command timeout is also reset by every other Motoron command, as long as its parameters are valid.)

For more information, see the "Reset command timeout" command in the Motoron user's guide.

See also
disableCommandTimeout(), setCommandTimeoutMilliseconds()

Definition at line 1771 of file Motoron.h.

◆ sendCommand()

void MotoronBase::sendCommand ( uint8_t  length,
const uint8_t *  cmd 
)
inlineprotected

This function is usable by subclasses but is not part of the public API and could be changed in future versions.

Definition at line 1853 of file Motoron.h.

◆ sendCommandAndReadResponse()

void MotoronBase::sendCommandAndReadResponse ( uint8_t  cmdLength,
const uint8_t *  cmd,
uint8_t  responseLength,
uint8_t *  response 
)
inlineprotected

This function is usable by subclasses but is not part of the public API and could be changed in future versions.

Definition at line 1861 of file Motoron.h.

◆ setAllBufferedSpeeds() [1/3]

void MotoronBase::setAllBufferedSpeeds ( int16_t  speed1)
inline

An overload of setAllBufferedSpeeds() for 1-channel Motorons.

Definition at line 1667 of file Motoron.h.

◆ setAllBufferedSpeeds() [2/3]

void MotoronBase::setAllBufferedSpeeds ( int16_t  speed1,
int16_t  speed2 
)
inline

An overload of setAllBufferedSpeeds() for 2-channel Motorons.

Definition at line 1654 of file Motoron.h.

◆ setAllBufferedSpeeds() [3/3]

void MotoronBase::setAllBufferedSpeeds ( int16_t  speed1,
int16_t  speed2,
int16_t  speed3 
)
inline

Sets the buffered speeds of all the motors.

The number of speed arguments you provide to this function must be equal to the number of motor channels your Motoron has, or else this command might not work.

This command does not immediately cause any change to the motors: it stores speed for each motor in the Motoron so they can be used by later commands.

This is equivalent to calling setBufferedSpeed() once for each motor, but it is more efficient because all of the speeds are sent in the same command.

For more information, see the "Set all speeds" command in the Motoron user's guide.

See also
setSpeed(), setBufferedSpeed(), setAllSpeeds(), setAllSpeedsUsingBuffers(), setAllSpeedsNowUsingBuffers()

Definition at line 1639 of file Motoron.h.

◆ setAllSpeeds() [1/3]

void MotoronBase::setAllSpeeds ( int16_t  speed1)
inline

An overload of setAllSpeeds() for single-channel Motorons.

Definition at line 1559 of file Motoron.h.

◆ setAllSpeeds() [2/3]

void MotoronBase::setAllSpeeds ( int16_t  speed1,
int16_t  speed2 
)
inline

An overload of setAllSpeeds() for 2-channel Motorons.

Definition at line 1546 of file Motoron.h.

◆ setAllSpeeds() [3/3]

void MotoronBase::setAllSpeeds ( int16_t  speed1,
int16_t  speed2,
int16_t  speed3 
)
inline

Sets the target speeds of all the motors at the same time.

The number of speed arguments you provide to this function must be equal to the number of motor channels your Motoron has, or else this command might not work.

This is equivalent to calling setSpeed() once for each motor, but it is more efficient because all of the speeds are sent in the same command.

For more information, see the "Set all speeds" command in the Motoron user's guide.

See also
setSpeed(), setAllSpeedsNow(), setAllBufferedSpeeds()

Definition at line 1531 of file Motoron.h.

◆ setAllSpeedsNow() [1/3]

void MotoronBase::setAllSpeedsNow ( int16_t  speed1)
inline

An overload of setAllSpeedsNow() for single-channel Motorons.

Definition at line 1610 of file Motoron.h.

◆ setAllSpeedsNow() [2/3]

void MotoronBase::setAllSpeedsNow ( int16_t  speed1,
int16_t  speed2 
)
inline

An overload of setAllSpeedsNow() for 2-channel Motorons.

Definition at line 1597 of file Motoron.h.

◆ setAllSpeedsNow() [3/3]

void MotoronBase::setAllSpeedsNow ( int16_t  speed1,
int16_t  speed2,
int16_t  speed3 
)
inline

Sets the target and current speeds of all the motors at the same time.

The number of speed arguments you provide to this function must be equal to the number of motor channels your Motoron has, or else this command might not work.

This is equivalent to calling setSpeedNow() once for each motor, but it is more efficient because all of the speeds are sent in the same command.

For more information, see the "Set all speeds" command in the Motoron user's guide.

See also
setSpeed(), setSpeedNow(), setAllSpeeds()

Definition at line 1582 of file Motoron.h.

◆ setAllSpeedsNowUsingBuffers()

void MotoronBase::setAllSpeedsNowUsingBuffers ( )
inline

Sets each motor's target speed and current speed equal to the buffered speed.

This command is the same as setAllSpeedsNow() except that the speeds are provided ahead of time using setBufferedSpeed() or setAllBufferedSpeeds().

See also
setAllSpeedsUsingBuffers(), setBufferedSpeed(), setAllBufferedSpeeds()

Definition at line 1698 of file Motoron.h.

◆ setAllSpeedsUsingBuffers()

void MotoronBase::setAllSpeedsUsingBuffers ( )
inline

Sets each motor's target speed equal to the buffered speed.

This command is the same as setAllSpeeds() except that the speeds are provided ahead of time using setBufferedSpeed() or setAllBufferedSpeeds().

See also
setAllSpeedsNowUsingBuffers(), setBufferedSpeed(), setAllBufferedSpeeds()

Definition at line 1684 of file Motoron.h.

◆ setBraking()

void MotoronBase::setBraking ( uint8_t  motor,
uint16_t  amount 
)
inline

Commands the motor to brake, coast, or something in between.

Sending this command causes the motor to decelerate to speed 0 obeying any relevant deceleration limits. Once the current speed reaches 0, the motor will attempt to brake or coast as specified by this command, but due to hardware limitations it might not be able to.

The motor number parameter should be between 1 and the number of motors supported by the Motoron.

The amount parameter gets stored in the "Target brake amount" variable for the motor and should be between 0 (coasting) and 800 (braking). Values above 800 will be clipped to 800 by the Motoron firmware.

See the "Set braking" command in the Motoron user's guide for more information.

See also
setBrakingNow(), getTargetBrakeAmount()

Definition at line 1722 of file Motoron.h.

◆ setBrakingNow()

void MotoronBase::setBrakingNow ( uint8_t  motor,
uint16_t  amount 
)
inline

Commands the motor to brake, coast, or something in between.

Sending this command causes the motor's current speed to change to 0. The motor will attempt to brake or coast as specified by this command, but due to hardware limitations it might not be able to.

The motor number parameter should be between 1 and the number of motors supported by the Motoron.

The amount parameter gets stored in the "Target brake amount" variable for the motor and should be between 0 (coasting) and 800 (braking). Values above 800 will be clipped to 800 by the Motoron firmware.

See the "Set braking" command in the Motoron user's guide for more information.

See also
setBraking(), getTargetBrakeAmount()

Definition at line 1750 of file Motoron.h.

◆ setBufferedSpeed()

void MotoronBase::setBufferedSpeed ( uint8_t  motor,
int16_t  speed 
)
inline

Sets the buffered speed of the specified motor.

This command does not immediately cause any change to the motor: it stores a speed for the specified motor in the Motoron so it can be used by later commands.

For single-channel Motorons, it is better to use setAllBufferedSpeeds() instead of this, since it sends one fewer byte.

For more information, see the "Set speed" command in the Motoron user's guide.

See also
setSpeed(), setAllBufferedSpeeds(), setAllSpeedsUsingBuffers(), setAllSpeedsNowUsingBuffers()

Definition at line 1506 of file Motoron.h.

◆ setCommandTimeoutMilliseconds()

void MotoronBase::setCommandTimeoutMilliseconds ( uint16_t  ms)
inline

Sets the command timeout period, in milliseconds.

For more information, see the "Command timeout" variable in the Motoron user's guide.

See also
disableCommandTimeout(), getCommandTimeoutMilliseconds()

Definition at line 1053 of file Motoron.h.

◆ setCurrentLimit()

void MotoronBase::setCurrentLimit ( uint8_t  motor,
uint16_t  limit 
)
inline

Sets the current limit for the specified motor.

This only works for the high-power Motorons.

The units of the current limit depend on the type of Motoron you have and the logic voltage of your system. See the "Current limit" variable in the Motoron user's guide for more information, or see MotoronI2C::calculateCurrentLimit().

See also
getCurrentLimit()

Definition at line 1299 of file Motoron.h.

◆ setCurrentSenseMinimumDivisor()

void MotoronBase::setCurrentSenseMinimumDivisor ( uint8_t  motor,
uint16_t  speed 
)
inline

Sets the current sense minimum divisor setting for the specified motor, given a speed between 0 and 800.

This is one of the settings that determines how current sense readings are processed.

If you do not care about measuring motor current, you do not need to set this variable.

For more information, see the "Current sense minimum divisor" variable in the Motoron user's guide.

This only works for the high-power Motorons.

See also
getCurrentSenseMinimumDivisor()

Definition at line 1343 of file Motoron.h.

◆ setCurrentSenseOffset()

void MotoronBase::setCurrentSenseOffset ( uint8_t  motor,
uint8_t  offset 
)
inline

Sets the current sense offset setting for the specified motor.

This is one of the settings that determines how current sense readings are processed. It is supposed to be the value returned by getCurrentSenseRaw() when Motor power is supplied to the Motoron and it is driving its motor outputs at speed 0.

The CurrentSenseCalibrate example shows how to measure the current sense offsets and load them onto the Motoron using this function.

If you do not care about measuring motor current, you do not need to set this variable.

For more information, see the "Current sense offset" variable in the Motoron user's guide.

This only works for the high-power Motorons.

See also
getCurrentSenseOffset()

Definition at line 1323 of file Motoron.h.

◆ setDirectionChangeDelay()

void MotoronBase::setDirectionChangeDelay ( uint8_t  motor,
uint8_t  duration 
)
inline

Sets the direction change delay of the specified motor (both directions), in units of 10 ms.

If this function succeeds, it is equivalent to calling setDirectionChangeDelayForward() and setDirectionChangeDelayReverse().

Definition at line 1282 of file Motoron.h.

◆ setDirectionChangeDelayForward()

void MotoronBase::setDirectionChangeDelayForward ( uint8_t  motor,
uint8_t  duration 
)
inline

Sets the direction change delay of the specified motor for the forward direction, in units of 10 ms.

For more information, see the "Direction change delay forward" variable in the Motoron user's guide.

See also
setDirectionChangeDelay(), getDirectionChangeDelayForward()

Definition at line 1260 of file Motoron.h.

◆ setDirectionChangeDelayReverse()

void MotoronBase::setDirectionChangeDelayReverse ( uint8_t  motor,
uint8_t  duration 
)
inline

Sets the direction change delay of the specified motor for the reverse direction, in units of 10 ms.

For more information, see the "Direction change delay reverse" variable in the Motoron user's guide.

See also
setDirectionChangeDelay(), getDirectionChangeDelayReverse()

Definition at line 1272 of file Motoron.h.

◆ setErrorMask()

void MotoronBase::setErrorMask ( uint16_t  mask)
inline

Sets the "Error mask" variable, which defines which status flags are considered to be errors.

For more information, see the "Error mask" variable in the Motoron user's guide.

See also
getErrorMask(), getStatusFlags()

Definition at line 1087 of file Motoron.h.

◆ setErrorResponse()

void MotoronBase::setErrorResponse ( uint8_t  response)
inline

Sets the error response, which defines how the Motoron will stop its motors when an error is happening.

The response parameter should be one of:

  • MOTORON_ERROR_RESPONSE_COAST
  • MOTORON_ERROR_RESPONSE_BRAKE
  • MOTORON_ERROR_RESPONSE_COAST_NOW
  • MOTORON_ERROR_RESPONSE_BRAKE_NOW

For more information, see the "Error response" variable in the Motoron user's guide.

See also
getErrorResponse()

Definition at line 1075 of file Motoron.h.

◆ setLatchedStatusFlags()

void MotoronBase::setLatchedStatusFlags ( uint16_t  flags)
inline

Sets the specified flags in getStatusFlags().

For each bit in the flags argument that is 1, this command sets the corresponding bit in the "Status flags" variable to 1.

For more information, see the "Set latched status flags" command in the Motoron user's guide.

See also
getStatusFlags(), setLatchedStatusFlags()

Definition at line 1433 of file Motoron.h.

◆ setMaxAcceleration()

void MotoronBase::setMaxAcceleration ( uint8_t  motor,
uint16_t  accel 
)
inline

Sets the maximum acceleration of the specified motor (both directions).

If this function succeeds, it is equivalent to calling setMaxAccelerationForward() and setMaxAccelerationReverse().

Definition at line 1176 of file Motoron.h.

◆ setMaxAccelerationForward()

void MotoronBase::setMaxAccelerationForward ( uint8_t  motor,
uint16_t  accel 
)
inline

Sets the maximum acceleration of the specified motor for the forward direction.

For more information, see the "Max acceleration forward" variable in the Motoron user's guide.

See also
setMaxAcceleration(), getMaxAccelerationForward()

Definition at line 1155 of file Motoron.h.

◆ setMaxAccelerationReverse()

void MotoronBase::setMaxAccelerationReverse ( uint8_t  motor,
uint16_t  accel 
)
inline

Sets the maximum acceleration of the specified motor for the reverse direction.

For more information, see the "Max acceleration reverse" variable in the Motoron user's guide.

See also
setMaxAcceleration(), getMaxAccelerationReverse()

Definition at line 1167 of file Motoron.h.

◆ setMaxDeceleration()

void MotoronBase::setMaxDeceleration ( uint8_t  motor,
uint16_t  decel 
)
inline

Sets the maximum deceleration of the specified motor (both directions).

If this function succeeds, it is equivalent to calling setMaxDecelerationForward() and setMaxDecelerationReverse().

Definition at line 1211 of file Motoron.h.

◆ setMaxDecelerationForward()

void MotoronBase::setMaxDecelerationForward ( uint8_t  motor,
uint16_t  decel 
)
inline

Sets the maximum deceleration of the specified motor for the forward direction.

For more information, see the "Max deceleration forward" variable in the Motoron user's guide.

See also
setMaxDeceleration(), getMaxDecelerationForward()

Definition at line 1190 of file Motoron.h.

◆ setMaxDecelerationReverse()

void MotoronBase::setMaxDecelerationReverse ( uint8_t  motor,
uint16_t  decel 
)
inline

Sets the maximum deceleration of the specified motor for the reverse direction.

For more information, see the "Max deceleration reverse" variable in the Motoron user's guide.

See also
setMaxDeceleration(), getMaxDecelerationReverse()

Definition at line 1202 of file Motoron.h.

◆ setProtocolOptions()

void MotoronBase::setProtocolOptions ( uint8_t  options)
inline

Sends the "Set protocol options" command to the device to specify options related to how the device processes commands and sends responses. The options are also saved in this object and are used later when sending other commands or reading responses.

When CRC for commands is enabled, this library generates the CRC byte and appends it to the end of each command it sends. The Motoron checks it to help ensure the command was received correctly.

When CRC for responses is enabled, this library reads the CRC byte sent by the Motoron in its repsonses and makes sure it is correct. If the response CRC byte is incorrect, getLastError() will return a non-zero error code after the command has been run.

When the I2C general call address is enabled, the Motoron receives commands sent to address 0 in addition to its usual I2C address. The general call address is write-only; reading bytes from it is not supported.

By default (in this libary and the Motoron itself), CRC for commands and responses is enabled, and the I2C general call address is enabled.

This method always sends its command with a CRC byte, so it will work even if CRC was previously disabled but has been re-enabled on the device (e.g. due to a reset).

The options argument should be 0 or a combination of the following expressions made using the bitwise or operator (|):

  • (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_COMMANDS)
  • (1 << MOTORON_PROTOCOL_OPTION_CRC_FOR_RESPONSES)
  • (1 << MOTORON_PROTOCOL_OPTION_I2C_GENERAL_CALL)

For more information, see the "Set protocol optons" command in the Motoron user's guide.

See also
enableCrc(), disableCrc(), enableCrcForCommands(), disableCrcForCommands(), enableCrcForResponses(), disableCrcForResponses(), enableI2cGeneralCall(), disableI2cGeneralCall()

Definition at line 134 of file Motoron.h.

◆ setProtocolOptionsLocally()

void MotoronBase::setProtocolOptionsLocally ( uint8_t  options)
inline

Sets the protocol options for this object, without sending a command to the Motoron.

If the options you specify here do not match the actual configuration of the Motoron, future communication could fail.

Most users should use setProtocolOptions() instead of this.

Definition at line 153 of file Motoron.h.

◆ setPwmMode()

void MotoronBase::setPwmMode ( uint8_t  motor,
uint8_t  mode 
)
inline

Sets the PWM mode for the specified motor.

The mode parameter should be one of the following:

  • MOTORON_PWM_MODE_DEFAULT (20 kHz)
  • MOTORON_PWM_MODE_1_KHZ 1
  • MOTORON_PWM_MODE_2_KHZ 2
  • MOTORON_PWM_MODE_4_KHZ 3
  • MOTORON_PWM_MODE_5_KHZ 4
  • MOTORON_PWM_MODE_10_KHZ 5
  • MOTORON_PWM_MODE_20_KHZ 6
  • MOTORON_PWM_MODE_40_KHZ 7
  • MOTORON_PWM_MODE_80_KHZ 8

For more information, see the "PWM mode" variable in the Motoron user's guide.

See also
getPwmMode()

Definition at line 1143 of file Motoron.h.

◆ setSpeed()

void MotoronBase::setSpeed ( uint8_t  motor,
int16_t  speed 
)
inline

Sets the target speed of the specified motor.

The current speed will start moving to the specified target speed, obeying any acceleration and deceleration limits.

The motor number should be between 1 and the number of motors supported by the Motoron.

The speed should be between -800 and 800. Values outside that range will be clipped to -800 or 800 by the Motoron firmware.

For single-channel Motorons, it is better to use setAllSpeeds() instead of this, since it sends one fewer byte.

For more information, see the "Set speed" command in the Motoron user's guide.

See also
setSpeedNow(), setAllSpeeds()

Definition at line 1460 of file Motoron.h.

◆ setSpeedNow()

void MotoronBase::setSpeedNow ( uint8_t  motor,
int16_t  speed 
)
inline

Sets the target and current speed of the specified motor, ignoring any acceleration and deceleration limits.

For single-channel Motorons, it is better to use setAllSpeedsNow() instead of this, since it sends one fewer byte.

For more information, see the "Set speed" command in the Motoron user's guide.

See also
setSpeed(), setAllSpeedsNow()

Definition at line 1481 of file Motoron.h.

◆ setStartingSpeed()

void MotoronBase::setStartingSpeed ( uint8_t  motor,
uint16_t  speed 
)
inline

Sets the starting speed of the specified motor (both directions).

If this function succeeds, it is equivalent to calling setStartingSpeedForward() and setStartingSpeedReverse().

Definition at line 1246 of file Motoron.h.

◆ setStartingSpeedForward()

void MotoronBase::setStartingSpeedForward ( uint8_t  motor,
uint16_t  speed 
)
inline

Sets the starting speed of the specified motor for the forward direction.

For more information, see the "Starting speed forward" variable in the Motoron user's guide.

See also
setStartingSpeed(), getStartingSpeedForward()

Definition at line 1225 of file Motoron.h.

◆ setStartingSpeedReverse()

void MotoronBase::setStartingSpeedReverse ( uint8_t  motor,
uint16_t  speed 
)
inline

Sets the starting speed of the specified motor for the reverse direction.

For more information, see the "Starting speed reverse" variable in the Motoron user's guide.

See also
setStartingSpeed(), getStartingSpeedReverse()

Definition at line 1237 of file Motoron.h.

◆ setVariable()

void MotoronBase::setVariable ( uint8_t  motor,
uint8_t  offset,
uint16_t  value 
)
inline

Configures the Motoron using a "Set variable" command.

This library has helper methods to set every variable, so you should not need to call this function directly.

Parameters
motor0 to set a general variable, or a motor number to set motor-specific variables.
offsetThe address of the variable to set (only certain offsets are allowed).
valueThe value to set the variable to.
See also
getVariables()

Definition at line 1034 of file Motoron.h.

◆ writeEeprom()

void MotoronBase::writeEeprom ( uint8_t  offset,
uint8_t  value 
)
inline

Writes a value to one byte in the Motoron's EEPROM memory.

This command only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

For more information, see the "Write EEPROM" command in the Motoron user's guide.

Definition at line 259 of file Motoron.h.

◆ writeEeprom16()

void MotoronBase::writeEeprom16 ( uint8_t  offset,
uint16_t  value 
)
inline

Writes a 2-byte value in the Motoron's EEPROM memory.

This command only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

Definition at line 281 of file Motoron.h.

◆ writeEepromAlternativeDeviceNumber()

void MotoronBase::writeEepromAlternativeDeviceNumber ( uint16_t  number)
inline

Writes to the alternative device number stored in EEPROM, changing it to the specified value.

This function is only useful for Motorons with a UART serial interface, and only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

See also
writeEepromDisableAlternativeDeviceNumber()

Definition at line 312 of file Motoron.h.

◆ writeEepromBaudRate()

void MotoronBase::writeEepromBaudRate ( uint32_t  baud)
inline

Writes to the baud rate stored in EEPROM, changing it to the specified value.

This function is only useful for Motorons with a UART serial interface, and only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

Definition at line 360 of file Motoron.h.

◆ writeEepromCommunicationOptions()

void MotoronBase::writeEepromCommunicationOptions ( uint8_t  options)
inline

Writes to the communication options byte stored in EEPROM, changing it to the specified value.

The bits in this byte are defined by the MOTORON_COMMUNICATION_OPTION_* macros.

This function is only useful for Motorons with a UART serial interface, and only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

Definition at line 346 of file Motoron.h.

◆ writeEepromDeviceNumber()

void MotoronBase::writeEepromDeviceNumber ( uint16_t  number)
inline

Writes to the device number stored in EEPROM, changing it to the specified value.

This command only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

Definition at line 295 of file Motoron.h.

◆ writeEepromDisableAlternativeDeviceNumber()

void MotoronBase::writeEepromDisableAlternativeDeviceNumber ( )
inline

Writes to EEPROM to disable the alternative device number.

This function is only useful for Motorons with a UART serial interface, and only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

See also
writeEepromAlternativeDeviceNumber()

Definition at line 328 of file Motoron.h.

◆ writeEepromResponseDelay()

void MotoronBase::writeEepromResponseDelay ( uint8_t  delay)
inline

Writes to the response delay setting stored in EEPROM, changing it to the specified value, in units of microseconds.

This function is only useful for Motorons with a UART serial interface, and only has an effect if JMP1 is shorted to GND.

Warning: Be careful not to write to the EEPROM in a fast loop. The EEPROM memory of the Motoron's microcontroller is only rated for 100,000 erase/write cycles.

Definition at line 376 of file Motoron.h.

Member Data Documentation

◆ lastError

uint8_t MotoronBase::lastError
protected

Zero if the last communication with the device was successful, non-zero otherwise.

Definition at line 1846 of file Motoron.h.

◆ protocolOptions

uint8_t MotoronBase::protocolOptions
protected

See setProtocolOptions.

Definition at line 1849 of file Motoron.h.


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