Controls a USB Sabertooth motor driver running in Packet Serial mode.
More...
|
| 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 () |
|
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
-
serial | The USBSabertoothSerial whose serial port the motor driver is on. |
address | The driver address. |
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
-
command | The number of the command. |
value | The 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
-
command | The number of the command. |
value | The command's value. |
bytes | The number of bytes in the value. |
void USBSabertooth::drive |
( |
int |
value | ) |
|
Controls the mixed-mode drive channel. In User Mode, this sets MD.
- Parameters
-
value | The value, between -2047 and 2047. |
void USBSabertooth::freewheel |
( |
int |
value = 2048 | ) |
|
Causes motor output 1 to freewheel. In User Mode, this sets Q1.
- Parameters
-
value | true 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
-
motorOutputNumber | The 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. |
value | true 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
-
type | The type of channel to get from. This can be 'S' (signal), 'A' (aux), 'M' (motor output), or 'P' (power output). |
number | The 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
-
motorOutputNumber | The number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address. |
unscaled | If 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
-
motorOutputNumber | The number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address. |
unscaled | If 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
-
motorOutputNumber | The number of the motor output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address. |
unscaled | If 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 | ) |
|
void USBSabertooth::motor |
( |
byte |
motorOutputNumber, |
|
|
int |
value |
|
) |
| |
Controls the specified motor output. In User Mode, this sets M1 or M2.
- Parameters
-
motorOutputNumber | The 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. |
value | The 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
-
value | The 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
-
powerOutputNumber | The 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. |
value | The value, between -2047 and 2047. |
void USBSabertooth::set |
( |
byte |
type, |
|
|
byte |
number, |
|
|
int |
value |
|
) |
| |
Sets a value on the motor driver.
- Parameters
-
type | The type of channel to set. This can be 'M' (motor output), 'P' (power output), 'Q' (freewheel), or 'R' (ramping). |
number | The number of the channel, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address. |
value | The 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
-
intervalMS | The command retry interval, in milliseconds. |
void USBSabertooth::setGetTimeout |
( |
int32_t |
timeoutMS | ) |
|
|
inline |
Sets the get timeout.
- Parameters
-
timeoutMS | The 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
-
value | The 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
-
motorOutputNumber | The 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. |
value | The ramping value, between -16383 (fast) and 2047 (slow). |
void USBSabertooth::setTimeout |
( |
int |
milliseconds | ) |
|
Sets the serial timeout.
- Parameters
-
milliseconds | The 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
-
type | The type of output to shut down. This can be 'M' (motor output) or 'P' (power output). |
number | The number of the output, 1 or 2. You can also use a character, such as '3', to select by Plain Text Serial address. |
value | true 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
-
value | The 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.