In this section you will find, where possible, the details of components used to build this robot and specific information about the software and about connections implemented
If you need additional specific information about this topic or if you want to look it personally please write an email
if (currMode == AUTOMODE) //Drive it manually
{
//Read Joystick values
SteerLeftPin = digitalRead(STEERINGLEFTPIN);
SteerRightPin = digitalRead(STEERINGRIGHTPIN);
balancelForward = digitalRead(BALANCEFORWARDPIN);
balancelBackward = digitalRead(BALANCEBACKWARDPIN);
DBGString[0] = '\0';
//Maintain maximum speed
if (curAutoSpeed > SABER_MOTOR1_HALF_FORWARD)
curAutoSpeed = SABER_MOTOR1_HALF_FORWARD;
if (SteerLeftPin == 0) {
SerialTransfer.isBack = false;
if (previousDirection == 99) {
previousDirection = LEFT;
curAutoSpeed = 1;
}
else if (previousDirection == LEFT)
curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
else {
previousDirection = LEFT;
curAutoSpeed = 1;
}
if ((curAutoSpeed % 5) == 0) { //Delay the string
sprintf(DBGString, "Turn RIGHT: %d\r", curAutoSpeed); //wrong string due to an error
SerialTransfer.SendDisplayString((char*)DBGString,0);
DBGString[0] = '\0';
}
//and now turn left
autoTurnLeft();
delay(50); //Slow down to delay cicles
}
else if (SteerRightPin == 0) {
SerialTransfer.isBack = false;
if (previousDirection == 99) {
previousDirection = RIGHT;
curAutoSpeed = 1;
}
else if (previousDirection == RIGHT)
curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
else {
previousDirection = RIGHT;
curAutoSpeed = 1;
}
//Turn right
if ((curAutoSpeed % 5) == 0) { //Delay the string
sprintf(DBGString, "Turn LEFT: %d\r", curAutoSpeed); //wrong string due to an error
SerialTransfer.SendDisplayString((char*)DBGString,0);
DBGString[0] = '\0';
}
autoTurnRight();
delay(50); //Slow down to delay cicles
}
else if (balancelForward == 0) {
SerialTransfer.isBack = false;
if (previousDirection == 99) {
previousDirection = FORWARD;
curAutoSpeed = 1;
}
else if (previousDirection == FORWARD)
curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
else {
previousDirection = FORWARD;
curAutoSpeed = 1;
}
if ((curAutoSpeed % 5) == 0) { //Delay the string
sprintf(DBGString, "Go FORWARD: %d\r", curAutoSpeed);
SerialTransfer.SendDisplayString((char*)DBGString,0);
DBGString[0] = '\0';
}
autoGoForward();
delay(50); //Slow down to delay cicles
}
else if (balancelBackward == 0) {
SerialTransfer.isBack = true;
if (previousDirection == 99) {
previousDirection = BACKWORD;
curAutoSpeed = 1;
}
else if (previousDirection == BACKWORD)
curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
else {
previousDirection = BACKWORD;
curAutoSpeed = 1;
}
if ((curAutoSpeed % 5) == 0) { //Delay the string
sprintf(DBGString, "Go BACKWORD: %d\r", curAutoSpeed);
SerialTransfer.SendDisplayString((char*)DBGString,0);
DBGString[0] = '\0';
}
//go backward
autoGoBackward();
delay(50); //Slow down to delay cicles
}
else
{
if (curAutoSpeed > 0) {
delay(50);
curAutoSpeed-=2;
switch (previousDirection){
case FORWARD:
autoGoForward();
break;
case BACKWORD:
autoGoBackward();
break;
case LEFT:
autoTurnLeft();
break;
case RIGHT:
autoTurnRight();
break;
}
}
else
{
previousDirection = 99;
}
//This is the declaration of the Sabertooth object. SWSerial is the serial port used.
//In my case I am using the wire lib to create a virtual
//Serial port using a separate pin on the Arduino board
Sabertooth ST(128, SWSerial);
//This function must be used at the beginning of your code to initialise the serial communication
//The serial communication can be obtained using the "wire" library or using a direct serial connection
void initSabertooth (void) {
SWSerial.begin(9600);
ST.autobaud();
}
//In the stup function I strongly suggest to stop all motors using these commands
ST.motor(1, SABER_ALL_STOP);
ST.motor(2, SABER_ALL_STOP);
//This is an example of the turn right function
//Simply tell to the motor the speed that is from 0 to 128 for a forward speed
//and from -1 to -128 for a backuward speed
//Other functions can be obtained in the same way
void autoTurnRight() {
ST.motor(1, curAutoSpeed);
ST.motor(2, curAutoSpeed - (curAutoSpeed * 2));
}