The robot utilizes the 2 axis joystick to control its movements. The movement's are very rudimentary, only being able to move forwards, backwards, turn left, and turn right.
Wiring:
This photo shows the connections between the robotic platform and the RF transceiver. The dataline is directly connected to Rx1 on the Arduino board so that it can receive and interpret the data incoming to direct the robot's movements. The Tx/Rx select is pulled low as was specified in the datasheet associated with the transceiver, pulling it low makes it act as a receiver.
This photo shows the connections between the controller and the RF transceiver. The dataline is connected to Tx0 so that it can send values to be read by robotic platform. The Tx/Rx select is pulled high to make it act as a transmitter.
This photo shows the connections between the controller and the 2 axis joystick. Power is applied to the L/R+ and the U/D+ and the datalines for L/R and U/D go to Analog ports A1 and A0 respectively.
Here is an overhead view of most of the controller circuit.
Code:
Transmitter (controller):
#include <SoftwareSerial.h>
int UD = 0;//initializes the up/down value to zero
int LR = 0;//initializes the left/right value to zero
void setup()
{
Serial.begin(2400);
/*set to 2400 baud, the corresponding receiving rate on the receiver so that the two
sets of programs can talk to each other over the RF transceivers*/
}
void loop()
{
UD = analogRead(A0);//reads the up/down analog value of the joystick
LR = analogRead(A1);//reads the left/right analog value of the joystick
if (LR < 200)
{
Serial.println("L");//a value between 400 and 90 are considered to be leftward values so a large outlier was set at 200
}
if (LR > 700)
{
Serial.println("R");//a value between 600 and 900 are considered to be rightward values so a smaller outlier was set to 700
}
if (UD > 700)
{
Serial.println("U");//the same concept applies here as did to the Serial.println("R");
}
if (UD < 300)
{
Serial.println("D");//the same concept applies here as did to the Serial.println("L"); only using 300 as the large outlier
}
if (UD > 300 && UD < 700 && LR > 200 & LR < 700)
{
Serial.println("S");//a value that is below 700, above 300, above 200, and below 700 in the UD an LR will make the robot stop
}
delay(100);
}
int UD = 0;//initializes the up/down value to zero
int LR = 0;//initializes the left/right value to zero
void setup()
{
Serial.begin(2400);
/*set to 2400 baud, the corresponding receiving rate on the receiver so that the two
sets of programs can talk to each other over the RF transceivers*/
}
void loop()
{
UD = analogRead(A0);//reads the up/down analog value of the joystick
LR = analogRead(A1);//reads the left/right analog value of the joystick
if (LR < 200)
{
Serial.println("L");//a value between 400 and 90 are considered to be leftward values so a large outlier was set at 200
}
if (LR > 700)
{
Serial.println("R");//a value between 600 and 900 are considered to be rightward values so a smaller outlier was set to 700
}
if (UD > 700)
{
Serial.println("U");//the same concept applies here as did to the Serial.println("R");
}
if (UD < 300)
{
Serial.println("D");//the same concept applies here as did to the Serial.println("L"); only using 300 as the large outlier
}
if (UD > 300 && UD < 700 && LR > 200 & LR < 700)
{
Serial.println("S");//a value that is below 700, above 300, above 200, and below 700 in the UD an LR will make the robot stop
}
delay(100);
}
Receiver (robot):
#include <SoftwareSerial.h>
const int stopValue = 0; //neutral value
const int forwardLeft = 127; //full forward (left)
const int forwardRight = 255; //full forward (right)
const int backwardLeft = 1; //full backward (left)
const int backwardRight = 128; //full backward (right)
char inByte;
/* stops robot's movement */
void stopRobot()
{
Serial3.write(stopValue); //writes pulse neutral (stopped) at 0
delay(50);
}
/* moves robot forward */
void forward()
{
Serial3.write(127);
Serial3.write(255);
delay(50);
}
/* moves robot backward */
void backward()
{
Serial3.write(1);
Serial3.write(128);
delay(50);
}
/* turns robot to the left */
void leftTurn()
{
Serial3.write(1);
Serial3.write(255);
delay(50);
}
/* turns robot to the right */
void rightTurn()
{
Serial3.write(127);
Serial3.write(128);
delay(50);
}
void setup()
{
Serial.begin(2400);
Serial1.begin(2400);
Serial3.begin(9600);
}
void loop()
{
if (Serial1.available())
{
char inByte = Serial1.read();
/*this couple of lines are the signal processing lines which take and
use the value in the following case structure */
Serial.print(inByte);
switch (inByte)
{
case 'U':
forward();//if the value received is "U" the robot will go forward
break;
case 'D':
backward();//if the value received is "D" the robot will go backward
break;
case 'L':
leftTurn();//if the value received is "L" the robot will turn left
break;
case 'R':
rightTurn();//if the value received is "R" the robot will turn right
break;
case 'S':
stopRobot();//if the value received is "S" the robot will stop (this is the default action)
break;
}
}
}
const int stopValue = 0; //neutral value
const int forwardLeft = 127; //full forward (left)
const int forwardRight = 255; //full forward (right)
const int backwardLeft = 1; //full backward (left)
const int backwardRight = 128; //full backward (right)
char inByte;
/* stops robot's movement */
void stopRobot()
{
Serial3.write(stopValue); //writes pulse neutral (stopped) at 0
delay(50);
}
/* moves robot forward */
void forward()
{
Serial3.write(127);
Serial3.write(255);
delay(50);
}
/* moves robot backward */
void backward()
{
Serial3.write(1);
Serial3.write(128);
delay(50);
}
/* turns robot to the left */
void leftTurn()
{
Serial3.write(1);
Serial3.write(255);
delay(50);
}
/* turns robot to the right */
void rightTurn()
{
Serial3.write(127);
Serial3.write(128);
delay(50);
}
void setup()
{
Serial.begin(2400);
Serial1.begin(2400);
Serial3.begin(9600);
}
void loop()
{
if (Serial1.available())
{
char inByte = Serial1.read();
/*this couple of lines are the signal processing lines which take and
use the value in the following case structure */
Serial.print(inByte);
switch (inByte)
{
case 'U':
forward();//if the value received is "U" the robot will go forward
break;
case 'D':
backward();//if the value received is "D" the robot will go backward
break;
case 'L':
leftTurn();//if the value received is "L" the robot will turn left
break;
case 'R':
rightTurn();//if the value received is "R" the robot will turn right
break;
case 'S':
stopRobot();//if the value received is "S" the robot will stop (this is the default action)
break;
}
}
}
Issues:
The only issues that came about (in this final project) was getting the robot to act based on the incoming value. I had, at one point, used if statements instead of the case structure in the receiver program and it did not work. Next, I tried using a case structure and found that I was able to get the robot to go forward only. After examining the program, I found that I had done Serial3.begin(2400); which would not properly communicate with the Sabertooth motor controller. After fixing the error, making it Serial3.begin(9600); I got full functionality.




No comments:
Post a Comment