MainProgram: gosub DrawEnvironment for i=1 to 10 // perform 10 iterations gosub InitRobot gosub GoThroughDoor next end DrawEnvironment: // draw walls LineWidth 2 Rectangle 200,290,350,310,black,gray Rectangle 420,290,600,310,black,gray Return InitRobot: rLocate 225+random(11),345+random(11),-5+random(11) rInvisible GREEN rPen DOWN rSlip 10 // %error Return // Program for Servo Article on programming sensors (Nov. 2016) // Download RobotBASIC to run this program (RobotBASIC.org) // experiment with the modifications discussed in the article GoThroughDoor: gosub FindDoor gosub PassThrough Return FindDoor: rTurn 90 dist = rRange(-90) // follow wall to doorway repeat if rRange(-90)dist then rTurn -1 rForward 1 until rRange(-80)>10+dist rForward 60 Return PassThrough: rTurn -90 while (rFeel()&17)!=17 rForward 1 if rFeel()&8 then rTurn 1 if rFeel()&2 then rTurn -1 wend rForward 50 // draw a circle to show where the robot stops // only needed when multiple iterations are used rGPS x,y linewidth 3 setcolor green circle x-18,y-18,x+18,y+18 Return