28.01.2013 Views

Build Your Own Combat Robot

Build Your Own Combat Robot

Build Your Own Combat Robot

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

296 <strong>Build</strong> <strong>Your</strong> <strong>Own</strong> <strong>Combat</strong> <strong>Robot</strong><br />

b2 = b0 + b1 'to turn. If both detectors return<br />

if b2 < 5 then main 'equal values, then go straight,<br />

if b0 < b1 then left 'otherwise turn in the direction that<br />

if b1 < b0 then right 'had the stronger return probability.<br />

goto main 'i.e. a lower hit number.<br />

left: 'Make a small left turn move<br />

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

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

pause 15 'Pause for 15 ms. This delay sets up<br />

goto main 'the ~50 Hz servo update frequency<br />

right: 'Make a small right turn move<br />

pulsout 0, 100<br />

pulsout 1, 100<br />

pause 15<br />

goto main<br />

Rturn: 'This is the Right Turn Routine.<br />

gosub back 'Call the back up routine.<br />

for b2 = 1 to 30 'This loop determines how much the<br />

pulsout 0, 100 'mini sumo turns. Increasing the<br />

pulsout 1, 100 'loop value (30) causes the mini<br />

pause 15 'sumo to turn more to the right,<br />

next 'decreasing this value decreases<br />

goto main 'the amount the mini sumo turns.<br />

Lturn: 'This is the Left Turn Routine.<br />

gosub back<br />

for b2 = 1 to 30<br />

pulsout 0, 200<br />

pulsout 1, 200<br />

pause 15<br />

next<br />

goto main<br />

back: 'This is the back up routine<br />

for b2 = 1 to 25 'This loop determines how far the mini<br />

pulsout 0, 200 'sumo will back up. Increasing the<br />

pulsout 1, 100 'loop value (25) will increase the<br />

pause 15 'overall distance. Decreasing the<br />

next 'value will cause the mini sumo to<br />

return 'back up less.

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

Saved successfully!

Ooh no, something went wrong!