robotics company robot company  

Go Back   Trossen Robotics Community > Blogs > mannyr7

Rate this Entry

IRBot

Posted 10-12-2009 at 10:32 PM by mannyr7
Updated 3 Weeks Ago at 01:48 AM by mannyr7
I've built my first Arduino-based bot today. It's a wheeled rover with Sharp IR sensor for obstacle detection. The brains are a Boarduino w/ Atmega 328 inserted in a mini breadboard from Radio Shack. For locomotion, I'm using a pair of Hitec HSR-1425 continuous rotation servos and a 1/2" plastic ball caster. This is just a little diversion from work on my Mech Warfare bot, but I'd like to play around with the code some more and try out different sensors. It's just the right size platform to experiment with line following, sumo, maybe even firefighting! I have some Tamiya 3V DC motors and a track kit that will find their way on later, once I get a suitable motor controller.

Parts List:

$17.50 DC Boarduino kit
$12.99 Hitec HSR -1425CR servos (each x2)
$ 7.50 Hitec Plastic Servo Wheels w/ Tires (pair)
$ 5.95 Lynxmotion aluminum servo bracket (pair)
$ 3.99 Pololu 1/2" Ball caster
$12.99 Sharp IR sensorGP2D12
$ 1.95 Sharp IR sensor to servo cable
$ 3.00 9V battery clip with 2.1mm barrel plug
$ 5.00 half-size breadboard
-------
$81.91 Total (not including tax, shipping, and misc. items such as screws and wire)

A $20.00 USB-TTL to RS-232 cable is required to upload sketches to this board, as it has no onboard FTDI chip. I am not including this in the cost, as I plan to reuse the cable for other projects besides this. And its not physically mounted on the bot.

All this is attached to a piece of scrap aluminum I had laying around, but a piece of 1/8" plastic or wood should work just as well. I splurged a little on the aluminum servo brackets and caster. You could just servo tape or velcro the servos to your base. You could also shave some dough, shopping around for cheaper servos and wheels (peanut butter lids work great!)

Code:
/* Project: IRBot
 * Differential drive robot using continuous rotation hobby servos
 * and Sharp GP2D12 IR sensor for collision avoidance. 
 * Inspired by: Makey Robot, MAKE Magazine, Volume 19, p. 77, created: June 2009 Kris Magri
 * Modified: Oct 11, 2009 'MannyR7' mramirezjr7(AT)yahoo(DOT)com
 */
  #include <Servo.h> 
  
  #define BOUNDARY     10      // Avoid objects closer than ~24"

  Servo leftservo;  // create servo objects to control a servo 
  Servo rightservo;  // 0 = full speed forward, 90 = full stop, 180 = full reverse (ONE SERVO IS REVERSE ROTATION!!!)

  long distance1 = 0;   // First distance reading from rangefinder.
  long distance2 = 0;   // Second distance reading from rangefinder. 
  long distance3 = 0;   // Third distance reading from rangefinder.
  int irReader = 1;    // the analog input pin for the IR reader

void setup()                                                 
{
  leftservo.attach(9);  // attaches the servos on pins 9 and 10 to the servo objects 
  rightservo.attach(10);
}

// Main program
// Roam around while avoiding objects.
// 
// Set motors to move forward,
// Take distance readings over and over, 
// as long as no objects are too close (determined by BOUNDARY).
// If object is too close, avoid it -- back up and turn.
// Repeat.

void loop()                     
{    
  do 
  {
    forward(); // Robot moves forward continuously.    
    distance1 =  analogRead(irReader);// Take a distance reading from the IR sensor
    delay(30);
    distance2 =  analogRead(irReader);// Take a distance reading from the IR sensor
    delay(30);   
    distance3 = analogRead(irReader);// Take a distance reading from the IR sensor
    delay(30);
    distance1 = ((distance1 + distance2 + distance3)/3);
  }
  while(distance1 < BOUNDARY);      // Loop while no objects close-by.
    // Robot has sensed a nearby object and exited the while loop. Take evasive action to avoid object.     
    backward();    // Move backward 300ms.          
    delay(300);     
    rightTurn();   // Turn right 500ms. ~ 45 degrees  
    delay(500);     
 } // end Main program

void forward()
{ 
    leftservo.write(0);           // tell servo to go to position in variable 'pos'
    rightservo.write(180);        // tell servo to go to position in variable 'pos'
    delay(500);
}  

void backward()
{
    leftservo.write(180);           // tell servo to go to position in variable 'pos'
    rightservo.write(0);           // tell servo to go to position in variable 'pos'           
}

void rightTurn()
{
    leftservo.write(0);           // tell servo to go to position in variable 'pos'
    rightservo.write(0);           // tell servo to go to position in variable 'pos'
}
Video as promised!!

Submit "IRBot" to Digg Submit "IRBot" to del.icio.us Submit "IRBot" to StumbleUpon Submit "IRBot" to Slashdot Submit "IRBot" to Google
Posted in Uncategorized
Views 330 Comments 0 Email Blog Entry
Total Comments 0

Comments

 
Total Trackbacks 0

Trackbacks


All times are GMT -5. The time now is 06:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.