projects 3&4: pyrobot & picobot
DESCRIPTION
Projects 3&4: PyRobot & Picobot. Project 3: PyRobot. Pt A. 2d Roomba simulator. Goal: get from Pt A to Pt B. Pt B. Project 3: PyRobot. IMPORTANT: ROBOT CAN START ANYWHERE!. Pt A. Pt B. IMPORTANT: GOAL CAN BE ANYWHERE. Project 3: PyRobot. - PowerPoint PPT PresentationTRANSCRIPT
Projects 3&4:PyRobot & Picobot
Project 3: PyRobot
Goal: get from Pt A to Pt B
2d Roomba simulator
Pt B
Pt A
Project 3: PyRobot
Pt B
Pt A IMPORTANT:ROBOT CAN START ANYWHERE!
IMPORTANT:GOAL CAN BE ANYWHERE
Robot control continuously runs three things:
SENSE PLAN
[x,y,thd], bump = self.getData()
if bump[0] == True or bump[1] == True: print 'BUMP!', print ' [Left bump sensor:', bump[0], '] ', print ' [Right bump sensor:', bump[1], '] ' robotTask = STOP
STOP is one of the robot's states. Every 40th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep!
while True:
Project 3: PyRobot
ACT
if robotTask == STOP: self.setVels(0,0) robotTask = KBD
BASIC ROBOT COMMANDS:STOP:self.setVels(0,0)
GO FORWARD:self.setVels(FV,0)
GO BACKWARD:self.setVels(-FV,0)
GO CLOCKWISE:self.setVels(0,RV)
GO COUNTERCLOCKWISE:self.setVels(0,-RV)
Project 3: PyRobot
Project 3: PyRobotTo make the robot go forward a set amount useThe max forward velocity: FVExample...
TIME_ONE_CIRCLE_OVER = RADIUS*2 / FV
if state==GO_LEFT_LITTLE:#FIGURE OUT HOW TO TRAVELpause_stop = time.time() + TIME_ONE_CIRCLE_OVERState = NOW_GOING_LEFT_LITTLE
if pause_stop > time.time() and state==NOW_GOING_LEFT_LITTLE:self.setVels(0,0) #STOP!
elif state==NOW_GOING_LEFT_LITTLE:self.setVels(0,FV) #KEEP GOING!
To rotate the robot use the Max Rotational Velocity: RV
Example...
TIME_ROTATE_90_DEGREES = 90.0 / RV
if state==ROTATE_LEFT_DOWN:#FIGURE OUT HOW LONG TO ROTATEpause_stop = time.time() + TIME_ROTATE_90_DEGREESState = NOW_ROTATING_DOWN
if pause_stop > time.time() and state==NOW_ROTATING_DOWN:self.setVels(0,0) #STOP!
elif state==NOW_ROTATING_DOWN:self.setVels(0,-RV) #KEEP GOING!
Project 3: PyRobot
One way to traverse the space isGO DOWN UNTIL BUMP SOMETHING,GO LEFT A LITTLEGO UP UNTIL BUMP SOMETHINGGO RIGHT A LITTLE
DO THIS UNTIL HIT CORNER THEN REVERSE....
Project 3: PyRobot
Required
We may test on any map with rectangular objects
Project 3: PyRobot
Project 4: Picobot
Your goal is to….
1) Create a maze with
Go and Stop buttons
2) Read in commands that will guide the robot through the maze
0 xxxx -> N 1 10 Nxxx -> S 2 20 xExx -> W 3
Creating a maze
Project 4: Picobot
X = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,0,1],[1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1],[1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1],[1,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1],[1,0,1,1,1,0,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,1],[1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,0,1,0,0,0,1],[1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,0,1,1,1],[1,1,0,1,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1],[1,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1],[1,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,1,1,0,1],[1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0,0,0,0,1],[1,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,1,1,1,0,1,0,1],[1,0,1,1,1,1,1,1,0,1,0,0,1,1,1,0,1,0,0,0,1,0,1,0,1],[1,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,1,1,1,0,1,0,1,0,1],[1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,1,0,1,0,1,0,1],[1,0,0,0,0,1,0,0,0,1,1,1,0,1,1,1,1,0,1,0,1,0,1,0,1],[1,0,1,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,1,1,0,1],[1,0,0,1,0,1,0,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1],[1,0,1,1,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,1],[1,0,1,0,0,1,0,1,0,0,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1],[1,0,1,1,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1],[1,0,0,0,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,1,0,0,0,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
Your program should read maze description from a file. If you mark blue by 1, and white by 0, then the maze could be represented as a 2D list:
Creating squares….
Project 4: Picobot
#square in mazewin = GraphWin("MyWindow",
400, 400)p1 = Point(0,355)p2 = Point(400,400)square5 = Rectangle(p1,p2)square5.setFill(“blue")square5.setOutline(“blue")square5.draw(win)
#Exit buttonp1 = Point(122,360)p2 = Point(198,390)square1 =
Rectangle(p1,p2)square1.setFill("gray")square1.draw(win)p = square1.getCenter()t = Text(p, "Exit")t.draw(win)
Project 4: Picobot
Figuring out when user clicks on a “button” K = win.getMouse()
GoStop = 0
if K.getX() > LEFT_X and K.getX() < RIGHT_X and K.getY() > TOP_Y and K.getY() < BOTTOM_Y: GoStop = 1
Project 4: Picobot
Remember to have the trail…
Reading in directions from a text file
Project 4: Picobot
0 xxxx -> N 1 10 Nxxx -> S 2 20 xExx -> W 3
Reading in directions from text file
Project 4: Picobot
f = open('map3.txt', 'r')#read in all commandstext = f.read()#split all commandsL = text.split()f.close()#everytime you get to an arrow grab the statefor i in range(len(L)): if L[i] == '->':
if L[i-1] == 'xxxx':
Map3.txt…0 xxxx -> N 1 10 Nxxx -> S 2 20 xExx -> W 3