Add sabertooth lib, start enabling all motor drive
This commit is contained in:
34
lib/Sabertooth/examples/2.Settings/MinVoltage/MinVoltage.ino
Normal file
34
lib/Sabertooth/examples/2.Settings/MinVoltage/MinVoltage.ino
Normal file
@ -0,0 +1,34 @@
|
||||
// Set Minimum Voltage Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
// The values in this sample are specifically for the Sabertooth 2x25, and may
|
||||
// not have the same effect on other models.
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.autobaud();
|
||||
|
||||
// This setting does not persist between power cycles.
|
||||
// See the Packet Serial section of the documentation for what values to use
|
||||
// for the minimum voltage command. It may vary between Sabertooth models
|
||||
// (2x25, 2x60, etc.).
|
||||
//
|
||||
// On a Sabertooth 2x25, the value is (Desired Volts - 6) X 5.
|
||||
// So, in this sample, we'll make the low battery cutoff 12V: (12 - 6) X 5 = 30.
|
||||
ST.setMinVoltage(30);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ST.motor(1, 50);
|
||||
delay(5000);
|
||||
|
||||
ST.motor(1, -50);
|
||||
delay(5000);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
// Set Baud Rate Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
// WARNING: This sample makes changes that will persist between restarts.
|
||||
// NOTE: The setBaudRate function will only have an effect on V2 controllers (2x12, 2x25 V2, 2x60, SyRen 50).
|
||||
// Earlier controllers automatically detect the baud rate you choose in Serial.begin
|
||||
// when you call the autobaud function. Autobaud was replaced in V2 controllers for reliability
|
||||
// in the event that the Sabertooth lost power.
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// This sample will tell the Sabertooth *at 9600 baud* to *switch to 2400 baud*.
|
||||
// Keep in mind you must send the command to change the baud rate *at the baud rate
|
||||
// the Sabertooth is listening at* (factory default is 9600). After that, if it works,
|
||||
// you will be able to communicate using the new baud rate.
|
||||
//
|
||||
// Options are:
|
||||
// 2400
|
||||
// 9600
|
||||
// 19200
|
||||
// 38400
|
||||
// 115200 (only supported by some devices such as 2X60 -- check the device's datasheet)
|
||||
//
|
||||
// WARNING: The Sabertooth remembers this command between restarts.
|
||||
// To change your Sabertooth back to its default, you must *be at the baud rate you've
|
||||
// set the Sabertooth to*, and then call ST.setBaudRate(9600)
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.setBaudRate(2400);
|
||||
SabertoothTXPinSerial.end();
|
||||
|
||||
// OK, we're at 2400. Let's talk to the Sabertooth at that speed.
|
||||
SabertoothTXPinSerial.begin(2400);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ST.drive(0);
|
||||
ST.turn(20);
|
||||
delay(2000);
|
||||
|
||||
ST.turn(-20);
|
||||
delay(2000);
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
// Set Deadband Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
// WARNING: This sample makes changes that will persist between restarts AND in all modes.
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.autobaud();
|
||||
|
||||
// This makes the deadband from -20 to 20 (of 127).
|
||||
// If your commands for a motor stay entirely within the deadband for more than
|
||||
// a second, the motor driver will stop the motor.
|
||||
// WARNING: The Sabertooth remembers this command between restarts AND in all modes.
|
||||
// To change your Sabertooth back to its default, call ST.setDeadband(0)
|
||||
ST.setDeadband(20);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// 50 is greater than 20, so the motor moves.
|
||||
ST.motor(1, 50);
|
||||
delay(5000);
|
||||
|
||||
// 10 is NOT, so the motor does not move.
|
||||
ST.motor(1, 10);
|
||||
delay(5000);
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
// Set Maximum Voltage Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
// WARNING: This sample makes changes that will persist between restarts AND in all modes.
|
||||
// The values in this sample are specifically for the Sabertooth 2x25, and may
|
||||
// not have the same effect on other models.
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.autobaud();
|
||||
|
||||
// See the Packet Serial section of the documentation for what values to use
|
||||
// for the maximum voltage command. It may vary between Sabertooth models
|
||||
// (2x25, 2x60, etc.).
|
||||
//
|
||||
// On a Sabertooth 2x25, the value is (Desired Volts) X 5.12.
|
||||
// In this sample, we'll cap the max voltage before the motor driver does
|
||||
// a hard brake at 14V. For a 12V ATX power supply this might be reasonable --
|
||||
// at 16V they tend to shut off. Here, if the voltage climbs above
|
||||
// 14V due to regenerative braking, the Sabertooth will go into hard brake instead.
|
||||
// While this is occuring, the red Error LED will turn on.
|
||||
//
|
||||
// 14 X 5.12 = 71.68, so we'll go with 71, cutting off slightly below 14V.
|
||||
//
|
||||
// WARNING: This setting persists between power cycles.
|
||||
ST.setMaxVoltage(71);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ST.motor(1, 50);
|
||||
delay(5000);
|
||||
|
||||
ST.motor(1, -50);
|
||||
delay(5000);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
// Set Ramping Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
// WARNING: This sample makes changes that will persist between restarts AND in all modes.
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.autobaud();
|
||||
|
||||
// See the Sabertooth 2x60 documentation for information on ramping values.
|
||||
// There are three ranges: 1-10 (Fast), 11-20 (Slow), and 21-80 (Intermediate).
|
||||
// The ramping value 14 used here sets a ramp time of 4 seconds for full
|
||||
// forward-to-full reverse.
|
||||
//
|
||||
// 0 turns off ramping. Turning off ramping requires a power cycle.
|
||||
//
|
||||
// WARNING: The Sabertooth remembers this command between restarts AND in all modes.
|
||||
// To change your Sabertooth back to its default, call ST.setRamping(0)
|
||||
ST.setRamping(14);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Full forward, both motors.
|
||||
ST.motor(1, 127);
|
||||
ST.motor(2, 127);
|
||||
delay(5000);
|
||||
|
||||
// Full reverse
|
||||
ST.motor(1, -127);
|
||||
ST.motor(2, -127);
|
||||
delay(5000);
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
// Set Serial Timeout Sample for Packet Serial
|
||||
// Copyright (c) 2012 Dimension Engineering LLC
|
||||
// See license.txt for license details.
|
||||
|
||||
#include <Sabertooth.h>
|
||||
|
||||
Sabertooth ST(128);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SabertoothTXPinSerial.begin(9600);
|
||||
ST.autobaud();
|
||||
|
||||
// setTimeout rounds up to the nearest 100 milliseconds, so this 950 will actually be 1 second.
|
||||
// A value of 0 disables the serial timeout.
|
||||
ST.setTimeout(950);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Set motor 1 to reverse 20 (out of 127), and sleep for 5 seconds.
|
||||
// Notice how it cuts out after 1 second -- this is the serial timeout in action.
|
||||
// Since we configured it in setup() for 1 second, 1 second without any new
|
||||
// commands will cause the motors to stop.
|
||||
ST.motor(1, -20);
|
||||
delay(5000);
|
||||
|
||||
// Why do this?
|
||||
// If the S1 wire gets cut for some reason, or if your program crashes,
|
||||
// the Sabertooth will stop receiving commands from the Arduino.
|
||||
// With a timeout, your robot will stop. So, it's a safety feature mostly.
|
||||
}
|
||||
|
Reference in New Issue
Block a user