Yellow Bug Eye

Apr 24, 2011

I’m taking a break from the autopilot project and just to keep my wit sharp, I built another robot. It’s a tank style and not really all that big a deal. It uses a DFRobot tread platform with twin 6v DC motors. I got it from the RobotShop for $50. Onto this went a universal mounting plate from Tamiya and a piece of perforated plastic strip the length of the platform but only half as wide. On this I mounted a servo upon which I placed a Sharp IR Ranging unit. This way, the robot can look both left and right as well as ahead. I also put an IR switch onto the platform. This looks at the ground in front of the robot, checking for dropoffs. If suddenly the ground drops away, the pin on the microcontroller it uses will go HIGH until the ground comes back. This makes a great detector to make sure the robot doesn’t drive itself off a table or down a flight of stairs. Just for the hell of it I installed a pair of superbright LEDs in the front as headlights, and installed a laser on the turret to show what the IR was looking at.

I use an Arduino Duemilanove as the brain and used a cheapo motor controller from RobotKits in India. I decided to power the whole thing on 5v, so I started out with a 7.4v lipo battery and then built a DC to DC converter/regulator. It uses 3 7806 voltage regulators in Parallel. For isolation, I use a diode on the outputs, and I have a filter cap to ground (.01 uf) as well. This allows the board to put out 5.3v DC, regulated. It is short the junction drop of the diodes, which deducts .7 volts from the 6 volt regulator output. I could get the voltage back up to 6 by putting a diode between the regulator ground pins and ground, but I want the 5.3 volts because it is close enough for the Arduino, IR Sensors, Motor Controller, and, of course, the 6v robot motors which will now never be driven hard enough to burn them out.

I use a pretty off the shelf type sketch:

 

#include <Servo.h>

#define sharp 0     //infrared ranger on analog 0
#define ir 5        //infrared sensor on digital 5
#define m1_1 6      //motor 1 forward
#define m1_2 9      // motor 1 backward
#define m2_1 10     //motor 2 forward
#define m2_2 11     //motor 2 backward

float l_volts = 0;  // left side range
float r_volts = 0;  // right side range
float c_volts = 0;  // center range
float volts = 0;    // utility variable
float distance = 0;

Servo pan;          //declare a servo

void setup() {
pan.attach(3);    //servo on digital 3
pan.write(90);    //center it
Serial.begin(9600);
pinMode(ir, INPUT);
pinMode(sharp, INPUT);
pinMode(m1_1, OUTPUT);
pinMode(m1_2, OUTPUT);
pinMode(m2_1, OUTPUT);
pinMode(m2_2, OUTPUT);
}

void halt() {
digitalWrite(m1_1, 0);
digitalWrite(m1_2, 0);
digitalWrite(m2_1, 0);
digitalWrite(m2_2, 0);
}

void ahead() {
digitalWrite(m1_1, 0);
digitalWrite(m1_2, 1);
digitalWrite(m2_1, 0);
digitalWrite(m2_2, 1);
}

void back() {
digitalWrite(m1_1, 1);
digitalWrite(m1_2, 0);
digitalWrite(m2_1, 1);
digitalWrite(m2_2, 0);
}

void left() {
digitalWrite(m1_1, 0);
digitalWrite(m1_2, 0);
digitalWrite(m2_1, 0);
digitalWrite(m2_2, 1);
}

void right() {
digitalWrite(m1_1, 0);
digitalWrite(m1_2, 1);
digitalWrite(m2_1, 0);
digitalWrite(m2_2, 0);
}

float scan() {
volts = analogRead(sharp) * (5/1024);
distance = 65 * pow(volts, -1.10);
distance = distance / 6;
return(distance);
}

void look_left() {
for (int pos=90; pos >=20; pos–) {
pan.write(pos);
delay(10);
}
}

void look_right() {
for (int pos=90; pos <=160; pos++) {
pan.write(pos);
delay(10);
}
}

void center() {
int x = pan.read();
if (x < 90) {
for (int pos=20; pos <=90; pos++) {
pan.write(pos);
delay(10);
}
}
if (x > 90) {
for (int pos=160; pos >=90; pos–) {
pan.write(pos);
delay(10);
}
}
pan.write(90);
}

void dropoff() {
if (digitalRead(ir) == HIGH) {
back();
delay(1500);
left();
delay(800);
halt();
}
}

void l_avoid() {
left();
delay(1200);
ahead();
}

void r_avoid() {
right();
delay(1200);
ahead();
}

void loop() {
ahead();
dropoff();
look_left();
delay(300);
scan();
l_volts = distance;
Serial.println(l_volts,DEC);
dropoff();
center();
delay(300);
scan();
c_volts = distance;
Serial.println(c_volts,DEC);
dropoff();
look_right();
delay(300);
scan();
r_volts = distance;
Serial.println(r_volts,DEC);
dropoff();
center();
delay(300);

if (c_volts < 25) {
if (l_volts > r_volts) {
l_avoid();
}
else {
r_avoid();
}
}
if (l_volts < 10) {
right();
delay(500);
ahead();
}
if (r_volts < 10) {
left();
delay(500);
ahead();
}
}

 

 

 

 

 

 

Anyway, that’s the new robot and I call it the Yellow Bug Eye because it’s yellow with bug eyes.