Home Depot Special

From LVL1
Jump to: navigation, search


Home depot special is a 'bot Brian Wagner built for the fall 2010 LVL1 Sumobot competition.


Components

I will get pictures up soon, but until then here are the components I used...

Motor and wheels http://www.solarbotics.com/products/gmpw_deal/

Casters to maintain balance http://www.pololu.com/catalog/product/950

Motor Driver http://www.pololu.com/catalog/product/110 (discontinued)

Bare Bones Board Arduino clone http://shop.moderndevice.com/products/bbb-kit

New work Box - makes a nice chassis. I cut holes in this and hot-melt glued the motors in it. http://www.homedepot.com/h_d1/N-5yc1v/R-100404058/h_d2/ProductDisplay?langId=-1&storeId=10051&catalogId=10053

digital line sensor http://www.pololu.com/catalog/product/959

distance sensor http://www.pololu.com/catalog/product/1136

battery Holder for Arduino power https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2111329_-1

battery holder for motor power (9v) https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_109154_-1

Misc switches and other stuff


Code

This is the code I used. It worked OK, but not great. I need to tweak it more.



/*************************************************************
Sumo Competition program by Brian Wagner
10/24/10
 * 
 *************************************************************/

#include <PololuQTRSensors.h>
#include <PololuSerial.h>
#include <NewSoftSerial.h>

#define LineSensorLeftPin 3
#define LineSensorRightPin 2
#define RangeSensorPin 0

int LineLeft = 0;
int LineRight = 0;
int Range = 0;

int LineThreshold = 800;
int RangeThreshold = 100;

int SpinDir = 0;
int spiral = 20;

#define rxPin 0
#define txPin 4
#define rstPin 5

NewSoftSerial mySerial =  NewSoftSerial(rxPin, txPin);
PololuSerial motor = PololuSerial(&mySerial,rstPin);
byte fwVersion = -1;

unsigned int sensors[2];
PololuQTRSensorsRC qtr((unsigned char[]) {LineSensorLeftPin,LineSensorRightPin}, 2, 2000, 255); //declares two line sensors on pins 2,3

void setup()  
{
  mySerial.begin(9600);
  motor.begin();
  motor.stopBothMotors();
  delay(5000);
}

void loop() 
{
  //check line sensors
  qtr.read(sensors);
 
 if (sensors[0] < LineThreshold && sensors[1] < LineThreshold) {
    motor.stopBothMotors();
    motor.motor0Reverse(127);
    motor.motor1Reverse(127);
    delay(500);
    motor.motor1Forward(127);
    delay(300);
    motor.stopBothMotors();
  } 
  else if (sensors[0] < LineThreshold && sensors[1] > LineThreshold) {
    motor.stopMotor0();
    motor.motor1Forward(127);
    delay(40);
    motor.motor0Forward(127);
    SpinDir = 1;
    spiral = 20;
  }
 else if (sensors[0] > LineThreshold && sensors[1] < LineThreshold) {
   motor.stopMotor1();
    motor.motor0Forward(127);
    delay(40);
    motor.motor1Forward(127);
    SpinDir = 0;
    spiral = 20;
 }
 else {
        
    Range = analogRead(RangeSensorPin);
    if ( Range > RangeThreshold ) {
        //Charge!!!
        motor.motor0Forward(127);
        motor.motor1Forward(127);
        delay(100);
    }
    else {
    //let's look around
      if (SpinDir == 1 ) {
        motor.motor0Forward(80);
        motor.motor1Forward(80);
      } else {
        motor.motor1Forward(80);
        motor.motor0Forward(80);    
      }
        delay(20); 
        //spiral = spiral +20;    
       // if (spiral > 100) { spiral = 20; }
        //motor.stopBothMotors();
    }
    
 }

}