Let's Make Robots!

CatScan Robot [altered SHR]

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MM0TAI's picture

i promise not to laugh.....honest :)

Voltar's picture

OK, since you promised then here it is.  It's the first PICAXE program I have ever written, plus I'm not a programmer so I realize that most of you could have written this whole program in, like; ten lines of code.

==============================================================

' Voltar July2011

' CatScan code for SHR.  Make the SHR wait for a cat, then chase it

 

'control RIGHT Wheel FORWARD A and BACKWARD A 

'control LEFT Wheel FORWARD B and BACKWARD B 

 

' servo 0 150 is CENTER

' servo 100    is RIGHT

' servo 200   is LEFT

 

'Sharp IR: Reading gets higher as wall gets closer

' 150 at 8  inches

'  75 at 16.inches 

'  45 at 24 inches and farther

 

'Variable Define

Symbol Too_Close = 150 ' If > than this, we found a cat.

Symbol Turn_Amount = 700 ' how much bot is turned

Symbol Servo_Delay = 700 ' delay for the servo to turn

 

servo 0, 150 'intit the servo the straight ahead

 

main: 'Scanner area

low 4 : low 5 : low 6 : low 7 'stop the robot. Decide direction

 

servopos 0, 150 

pause Servo_Delay

 

Do until b1 => Too_Close 'Cat seen? If yes, exit loop

readadc 0, b1

loop

 

servopos 0, 200    'This 

pause Servo_Delay  'just

servopos 0,100      'wiggles

pause Servo_Delay  'the servo to allow the cat to move

pause Servo_Delay  'Cats love this part of the routine….

 

servopos 0, 150 

pause Servo_Delay

 

servopos 0, 200

pause Servo_Delay

readadc 0, b0 ' read LEFT distance into b0

 

servopos 0, 150 

pause Servo_Delay 

readadc 0, b1 ' read CENTER distance into b1

 

servopos 0, 100

pause Servo_Delay

readadc 0, b2 ' read RIGHT distance into b2

 

 

'Largest b value points to cat. Move that way

if b0 => b1 then 

b1 = 0

else

b0 = 0

end if

if b0 => b2 then 

b2 = 0

else

b0 = 0

end if

 

if b1 => b2 then

b2 = 0

end if

 

servopos 0, 150

 

if b0 <> 0 then 'cat on left

forward a

pause Turn_Amount

for b3 = 1 to 3 'move forward

forward a 'RIGHT Wheel

forward b 'LEFT Wheel

pause Turn_Amount

next b3

end if

 

if b1 <> 0 then 'cat center

for b3 = 1 to 3 'move forward

forward a

forward b

pause Turn_Amount

next b3

end if

 

if b2 <> 0 then 'cat right

forward b

pause Turn_Amount

for b3 = 1 to 3 'move forward

forward a

forward b

pause Turn_Amount

next b3

end if

 

goto main

MM0TAI's picture

cool little bot, what alterations did you make to the shr code or did you write your own?

Voltar's picture

I wrote the code from scratch.  I'll post it if everyone promises not to laugh at it.  Ha!