Mikey, the Robot With Vision

by MikeTheMaker in Circuits > Robots

35564 Views, 65 Favorites, 0 Comments

Mikey, the Robot With Vision

mikey81.jpg

Mikey the Robot "sees the frog" using the Pixy camera vision system. Pixy costs about $70. and easily interfaces with an included cable to Arduino. Pixy can be "trained" to recognize up to seven different colors. Pixy returns the x,y coordinates of the center of a trained object, along with the width and height of the object. Pixy is open source and all the hardware and software are available through cmucam.org.

In my setup, Pixy communicates with an Arduino which I call a "Sensor Interface." When the center of the target (frog) is toward the right (>170 out of 319), the red LED illuminates and the robot turns toward the right. When the frog is toward the left (<150 out of 319), the white LED illuminates and the robot turns to the left. When the frog is pretty much in the center (>150 and <170), both LEDs illuminate and the robot moves forward.


Parts:

Pixy Camera---Amazon.com

4WD Arduino Compatible Mobile Platform--Makershed.com

Arduino Motor Shield--Makershed.com

(2) Arduino Uno--Amazon.com

(7) NiMh AA batteries--Amazon.com

Misc: Red led, white led, (2) 220 ohm resistors, SPST toggle switch

mikey2.jpg

Start by soldering wires to the motors on the mobile platform. I used an AA battery to make sure that positive on the red wire and negative on the black would cause each motor to move the platform forward. This needs to be consistent on all motors (which means the red wire will probably be on top of the right side motors and on the bottom of the left side motors).

mikey2.jpg

Secure the lower plate with screws, making sure that the motor wires come through open holes.

mikey3.jpg

Add battery holders. My choice of (7) AA batteries relates to a future recharging home base (which Mikey will locate using his vision--soon).

mikey6.jpg
mikey5.jpg
mikey4.jpg

Add the upper plate, switch, two Arduinos (one with a motor shield on top) and the Pixy Camera.

Files for the 3D printed switch holder can be found here:

http://www.thingiverse.com/thing:331319

Pixy is connected to the Arduino with a simple cable (included with Pixy). More information on connecting Pixy can be found here:

http://cmucam.org/projects/cmucam5/wiki/Hooking_up...

Training Pixy

mikey7.jpg

Training Pixy to a color is mainly a question of holding a button (red for the first color, orange second, yellow third, green fourth, cyan fifth, blue sixth, violet seventh) then releasing. Place the object in front of the camera. When the LED is pretty much the color of the object, quickly press and release the button. The LED will blink red a few times if Pixy "bought" the object. That's it.

Schematic

schematic14052014.jpg

This is the schematic.

Sensor Software

The sensor software for Arduino is a modified version of their "hello world" sketch.

Download the Arduino library "arduino_pixy-x.y.z.zip" here.

http://cmucam.org/attachments/download/958/arduino...

Bring up the Arduino IDE and import the Pixy library by selecting SketchâžœImport Library in the Arduino IDE, and then browsing to the Pixy.zip file that you just downloaded.

//
// begin license header // // This file is part of Pixy CMUcam5 or "Pixy" for short // // All Pixy source code is provided under the terms of the // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html). // Those wishing to use Pixy source code, software and/or // technologies under different licensing terms should contact us at // cmucam@cs.cmu.edu. Such licensing terms are available for // all portions of the Pixy codebase presented here. // // end license header //

#include #include

Pixy pixy;

int stuff=0; int position=150; const int red=5; const int white=9; const int redled=3; const int whiteled=8;

void setup() {

pinMode(red, OUTPUT); pinMode(white, OUTPUT); pinMode(redled, OUTPUT); pinMode(whiteled,OUTPUT); digitalWrite(redled, HIGH);//right test digitalWrite(whiteled,HIGH);//left test delay(2000); digitalWrite(redled,LOW);//right off digitalWrite(whiteled,LOW);//left off digitalWrite(red,LOW); digitalWrite(white,LOW); delay(2000);

Serial.begin(9600); Serial.print("Starting...\n"); }

void loop() { static int i = 0; int j; uint16_t blocks; char buf[32]; blocks = pixy.getBlocks(); if (blocks) { i++; if (i%50==0) { //sprintf(buf, "Detected %d:\n", blocks); // Serial.print(buf); //for (j=0; j170) { digitalWrite(red,HIGH); digitalWrite(redled,HIGH); delay(1000); digitalWrite(red,LOW); digitalWrite(redled,LOW); } if(pixy.blocks[j].x<150){ digitalWrite(white,HIGH); digitalWrite(whiteled,HIGH); delay(1000); digitalWrite(white,LOW); digitalWrite(whiteled,LOW); } if(pixy.blocks[j].x>149 && pixy.blocks[j].x<171) { digitalWrite(white,HIGH); digitalWrite(whiteled,HIGH); digitalWrite(red,HIGH); digitalWrite(redled,HIGH); delay(1000); digitalWrite(white,LOW); digitalWrite(whiteled,LOW); digitalWrite(red,LOW); digitalWrite(redled,LOW); } } } }}

Motor Software

This sketch is loaded into the Arduino that has a motor shield on top.

Note that the "jump=1" moves to the second part of the program, where the robot chases the frog. The first part of the program is used to enable the robot to move around without getting stuck (a future enhancement--coming soon).

int val=0;
int val1=0; int valm=0; int valm1=0; int jump=1;

const int pwmA=3; const int pwmB=11; const int brakeA=9; const int brakeB=8; const int dirA=12; const int dirB=13; const int right=5; const int left=7;

void setup() { pinMode(dirA, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(dirB, OUTPUT); pinMode(brakeB, OUTPUT); pinMode(right,INPUT); pinMode(left,INPUT); digitalWrite(dirA, HIGH);//forward A digitalWrite(brakeA,LOW);//release brakeA analogWrite(pwmA,100);//set speed A digitalWrite(dirB,HIGH);//forward B motor digitalWrite(brakeB,LOW);// analogWrite(pwmB,100);//set speed B delay(700);

}

void loop () { if (jump==0) { valm=analogRead(0); valm1=analogRead(1); if(valm>500 or valm1>500) { valm=analogRead(0); valm1=analogRead(1); if(valm>450 or valm1>450) { digitalWrite(brakeA, HIGH); digitalWrite(brakeB, HIGH); digitalWrite(dirA, LOW);//reverse A digitalWrite(brakeA, LOW);// analogWrite(pwmA, 200); digitalWrite(dirB,LOW); digitalWrite(brakeB,LOW); analogWrite(pwmB,200); delay(700);//backup digitalWrite(brakeA,HIGH);//stop one wheel analogWrite(pwmA,0); delay(1000); digitalWrite(brakeB,HIGH);//stop other wheel //start both wheels forward digitalWrite(dirA,HIGH); digitalWrite(brakeA,LOW); analogWrite(pwmA,140); digitalWrite(dirB,HIGH); digitalWrite(brakeB,LOW); analogWrite(pwmB,140); delay(1000); }}} //jump equal one analogWrite(pwmA,0); analogWrite(pwmB,0); val=digitalRead(right); val1=digitalRead(left); if (val==HIGH && val1==HIGH) { analogWrite(pwmA,140); analogWrite(pwmB,140); delay(1000); } if (val==HIGH &&val1==LOW) { analogWrite(pwmA, 140); analogWrite(pwmB,50); delay(1000); } if (val1==HIGH && val==LOW) { analogWrite(pwmB,140); analogWrite(pwmA,50); delay(1000); }

}

mikey81.jpg

I hope to enable Mikey to come out on command, run around and do things, then return (on his own) to recharge.

Having Pixy vision should simplify all these tasks.


I've changed the Pixy part of the software slightly so that time is not wasted reading empty blocks. Also, I've included the Arduino files for both Pixy and the motor shield.