Home Depot Special

From LVL1
Revision as of 10:13, 16 February 2011 by Bpwagner (talk | contribs) (→‎Code)
Jump to navigation Jump to 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.

/*************************************************************
Motor test by Brian Wagner
10/21/10
 * 
 *************************************************************/

#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 = 7;
int RangeThreshold = 100;

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

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

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

void loop() 
{
  //check line sensors
  //1 = white, 15 = black
  //left Sensor
  pinMode( LineSensorLeftPin, OUTPUT );
  digitalWrite( LineSensorLeftPin, HIGH );
  delayMicroseconds( 50 );
  pinMode( LineSensorLeftPin, INPUT );
  long LineLeft	= 0;
  while ( digitalRead( LineSensorLeftPin ) == HIGH ) {
    LineLeft++;
    if ( LineLeft == 15 ) { break; }
    delay( 20 );
  }

  //right sensor
  pinMode( LineSensorRightPin, OUTPUT );
  digitalWrite( LineSensorRightPin, HIGH );
  delayMicroseconds( 50 );
  pinMode( LineSensorRightPin, INPUT );
  long LineRight = 0;
  while ( digitalRead( LineSensorRightPin ) == HIGH ) {
    LineRight++;
    if ( LineRight == 15 ) { break; }
    delay( 20 );
  }
 
 if (LineLeft < LineThreshold and LineRight < LineThreshold) {
    motor.stopBothMotors();
    motor.motor0Reverse(127);
    motor.motor1Reverse(127);
    delay(500);
    motor.motor1Forward(127);
    delay(300);
    motor.stopBothMotors();
  } 
  else if (LineLeft < LineThreshold) {
    motor.stopBothMotors();
    motor.motor1Forward(127);
    delay(10);
  }
 else if (LineRight < LineThreshold) {
   motor.stopBothMotors();
    motor.motor0Forward(127);
    delay(10);
 }
 else {
        
    Range = analogRead(RangeSensorPin);
    if ( Range < RangeThreshold ) {
        //Charge!!!
        motor.motor0Forward(127);
        motor.motor1Forward(127);
        delay(1000);
    }
    else {
    //let's look around
        motor.motor0Forward(64);
        motor.motor1Forward(0);    
        delay(10);     
    }
    
 }

}