Basic Stamp 2 Robot Programming - ISL
Basic Stamp 2 Robot Programming - ISL
Basic Stamp 2 Robot Programming - ISL
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Basic</strong> <strong>Stamp</strong> 2 <strong>Robot</strong> <strong>Programming</strong> 6-25<br />
‘ Copyright (C) 2001 McGraw-Hill<br />
‘<br />
‘ { $STAMP BS2 }<br />
‘ Variables<br />
Flag var bit ‘ One “Ouch” Per Collision (0)<br />
‘ Mainline<br />
high SC<br />
‘ Set the I/O Bits As O/P<br />
high SD ‘ and High<br />
pause 100<br />
‘ Stop the <strong>Robot</strong> from Running<br />
<strong>Robot</strong>Data = <strong>Robot</strong>Stop ‘ (1)<br />
gosub <strong>Robot</strong>Send<br />
OuchlessLoop: ‘ (2)<br />
Flag = 0<br />
Loop: ‘ Repeat Here Forever (3)<br />
pause 500<br />
‘ Poll Once Every 1/2 Second<br />
<strong>Robot</strong>Data = <strong>Robot</strong>Whiskers ‘ Read the <strong>Robot</strong> Whiskers<br />
gosub <strong>Robot</strong>SendReceive<br />
if (<strong>Robot</strong>Data = 0) then OuchlessLoop ‘ (4)<br />
‘ Collision<br />
<strong>Robot</strong>Data = <strong>Robot</strong>LEDOn ‘ Flash LED (5)<br />
gosub <strong>Robot</strong>Send<br />
Pause 500<br />
<strong>Robot</strong>Data = <strong>Robot</strong>LEDOff<br />
gosub <strong>Robot</strong>Send<br />
if (Flag = 1) then Loop ‘ Don’t Print “Ouch” Twice (6)<br />
Flag = 1 ‘ Indicate “Ouch” Output (7)<br />
debug “Ouch! Something Hit Me”, cr<br />
goto Loop ‘ (8)<br />
‘ <strong>Robot</strong> Interface Code Follows:<br />
‘<br />
‘ Myke Predko<br />
‘<br />
‘ Copyright (C) 2001 McGraw-Hill<br />
‘<br />
‘ <strong>Robot</strong> Commands<br />
<strong>Robot</strong>Stop con 0 ‘ Stop the <strong>Robot</strong><br />
Behavior1 con 1 ‘ Random Movement<br />
Behavior2 con 2 ‘ Photovore<br />
Behavior3 con 3 ‘ Photophobe<br />
Behavior4 con 4 ‘ Wall Hugger/Maze Solver<br />
<strong>Robot</strong>Forward con 5<br />
‘ Move Forward for 200 msec<br />
<strong>Robot</strong>Reverse con 6<br />
‘ Move Reverse for 200 msec<br />
<strong>Robot</strong>Left con 7 ‘ Turn Left for 200 msec<br />
<strong>Robot</strong>Right con 8 ‘ Turn Right for 200 msec