28.01.2013 Views

Build Your Own Combat Robot

Build Your Own Combat Robot

Build Your Own Combat Robot

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

'again. If the mini sumo sees an object in front of it, it will turn towards<br />

'the object.<br />

'pin0 = Right Servo These pin(s) are I/O pins, not<br />

'pin1 = Left Servo physical pins on the Stamp 1<br />

'pin2 = Right Edge Detector<br />

'pin3 = Left Edge Detector<br />

'pin5 = Left Opponent Detector LED<br />

'pin6 = Right Opponent Detector LED<br />

'pin7 = IR Receiver Sensor<br />

dirs=%01100011 'Initialize the I/O pin directions pin0, pin1,<br />

' pin5, pin6 are outputs<br />

pause 5000 'Pause 5000 ms (or 5 seconds)<br />

main: 'Main Program Loop<br />

if pin2 = 0 then Lturn 'Check right edge detector, if the detector sees the<br />

' white line, then goto the left turn routine.<br />

if pin3 = 0 then rturn 'Check right edge detector, if the detector sees the<br />

goto main<br />

' white line, then goto the right turn routine.<br />

pulsout 0,100 'Send a 1 ms pulse to the right servo<br />

pulsout 1,200 'Send a 2 ms pulse to the left servo<br />

b0 = 0 'Sample the left object detector for<br />

for b2 = 1 to 5 '5 times by toggling the IR LED on/off<br />

pin5 = 1 'The output pin will be high if there<br />

pin5 = 0 'is no reflected signal. If b0 (or b1)<br />

b0 = b0 + pin7 'is less than 3 then over 50% of the<br />

next 'signals returned back to the receiver.<br />

'This gives a good indication that<br />

pulsout 0, 100 'an object was detected, and a<br />

pulsout 1, 200 'less chance that the signals were<br />

b1 = 0 'random noise or false signals<br />

for b2 = 1 to 5<br />

pin6 = 1<br />

pin6 = 0<br />

b1 = b1 + pin7<br />

next<br />

if b0 < 3 then turn 'If a positive object detection was obtained, then<br />

if b1 < 3 then turn 'goto the turn routine<br />

turn: 'This routine determines which direction<br />

Chapter 13: <strong>Robot</strong> Sumo 295

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!