160 likes | 289 Views
Projects 3&4: PyRobot & Picobot. Arindam Paul – Project 3 Ning Xia – Project 4. 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.
E N D
Projects 3&4:PyRobot & Picobot Arindam Paul – Project 3 Ning Xia – Project 4
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 Robot control continuously runsthree things: whileTrue: ACT SENSE PLAN [x,y,thd], bump = self.getData() if bump[0] == Trueor 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
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)
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!
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!
Project 3: PyRobot One way to traverse the space is GO DOWN UNTIL BUMP SOMETHING, GO LEFT A LITTLE GO 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 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 1 10 Nxxx -> S 2 20 xExx -> W 3
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]]
Project 4: Picobot • Creating squares…. #Exit button 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)
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…
Project 4: Picobot • Reading in directions from a text file 0 xxxx -> N 1 10 Nxxx -> S 2 20 xExx -> W 3
Project 4: Picobot • Reading in directions from text file 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 1 10 Nxxx -> S 2 20 xExx -> W 3