Tuesday, October 15, 2013

Sabertooth with Serial commands

This assignment was similar to the last one but with simplified programming. This was very similar to the last assignment with the same moves and displays on the screen.

 
 
The wiring for this assignment was almost identical to the last one. The Sabertooth had less wires going to the Arduino because we switched to the Simplified Serial mode. This made it easier to control the motors and less cluttered. We also did not need power going to the Arduino from the Sabertooth because the power was a little redundant. The Simplified Serial mode also required us to move the signal wire to a TX port so it was able to control both motors.
 
 
 
The programming was simple and much easier for this assignment for several reasons. I didn't have to include any libraries, assign any variables, or define any servos. This made reading the program much easier and more straight-forward. I did have some trouble with one of my motors not moving at full speed but I found that it was a programming error and I was able to fix it (after switching many other things only to find that they weren't my problem). 
 
 
 
/*
Brian Swanson
AR II

This program is the first to use Serial.write to control the speed controllers. 
Parts:
Arduino Mega
2 Motors
1 Sabertooth Dual Speed Controller
1 Breadboard
1 Switch

Connections:
Sabertooth connected to TX2
LCD Screen connected to TX3
Battery, Arduino, Sabertooth to ground
Switch, Arduino, Sabertooth to power

0-both motors stop
1-left full reverse
64-left stop
127-left full forward
128-right full reverse
191-right stop
255-right full forward

*/
void halt()
{
  Serial3.write(12);          //12 is the command to clear the LCD screen
  delay(5);                   //mandatory delay
  Serial3.print("stop");      //prints "stop" to the screen
  Serial2.write(0);          
  delay(1000);
}

void forward()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("forward");
  Serial2.write(127);
  Serial2.write(255);
  delay(1000);
}

void slowForward()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("slowForward");
  Serial2.write(110);
  Serial2.write(238);
  delay(1000);
}

void backwards()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("backwards");
  Serial2.write(1);
  Serial2.write(128);
  delay(1000);
}

void slowBackwards()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("slowBackwards");
  Serial2.write(30);
  Serial2.write(157);
  delay(1000);
}

void turnLeft()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("turnLeft");
  Serial2.write(16);
  Serial2.write(230);
  delay(1000);
}

void turnRight()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("turnRight");
  Serial2.write(112);
  Serial2.write(143);
  delay(1000);
}

void veerRight()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("veerLeft");
  Serial2.write(127);
  Serial2.write(225);
  delay(1000);
  Serial3.write(12);
}

void veerLeft()
{
  Serial3.write(12);
  delay(5);
  Serial3.print("veerLeft");
  Serial2.write(97);
  Serial2.write(255);
  delay(1000);
}

void pause()
{
  Serial2.write(0);
  delay(250);
}
void setup()
{
  Serial2.begin(9600);      //motors and screen on same baud
  Serial3.begin(9600);
}
void loop()
{
  halt();
  forward();
  pause();
  slowForward();
  pause();
  backwards();
  pause();
  slowBackwards();
  pause();
  turnLeft();
  pause();
  turnRight();
  pause();
  veerLeft();
  pause();
  veerRight();
  pause(); 
}

 
 
 
 



No comments:

Post a Comment