Presentation is loading. Please wait.

Presentation is loading. Please wait.

Projects 3&4: PyRobot & Picobot

Similar presentations


Presentation on theme: "Projects 3&4: PyRobot & Picobot"— Presentation transcript:

1 Projects 3&4: PyRobot & Picobot

2 Goal: get from Pt A to Pt B
Project 3: PyRobot Pt A 2d Roomba simulator Goal: get from Pt A to Pt B Pt B

3 Project 3: PyRobot IMPORTANT: ROBOT CAN START ANYWHERE! IMPORTANT:
Pt A IMPORTANT: ROBOT CAN START ANYWHERE! Pt B IMPORTANT: GOAL CAN BE ANYWHERE

4 Robot control continuously runs three things:
Project 3: PyRobot while True: Robot control continuously runs three things: SENSE PLAN ACT [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! if robotTask == STOP: self.setVels(0,0) robotTask = KBD

5 Project 3: PyRobot 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)

6 Project 3: PyRobot To make the robot go forward a set amount use
The max forward velocity: FV Example... TIME_ONE_CIRCLE_OVER = RADIUS*2 / FV if state==GO_LEFT_LITTLE: #FIGURE OUT HOW TO TRAVEL pause_stop = time.time() + TIME_ONE_CIRCLE_OVER State = 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!

7 Project 3: PyRobot 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 ROTATE pause_stop = time.time() + TIME_ROTATE_90_DEGREES State = 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!

8 Project 3: PyRobot One way to traverse the space is
GO DOWN UNTIL BUMP SOMETHING, GO LEFT A LITTLE GO UP UNTIL BUMP SOMETHING GO RIGHT A LITTLE DO THIS UNTIL HIT CORNER THEN REVERSE....

9 Project 3: PyRobot Required
We may test on any map with rectangular objects

10 Project 4: Picobot Your goal is to…. Create a maze with
Go and Stop buttons 2) Read in commands that will guide the robot through the maze 0 xxxx -> N Nxxx -> S 2 20 xExx -> W 3

11 Project 4: Picobot Creating a maze
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: 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]]

12 Project 4: Picobot Creating squares…. #Exit button #square in maze
p1 = 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) #square in maze win = 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)

13 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

14 Project 4: Picobot Remember to have the trail…

15 Project 4: Picobot Reading in directions from a text file
0 xxxx -> N Nxxx -> S 2 20 xExx -> W 3

16 Project 4: Picobot Reading in directions from text file Map3.txt…
f = open('map3.txt', 'r') #read in all commands text = f.read() #split all commands L = text.split() f.close() #everytime you get to an arrow grab the state for i in range(len(L)): if L[i] == '->': if L[i-1] == 'xxxx': Map3.txt… 0 xxxx -> N Nxxx -> S 2 20 xExx -> W 3


Download ppt "Projects 3&4: PyRobot & Picobot"

Similar presentations


Ads by Google