Sie sind auf Seite 1von 3

Lesson 5-6

Taking the # off of one of these phrases, lets me run that program. This
is useful because I can run as many puzzles as I want without having to
run their separate code.
#from moveLightWorld import *
#from chasingLightWorld import *
#from obstacleWorld import *
#from wallWorld import *
from mazeWorldDrawn import *
#from mazeWorld import *
#Baseline follow Light behavior
def followLight():
while True:
left,center,right=myGetLight()
myMotors(center,center)
#Infrared Behaviors. Use with wallWorld, obstacleWorld, mazeWorld
def stopAtWall():
while True:
left,right = getIR()
if(left==1 or right==1):
myMotors(1,1)
else:
myMotors(0,0)
break;
#Example of getLine(). Use in mazeWorldDrawn
def stopDrawnWall():
penDown("orange")
while True:
left,right = getLine()
if(left==1 or right==1):
translate(random()) # robot backs up random amout
wait(random()) #see comment above
rotate(random()) #robot robots random amount
wait(random()) #see comment above
else:
myMotors(1,1)

This program allows my virtual robot to navigate a virtual maze by


itself. It can detect where the walls of the maze are in accordance with
the robot, and allows the robot to make turns efficiently. I used this
program previously when I made my maze.
def navigateDrawnWall():
penDown("red")
while True:
left,right = getLine()
if (left==0 and right==0):
backward(1,2)
elif (left==1):
myMotors(-1,-1)
rotate(1,1)
wait(0.5)
elif (right==1):
myMotors(-1,-1)
rotate(-1,-1)
wait(0.5)
elif (left==1 and right==1):
backward(1,2)
else:
myMotors(1,1)

This program makes it so my virtual robot stops when it sees a virtual


wall.
def stopAtDrawnWall():
while True:
left,right = getLine()
if(left==1 or right==1):
myMotors(1,1)
else:
myMotors(0,0)
break;
#Make a robot that can run from the light and not hit the wall
#Uncomment chasingLightWorld

Das könnte Ihnen auch gefallen