Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Robots Musical Chairs. Programming Robots The Game: Version 1:  Wander around the corral until a bright light shines.  Upon seeing the bright.

Similar presentations


Presentation on theme: "Programming Robots Musical Chairs. Programming Robots The Game: Version 1:  Wander around the corral until a bright light shines.  Upon seeing the bright."— Presentation transcript:

1 Programming Robots Musical Chairs

2 Programming Robots The Game: Version 1:  Wander around the corral until a bright light shines.  Upon seeing the bright light move towards that light  In front of the light there will be a black line on the floor; stop when you cross the black line

3 Programming Robots Musical Chairs: Version 2 Like before, you wander aimlessly within the corral. Avoid obstacles and back away if you stall against anything. Ignore light until a distinctly bright light shines. When the bright light shines move towards it until you cross the black line. In this version you will notify other robots who are doing the same thing that you have crossed the black line. The last robot left who has not yet crossed the black line is the loser of the game and should print out “I Lost”; other robots should print out “I Won” when they cross the black line.

4 Programming Robots Chatting with other robots # add yourself to chat chat = Chat(myName+'@joyous.cs.newpaltz.edu',myName)‏myName+'@joyous.cs.newpaltz.edu # get other participant names name = raw_input('Other Participants: '); while name != 'DONE': mc.addToPlayerList(name.lower())‏ maxRobotCount = maxRobotCount + 1 name = raw_input('Other Participants (DONE to finish): '); # if you cross the black line tell everyone you did. L= self.getLine()‏ if L[0] == 1 or L[1] == 1: for p in self.playerList: self.myChat.send(p,'Done')‏ print 'I won'

5 Programming Robots Issues: This program must be threaded. This is because the robot needs to wander around doing its thing while the main program waits for a chat message to arrive. # robot sets mc.STOP when it has crossed the black line messages = chat.receive()‏ while len(messages) == 0 or mc.STOP != 0: time.sleep(1)‏ messages = chat.receive()‏ if len(messages) > 0 : print messages

6 Programming Robots Main program: Create a robot that extends MyScribbler and threading.Thread (Remember you must implement the run() method now)‏ Get a list of other players Connect to chat Start your thread Wait for messages and as they arrive increment a counter that allows the robot to see if it is the last to cross the line Terminate when the robot has stopped running; either because it crossed the line or because it is the only robot not to cross the line.

7 Programming Robots The Robot: How to make our normal robot object run in a separate thread. From threading import Thread class MCRobot (MyScribbler,Thread):... def run(self): self.main(120)‏

8 Programming Robots Methods Needed: checkLine: checks if you crossed the black line; sends out messages to other players and stops the robot and its thread; fails otherwise checkLight: checks if light has suddenly gotten brighter; if so, directs robot to get closer to the light; fails otherwise checkMsgs: Determines if you have received n-1 messages where n is the number of participating robots (including yourself). Fails unless you are the last robot, in which case it succeeds and directs you to a “terminating” method. checkStall: checks if you are stalled; if so reverses the direction of the robot. checkObstacle: checks if obstacle in view; if so, alters course.

9 Programming Robots Methods Needed: dflt: This method sets a random behaviour that will run for a few seconds before being replaced by another random behaviour. We can keep track of how long to implement a specific behaviour by having this method change the behaviour only once every 10 (for example) times it is called. def dflt(self): if self.count < 10: self.count = self.count + 1 else: self.count = 0 self.T = random.random()*random.choice([-1,1])‏ self.R = random.random()*random.choice([-1,1])‏ return [True,self.T,self.R,self.move]

10 Programming Robots Strategy: As long as the light is more or less ambient you should:  Ignore any black lines  Keep your eye open for a light change  Avoid obstacles  Back away from something you have hit  Wander around randomly.  Watch for messages Once you notice the presence of a bright light you should:  Ignore everything but the bright light source  Keep your eye open for the black line  Continue to watch for messages


Download ppt "Programming Robots Musical Chairs. Programming Robots The Game: Version 1:  Wander around the corral until a bright light shines.  Upon seeing the bright."

Similar presentations


Ads by Google