Phase 9 - Web Control (Serial Preview/Wannabe Web Control)

The thought occurred to me to test out a basic sketch for the wireless control portion in phase 9. Even though I'm not there yet, I'll be waiting on parts for awhile and thought to try my hand at serial commands. I do a lot of "remote desktop"-ing for work and use a free program called TeamViewer to remotely control a computer when there is a problem. I'm not an IT expert, but I'm just dangerous in enough areas that I get called on to do things like that from time to time. It's helped me tremendously when on business trips.

The idea here is that I can sketch out a basic framework for future telecommands with serial input... and silly as it may be, things like this really help me grasp what it is I'm trying to accopmlish with this robot... so, I tethered my laptop to the robot and "remoted in" to send serial commands from my desktop machine to the laptop running the arduino IDE with serial monitor open.

It was easy, and successful. I could even get video stream from a webcam to satisfy my IP camera fantasies... there was just one problem. The laptop was waaaay too heavy for this little robot to pull. It seriously makes me wonder what type of lightweight IP camera system I'm going to have to use for this project. However, I had a USB cable extension and was able to have a few feet of maneuverability. Knowing that this kind of thing is even possible makes me happy. Here comes the sketch:

#include <AFMotor.h>

AF_DCMotor frontMotor(1); //Declaration of Front Motor for M1 of Motor Shield

AF_DCMotor rearMotor(3);  //Declaration of Rear Motor for M3 of Motor Shield

AF_DCMotor steerMotor(2);  //Declaration of Steer Motor for M2 of Motor Shield

int runSpeed = 255, turnSpeed = 255; //Declared speed for the Motor

void setup() {

  Serial.begin(9600);   // initialize serial communication:

  frontMotor.setSpeed(runSpeed);

  rearMotor.setSpeed(runSpeed);

  steerMotor.setSpeed(turnSpeed);

  frontMotor.run(RELEASE);

  rearMotor.run(RELEASE);

  steerMotor.run(RELEASE); 

}

void loop()

{

if (Serial.available()) {

    char ser = Serial.read();

   if(ser == '8'){

    Forward(); 

   }else if(ser == '2'){

    backupTurn(); 

   }

 }

}

 

void Forward() 

{

 Serial.println("Forward..."); 

  (runSpeed = 255);

  steerMotor.run(RELEASE); // stops steering motor

  frontMotor.run(FORWARD);

  frontMotor.setSpeed(runSpeed);

  rearMotor.run(FORWARD);

  rearMotor.setSpeed(runSpeed); 

  delay (1000);

}

void backupTurn() 

{

 Serial.println("backing up and turning...");

  (runSpeed = 255);

  steerMotor.run(FORWARD);

  steerMotor.setSpeed(turnSpeed);

  frontMotor.run(BACKWARD);

  frontMotor.setSpeed(runSpeed);

  rearMotor.run(BACKWARD);

  rearMotor.setSpeed(runSpeed);

  delay (1500);

End Phase 9's Wannabe Web Control