Support Forums
Coding a robot with a GP2Y0A02YK sharp infrared range finding sensor [Picaxe Board] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Life Support (https://www.supportforums.net/forumdisplay.php?fid=12)
+---- Forum: Omni's Secret Hidden Inside Tricks (https://www.supportforums.net/forumdisplay.php?fid=13)
+---- Thread: Coding a robot with a GP2Y0A02YK sharp infrared range finding sensor [Picaxe Board] (/showthread.php?tid=16455)



Coding a robot with a GP2Y0A02YK sharp infrared range finding sensor [Picaxe Board] - Tate - 02-25-2011

I'm going to be coding a robot that will seek adventure. I've recently gotten into robotics, and this should be a fairly simple task. The GP2Y0A02YK range finder will send off an infrared light and look for it's reflection. It then calculates the time it takes to see a reflection and finds the distance my robot is from an object. I will then use a programming language called Picaxe to control my circuit board so that when it gets within a few feet of an object, it will look left and log the distance from the next object in sight, and then look right and do the same. It will then turn itself and go towards the area where the next object is the farthest away.

I'm going to be using a Picaxe project board, which will allow me to manuever everything with a microproccessor which I can code to with picaxe. I already have a cable for coding with Picaxe from a past project.

Here's a picture of the Picaxe project board which can be bought for $20 online:
[Image: 28510-dscn1098_ps.jpg]

For only $14.50, here's the sensor I'm using:
[Image: R144-GP2Y0A02YK.jpg]

If you want to do your own, here's a Picaxe source. This was originally intended to just turn itself around and randomly move in another direction when in contact with an object, but I modified it do do what I needed.

You're going to need to learn a little picaxe before understanding it. It's not really too similar to any popular languages. I would compare it to visual basic more than anything else (due to it's horrifying [yet popular] syntax).

Picaxe Code:
PHP Code:
Symbol dangerlevel 70
symbol turn 
300
symbol servo_turn 
700 

main
:
readadc 0b1
if b1 dangerlevel then
gosub nodanger 
else 
gosub whichway
end 
if
goto 
main 


nodanger
:
high 5 high 6 low 4 low 7
return


whichway:
gosub totalhalt


gosub lturn 
pause servo_turn
readadc 0
b1
gosub totalhalt



gosub rturn 
pause servo_turn
readadc 0
b2
gosub totalhalt

if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end 
if
return

body_lturn:
high 6 low 5 low 7 high 4
pause turn 
gosub totalhalt
return

body_rturn:
high 5 low 6 low 4 high 7
pause turn 
gosub totalhalt
return

rturn:
server 0,100
return

lturn:
servo 0200 
return

totalhalt:
low 4 low 5 low 6 low 7
Servo 0
,150 
wait 1 
return 



RE: Coding a robot with a GP2Y0A02YK sharp infrared range finding sensor [Picaxe Board] - Omniscient - 02-25-2011

http://www.rev-ed.co.uk/picaxe/

Some interesting stuff to read about.


RE: Coding a robot with a GP2Y0A02YK sharp infrared range finding sensor [Picaxe Board] - Tate - 02-26-2011

(02-25-2011, 11:49 PM)Omniscient Wrote: http://www.rev-ed.co.uk/picaxe/

Some interesting stuff to read about.

Indeed. Particularly here: http://www.techsupplies.co.uk/AXE020

And Picaxe Information->Basic Commands.