Difference between revisions of "Explore.py"

From IPRE Wiki
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<nowiki>
+
<nowiki>
from myro import *;
+
from myro import *
  
 
"""
 
"""
 
   This program causes the robot to "explore" the room.  The robot starts moving forward, and when it
 
   This program causes the robot to "explore" the room.  The robot starts moving forward, and when it
 
   hits a wall (i.e., it stalls) it stops, backs up a bit, turns a bit, then continues moving forward.
 
   hits a wall (i.e., it stalls) it stops, backs up a bit, turns a bit, then continues moving forward.
   The program stops when a key is pressed or 1 minute is up, whichever occurs first.
+
   The program stops when 1 minute is up.
 
    
 
    
 
   @author Douglas Harms  
 
   @author Douglas Harms  
 
  """
 
  """
  
initialize( "/dev/rfcomm1")
+
initialize( )
  
 
#start moving forward
 
#start moving forward
forward( 0.7 );
+
forward( 0.7 )
 
   
 
   
# keep executing for 1 minute or until a key is pressed
+
# keep executing for 1 minute
startTime = currentTime();
+
startTime = currentTime()
endTime = startTime + 60*1000;
+
endTime = startTime + 60*1000
 
while currentTimeMillis() < endTime:
 
while currentTimeMillis() < endTime:
            if getStall():  
+
    if getStall():  
                #we must have hit something so stop, backup a bit, turn, and continue
+
        #we must have hit something so stop, backup a bit, turn, and continue
                stop()
+
        stop()
                backward( 0.4, 1.0 )
+
        backward( 0.4, 1.0 )
                turnLeft( 0.5, 0.75 )
+
        turnLeft( 0.5, 0.75 )
                forward( 0.7 )
+
        forward( 0.7 )
 
          
 
          
 
  #stop the robot and close
 
  #stop the robot and close
 
  stop()  
 
  stop()  
</nowiki>
+
</nowiki>

Latest revision as of 18:53, 7 March 2011

from myro import *

"""
  This program causes the robot to "explore" the room.  The robot starts moving forward, and when it
  hits a wall (i.e., it stalls) it stops, backs up a bit, turns a bit, then continues moving forward.
  The program stops when 1 minute is up.
  
  @author Douglas Harms 
 """

initialize( )

#start moving forward
forward( 0.7 )
 
# keep executing for 1 minute
startTime = currentTime()
endTime = startTime + 60*1000
while currentTimeMillis() < endTime:
    if getStall(): 
        #we must have hit something so stop, backup a bit, turn, and continue
        stop()
        backward( 0.4, 1.0 )
        turnLeft( 0.5, 0.75 )
        forward( 0.7 )
        
 #stop the robot and close
 stop()