Monday, October 7, 2013

Using Different Speed Controllers for the Same Thing

There were two parts to this assignment. In the first part, we used two Parallax speed controllers and then switched to one dual Sabertooth speed controller. We had to do a set of basic maneuvers and display messages on a screen while it went through the process.

 
It took me about 4 or 5 hours to complete the whole assignment and I found out that there was more to be learned than I thought. The wiring for the Parallax speed controllers was similar to the previous assignment except for the Parallax also needed 3-pin connectors that needed to go to the Arduino. The Parallax screen also had a 3-pin connector that I connected to the Arduino with the TX3 port.
 

 
The programming was the part where I learned the most. I had trouble at first with printing to the screen but after looking online, I was able to find out one way to print to the screen. I later revised this due to some advisement and better programming techniques. I watched several videos made by "drbrono" on YouTube and found them very helpful with programming the screen. 
 
 
 
/*
Brian Swanson
AR II

The assignment was to use the Arduino to control the two Parallax speed controllers.
Parts:
Arduino Mega
2 Motors
2 Parallax Speed Controllers
1 Breadboard
1 Switch

Connections:

Left speed controller to PWM 13
Right speed controller to PWM 12
Battery, Arduino, Right and Left Speed controller to ground
Switch, Arduino, Right and Left Speed controller to power

*/
#include <Servo.h>          //Adds Library for servos
Servo left;
Servo right;

int leftMotor = 13;        //sets motors for PWM ports
int rightMotor = 12;
byte clrscn = 12;          //sends a byte instead of a bit for the clear screen command

void forward()
{
  Serial3.write(clrscn);          //writes to TX3 and RX3 to clear the screen
  delay(5);                        //mandatory delay after command
  Serial3.print("forward");        //prints "forward" on the screen
  left.writeMicroseconds(1900);
  right.writeMicroseconds(1800);
  delay(1000);
}

void slowForward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("slowForward");
  left.writeMicroseconds(1650);
  right.writeMicroseconds(1650);
  delay(1000);
}

void backward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("backward");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(1200);
  delay(1000);
}

void slowBackward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("slowBackward");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(1300);
  delay(1000);
}

void rightTurn()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("rightTurn");
  left.writeMicroseconds(2000);
  right.writeMicroseconds(1000);
  delay(1000);
}

void leftTurn()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("leftTurn");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(2000);
  delay(1000);
}

void veerRight()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("veerRight");
  left.writeMicroseconds(1900);
  right.writeMicroseconds(1700);
  delay(2000);
}

void veerLeft()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("veerLeft");
  left.writeMicroseconds(1700);
  right.writeMicroseconds(1900);
  delay(1000);
  Serial3.write(clrscn);
}

void motorStop()
{
  left.writeMicroseconds(1500);
  right.writeMicroseconds(1500);
  delay(1000);
}

void motorPause()
{
  left.writeMicroseconds(1500);
  right.writeMicroseconds(1500);
  delay(250);
}

void setup()
{
  left.attach(leftMotor);
  right.attach(rightMotor);
  Serial3.begin(9600);          //sets the baud of the motors and the screen the same
  Serial.begin(9600);
}

void loop()
{
  Serial3.write(17);      //command to turn the backlight on
  motorStop();
  forward();
  motorPause();
  slowForward();
  motorPause();
  backward();
  motorPause();
  slowBackward();
  motorPause();
  leftTurn();
  motorPause();
  rightTurn();
  motorPause();
  veerRight();
  motorPause();
  veerLeft(); 
  Serial3.write(18);      //command to turn the backlight off
  delay(1000);
}

 

  

 

 


 

 
 

The wiring for the Sabertooth was the biggest difference between it and the Parallax speed controllers. It was much less cluttered with just one speed controller in my robot. I had to take four wires from the Sabertooth to the Arduino to control each motor, power, and ground. The other side of the Sabertooth had connections for two wires from each motor and a spot for power and ground. This is where I tied together power from the Arduino and the switch with the Sabertooth and ground from the Arduino and battery with the Sabertooth.



The programming was identical to the first but I still had to work out some bugs. I had to switch the wires going into the Sabertooth to change the direction that the wheels were spinning. after solving all of these problems, I was able to complete this project.

Robot with Sabertooth dual speed controller


Sorry the video is upside down and there is a spot where it loses traction fro a second.


/*
Brian Swanson
AR II

The assignment was to use the Arduino to control the Sabertooth dual speed controller.
Parts:
Arduino Mega
2 Motors
1 Sabertooth Dual Speed Controller
1 Breadboard
1 Switch

Connections:
Left speed controller to PWM 13
Right speed controller to PWM 12
Battery, Arduino, and Sabertooth to ground
Switch, Arduino, and Sabertooth to power

*/
#include <Servo.h>          //Adds Library for servos
Servo left;
Servo right;

int leftMotor = 13;        //sets motors for PWM ports
int rightMotor = 12;
byte clrscn = 12;          //sends a byte instead of a bit for the clear screen command

void forward()
{
  Serial3.write(clrscn);          //writes to TX3 and RX3 to clear the screen
  delay(5);                        //mandatory delay after command
  Serial3.print("forward");        //prints "forward" on the screen
  left.writeMicroseconds(1900);
  right.writeMicroseconds(1800);
  delay(1000);
}

void slowForward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("slowForward");
  left.writeMicroseconds(1650);
  right.writeMicroseconds(1650);
  delay(1000);
}

void backward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("backward");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(1200);
  delay(1000);
}

void slowBackward()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("slowBackward");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(1300);
  delay(1000);
}

void rightTurn()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("rightTurn");
  left.writeMicroseconds(2000);
  right.writeMicroseconds(1000);
  delay(1000);
}

void leftTurn()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("leftTurn");
  left.writeMicroseconds(1000);
  right.writeMicroseconds(2000);
  delay(1000);
}

void veerRight()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("veerRight");
  left.writeMicroseconds(1900);
  right.writeMicroseconds(1700);
  delay(2000);
}

void veerLeft()
{
  Serial3.write(clrscn);
  delay(5);
  Serial3.print("veerLeft");
  left.writeMicroseconds(1700);
  right.writeMicroseconds(1900);
  delay(1000);
  Serial3.write(clrscn);
}

void motorStop()
{
  left.writeMicroseconds(1500);
  right.writeMicroseconds(1500);
  delay(1000);
}

void motorPause()
{
  left.writeMicroseconds(1500);
  right.writeMicroseconds(1500);
  delay(250);
}

void setup()
{
  left.attach(leftMotor);
  right.attach(rightMotor);
  Serial3.begin(9600);          //sets the baud of the motors and the screen the same
  Serial.begin(9600);
}

void loop()
{
  Serial3.write(17);      //command to turn the backlight on
  motorStop();
  forward();
  motorPause();
  slowForward();
  motorPause();
  backward();
  motorPause();
  slowBackward();
  motorPause();
  leftTurn();
  motorPause();
  rightTurn();
  motorPause();
  veerRight();
  motorPause();
  veerLeft(); 
  Serial3.write(18);      //command to turn the backlight off
  delay(1000);
}












 

No comments:

Post a Comment