Let's Make Robots!

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Have you considered using a Raspberry Pi (or any other embedded PC of choice)?

I say this because I just completed controlling a servo from a web page using the Raspberry Pi, and it wasn't nearly as bad as I thought.  I'm a Windows guy, so I've had some growing pains context switching to Linux, but luckily with the Pi there's enough community that google searching can usually get you unstuck.

Now I just drove the servo right off the GPio pin, but I just got in (yet another) Uno-compatible board, so I'm going to experiment with the good ol Arduino/Pi combo.  

Just may be something you want to look into, and I can point you towards some resources and help you out (at least get you as far as I got) if/when you get stuck.

Hi lukeyes, yes, I've thought a lot about both the raspberry pi an the beaglebone black, but I want to try and finish this with the metric crapton of arduino boards, shields, sensors, etc. first.