Friday, November 29, 2013

Agile Robotics Final Project: Weeks 2 & 3

This was due a week or so ago but I haven't spent a significant amount of time on the robot as life has been preoccupying me.

Some updates:


  • Got the main "tracking rail" for the bed edge built and programmed to return
  • Began working on the actual following of the bed edge




Wiring:

In this photo, the connections between the servo and sensors are given. The push button and limit switch are connected to a "pull-up" resistor. The connections have been rearranged for organization in the past week.

Code: (uncommented)

#include <Servo.h>


 int val;
 int encoder0PinA = 12;
 int encoder0PinB = 13;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;
 Servo finderServo;

 int stopButton = 4;
 int resetButton = 3;
 int stopButtonValue = 0;
 int resetButtonValue = 0;


 int encoderRead()
 {
    n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
     Serial.println (encoder0Pos);
   }
   encoder0PinALast = n;
 }

 void armIn()
 {
   finderServo.write(0);
 }

 void armOut()
 {
   finderServo.write(180);
 }

 void armStop()
 {
   finderServo.write(90);
 }

 void armReturn()
 {
   while(stopButtonValue == 0)
   {
     stopButtonValue = digitalRead(stopButton);
     armIn();
   }
   armStop();
   Serial.print("StopButton Value =");
   Serial.println(stopButtonValue);
 }

 void setup() {
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   Serial.begin (9600);
   finderServo.attach(9);
   pinMode (resetButton, INPUT);
   pinMode (stopButton, INPUT);
 }

 void loop()
 {
 
   while(resetButtonValue == 0)
   {
     resetButtonValue = digitalRead(resetButton);
     armStop();
     Serial.print("ResetButton Value = ");
     Serial.println(resetButtonValue);
     delay(50);
   }
 
   while (stopButtonValue == 0)
   {
     stopButtonValue == digitalRead(stopButton);
     armReturn();
     Serial.print("ResetButton Value = ");
     Serial.println(resetButtonValue);
     delay(50);
   }
 
   encoderRead();
 
   if(encoder0Pos < 150)
   {
    armOut();
   }
 
  if(encoder0Pos > 150)
   {
    armStop();
   }
 } 

Issues:
No significant issues have come about other than a minor encoder issue with getting it to read properly but this was resolved.

Tuesday, November 19, 2013

Agile Robotics Final Project: Week 1

I was lazy and didn't do any work from Tuesday, November 5 until Tuesday, November 12. On this day, however I began assembling the main parts of the robot. Information on this will be in  Agile Robotics Final Project: Week 2.

Tuesday, November 5, 2013

Own Programmed RC

The assignment given, really for the previous week but I couldn't get to work due to complexity, for this week was to integrate two more IOs to the Arduino, research them, and program to be able to use them. I chose two RF transceivers (pictured below) and a 2 axis joystick (also pictured below). Both of the integrated IOs used were developed by Parallax. About 6 hours were spent on the previous (failed) attempt and 4 spent on the most recent (successful) attempt at getting the robot to perform as desired.

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);
}




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;
   }
  }
}

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.