USB Sabertooth Packet Serial Library for Arduino
Control your USB-enabled Sabertooth with reliable Packet Serial.
Public Member Functions | List of all members
USBSabertooth Class Reference

Controls a USB Sabertooth motor driver running in Packet Serial mode. More...

Public Member Functions

 USBSabertooth (USBSabertoothSerial &serial, byte address)
 
byte address () const
 
void command (byte command, byte value)
 
void command (byte command, const byte *value, size_t bytes)
 
void motor (int value)
 
void motor (byte motorOutputNumber, int value)
 
void power (int value)
 
void power (byte powerOutputNumber, int value)
 
void drive (int value)
 
void turn (int value)
 
void freewheel (int value=2048)
 
void freewheel (byte motorOutputNumber, int value=2048)
 
void shutDown (byte type, byte number, boolean value=true)
 
void set (byte type, byte number, int value)
 
void setRamping (int value)
 
void setRamping (byte motorOutputNumber, int value)
 
void setTimeout (int milliseconds)
 
void keepAlive ()
 
int get (byte type, byte number)
 
int getBattery (byte motorOutputNumber, boolean unscaled=false)
 
int getCurrent (byte motorOutputNumber, boolean unscaled=false)
 
int getTemperature (byte motorOutputNumber, boolean unscaled=false)
 
int32_t getGetRetryInterval () const
 
void setGetRetryInterval (int32_t intervalMS)
 
int32_t getGetTimeout () const
 
void setGetTimeout (int32_t timeoutMS)
 
boolean usingCRC () const
 
void useChecksum ()
 
void useCRC ()
 

Detailed Description

Controls a USB Sabertooth motor driver running in Packet Serial mode.

Examples:
1.Basics/Freewheeling/Freewheeling.ino, 1.Basics/PowerOutputs/PowerOutputs.ino, 1.Basics/Simplest/Simplest.ino, 1.Basics/Sweep/Sweep.ino, 1.Basics/TankStyleSweep/TankStyleSweep.ino, 2.Settings/Ramping/Ramping.ino, 2.Settings/SerialTimeout/SerialTimeout.ino, 3.Advanced/Checksum/Checksum.ino, 3.Advanced/SharedLine/SharedLine.ino, and 3.Advanced/SoftwareSerial/SoftwareSerial.ino.

Constructor & Destructor Documentation

USBSabertooth::USBSabertooth ( USBSabertoothSerial serial,
byte  address 
)

Initializes a new instance of the USBSabertooth class. The driver address is set to the value given, and the specified serial port is used.

Parameters
serialThe USBSabertoothSerial whose serial port the motor driver is on.
addressThe driver address.

Member Function Documentation

byte USBSabertooth::address ( ) const
inline

Gets the driver address.

Returns
The driver address.
void USBSabertooth::command ( byte  command,
byte  value 
)

Sends a packet serial command to the motor driver.

Parameters
commandThe number of the command.
valueThe command's value.
void USBSabertooth::command ( byte  command,
const byte *  value,
size_t  bytes 
)

Sends a multibyte packet serial command to the motor driver.

Parameters
commandThe number of the command.
valueThe command's value.
bytesThe number of bytes in the value.
void USBSabertooth::drive ( int  value)

Controls the mixed-mode drive channel. In User Mode, this sets MD.

Parameters
valueThe value, between -2047 and 2047.
void USBSabertooth::freewheel ( int  value = 2048)

Causes motor output 1 to freewheel. In User Mode, this sets Q1.

Parameters
valuetrue or a positive value lets the motor outputs freewheel. false or a negative or zero value stops the freewheeling.
void USBSabertooth::freewheel ( byte  motorOutputNumber,
int  value = 2048 
)

Causes the specified motor output to freewheel. In User Mode, this sets Q1 or Q2.

Parameters
motorOutputNumberThe motor output number, 1 or 2. You can also use a character, such as '3', to select the motor output by its Plain Text Serial address.
valuetrue or a positive value lets the motor output freewheel. false or a negative or zero value stops the freewheeling.
int USBSabertooth::get ( byte  type,
byte  number 
)
inline

Gets a value from the motor driver.

Parameters
typeThe type of channel to get from. This can be 'S' (signal), 'A' (aux), 'M' (motor output), or 'P' (power output).
numberThe number of the channel, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
Returns
The value, or SABERTOOTH_GET_TIMED_OUT.
int USBSabertooth::getBattery ( byte  motorOutputNumber,
boolean  unscaled = false 
)
inline

Gets the battery voltage.

Parameters
motorOutputNumberThe number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
unscaledIf true, gets in unscaled units. If false, gets in scaled units.
Returns
The value, or SABERTOOTH_GET_TIMED_OUT.
int USBSabertooth::getCurrent ( byte  motorOutputNumber,
boolean  unscaled = false 
)
inline

Gets the motor output current.

Parameters
motorOutputNumberThe number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
unscaledIf true, gets in unscaled units. If false, gets in scaled units.
Returns
The value, or SABERTOOTH_GET_TIMED_OUT.
int32_t USBSabertooth::getGetRetryInterval ( ) const
inline

Gets the get retry interval.

Returns
The get retry interval, in milliseconds.
int32_t USBSabertooth::getGetTimeout ( ) const
inline

Gets the get timeout.

Returns
The get timeout, in milliseconds.
int USBSabertooth::getTemperature ( byte  motorOutputNumber,
boolean  unscaled = false 
)
inline

Gets the motor output temperature.

Parameters
motorOutputNumberThe number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
unscaledIf true, gets in unscaled units. If false, gets in scaled units.
Returns
The value, or SABERTOOTH_GET_TIMED_OUT.
void USBSabertooth::keepAlive ( )

Resets the serial timeout. This is done automatically any time a motor output is set. You can, however, call this if you don't want to set any motor outputs.

void USBSabertooth::motor ( int  value)

Controls motor output 1. In User Mode, this sets M1.

Parameters
valueThe value, between -2047 and 2047.
Examples:
3.Advanced/SharedLine/SharedLine.ino.
void USBSabertooth::motor ( byte  motorOutputNumber,
int  value 
)

Controls the specified motor output. In User Mode, this sets M1 or M2.

Parameters
motorOutputNumberThe motor output number, 1 or 2. You can also use a character, such as '3', to select the motor output by its Plain Text Serial address.
valueThe value, between -2047 and 2047.
void USBSabertooth::power ( int  value)

Controls power output 1, if power output 1 is configured as a controllable output. In User Mode, this sets P1.

Parameters
valueThe value, between -2047 and 2047.
void USBSabertooth::power ( byte  powerOutputNumber,
int  value 
)

Controls the specified power output, if the power output is configured as a controllable output. In User Mode, this sets P1 or P2.

Parameters
powerOutputNumberThe power output number, 1 or 2. You can also use a character, such as '3', to select the power output by its Plain Text Serial address.
valueThe value, between -2047 and 2047.
void USBSabertooth::set ( byte  type,
byte  number,
int  value 
)

Sets a value on the motor driver.

Parameters
typeThe type of channel to set. This can be 'M' (motor output), 'P' (power output), 'Q' (freewheel), or 'R' (ramping).
numberThe number of the channel, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
valueThe value, between -16383 and 16383 (though in many cases, only -2047 to 2047 are meaningful).
void USBSabertooth::setGetRetryInterval ( int32_t  intervalMS)
inline

Sets the get retry interval.

Parameters
intervalMSThe command retry interval, in milliseconds.
void USBSabertooth::setGetTimeout ( int32_t  timeoutMS)
inline

Sets the get timeout.

Parameters
timeoutMSThe get timeout, in milliseconds.
void USBSabertooth::setRamping ( int  value)

Sets the ramping for all motor outputs. In User Mode, this sets R1 and R2.

Parameters
valueThe ramping value, between -16383 (fast) and 2047 (slow).
void USBSabertooth::setRamping ( byte  motorOutputNumber,
int  value 
)

Sets the ramping for the specified motor output. In User Mode, this sets R1 or R2.

Parameters
motorOutputNumberThe motor output number, 1 or 2. You can also use a character, such as '3', to select the motor output by its Plain Text Serial address.
valueThe ramping value, between -16383 (fast) and 2047 (slow).
void USBSabertooth::setTimeout ( int  milliseconds)

Sets the serial timeout.

Parameters
millisecondsThe maximum time in milliseconds between packets. If this time is exceeded, the driver will stop the motor and power outputs. A value of zero uses the DEScribe setting. SABERTOOTH_INFINITE_TIMEOUT disables the timeout.
void USBSabertooth::shutDown ( byte  type,
byte  number,
boolean  value = true 
)

Shuts down an output.

Parameters
typeThe type of output to shut down. This can be 'M' (motor output) or 'P' (power output).
numberThe number of the output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address.
valuetrue sets the shutdown. false clears the shutdown.
void USBSabertooth::turn ( int  value)

Controls the mixed-mode turn channel. In User Mode, this sets MT.

Parameters
valueThe value, between -2047 and 2047.
void USBSabertooth::useChecksum ( )
inline

Causes future commands to be sent CRC-protected (larger packets, excellent error detection).

void USBSabertooth::useCRC ( )
inline

Causes future commands to be sent checksum-protected (smaller packets, reasonable error detection).

boolean USBSabertooth::usingCRC ( ) const
inline

Gets whether CRC-protected commands are used. They are, by default.

Returns
True if CRC-protected commands are used.