Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Robots Programming Notes:. Programming Robots Programming a Timed Event Suppose we want a behaviour like the default behaviour to go on but.

Similar presentations


Presentation on theme: "Programming Robots Programming Notes:. Programming Robots Programming a Timed Event Suppose we want a behaviour like the default behaviour to go on but."— Presentation transcript:

1 Programming Robots Programming Notes:

2 Programming Robots Programming a Timed Event Suppose we want a behaviour like the default behaviour to go on but never for a prolonged period of time. Suppose we want the default behaviour to never last longer than three seconds without a change. For example, if we want the robot to run around, responding to obstacles and light by changing direction but we don't want the robot to wander off if there are no light or obstacle stimuli.

3 Programming Robots Example Program the robot to stay within an imaginary 4 foot box, all the while responding to light and obstacle stimuli.

4 Programming Robots What is Needed? We need to write our own timeRemaining() mechanism. import time class Template (MyScribbler): def __init__(self,port,t=0,r=0): MyScribbler.__init__(self,port,t,r)‏ # add additional behaviours here for this program only self.masterMethodsList['myBehaviour'] = self.myBehaviour self.masterMethodsList['dflt'] = self.dflt self.timeRemaining = -1 self.timeOut = 3 self.startTime = time.time()‏

5 Programming Robots What is Needed? We need to write our own “timeRemaining” mechanism. def dflt(self): if self.timeRemaining < 0: self.startTime = time.time() self.timeRemaining = self.timeOut elif self.timeRemaining >= 0: now = time.time()‏ self.timeRemaining -= (now-self.starttime)‏ if self.timeRemaining <= 0: self.timeRemaining = -1 return [True, self.T,self.R, doWierd] return [True,self.T,self.R,self.move]

6 Programming Robots What is Needed? We need to write our own “timeRemaining” mechanism into any given behaviour. def myBehaviour(self): if self.timeRemaining < 0: self.startTime = time.time() self.timeRemaining = self.timeOut elif self.timeRemaining >= 0: now = time.time()‏ self.timeRemaining -= (now-self.starttime)‏ if self.timeRemaining <= 0: self.timeRemaining = -1 return [True, self.T,self.R, doBehaviour] return [False,self.T,self.R,self.move]

7 Programming Robots Example: Write a program using the above dflt() method to keep the robot from going more than 4 feet in a straight line. Have the robot respond to light and obstacle sensory data by changing direction. Adjust self.timeOut appropriately

8 Programming Robots A Second Example: Have the robot back away from intense light. It will go straight back if the light is on the center sensor; veer right if the light is on the left sensor and veer left if the light is on the right sensor.

9 Programming Robots Game: Two people with flashlights try to push the robot across the far line by using their flashlights only. The robot will go backward whenever the light is shining on the center sensor. The robot will move forward slowly/quickly by dflt.


Download ppt "Programming Robots Programming Notes:. Programming Robots Programming a Timed Event Suppose we want a behaviour like the default behaviour to go on but."

Similar presentations


Ads by Google