def entry(self):
     
     #Resets the variables since the last use of the state:
     
     #starting angle
     self.start_angle = imu.get_angle()[2]
     
     #Timers
     self.start_time=time.time()
     self.timer=self.start_time+self.time_between
     
     #Which direction it should start turning its head
     self.left_or_right=self.direction
     
     #Makes sure that the head hardness is correct and
     #stores the current head position
     robotbody.set_head_hardness(0.95)
     self.wanted_head_position=robotbody.get_head_position()
     
     #Initiates the turn in the right direction
     if self.direction=="left":
         walk.turn_left(0.2)
     else:
         walk.turn_right(0.2)
         
     #Sets a fancy blue eye colour
     robotbody.set_eyes_led(0, 0, 31)
         
     print("Tracking ball")
 def update(self): 
          
     #Tests if the robot has fallen
     if has_fallen():
         return "fallen"
     
     #Stores the if it has a new goal observation for further tests
     self.has_new_goal_observation=vision.has_new_goal_observation()
     
     #Stores the current head position for further tests
     self.current_head_position=robotbody.get_head_position()[0]
     
     self.current_time=time.time()
     
     #If the timer has run out or if the robot has failed to find a goal post
     #it leaves the state depending with a few commands.
     if self.fail_timer<=self.current_time or self.failing:
         
         #If it's not failing it knows that it have found at least one goal post
         #Then it will update the fail timer so that it has time enough to move
         #its head towards that direction
         if not self.failing:
             self.failing=True
             self.fail_timer=self.current_time+1
         
         #If the timer has run out it's time to leave the state
         if self.fail_timer<=self.current_time:
             if len(self.angles)==0:
                 robotbody.set_eyes_led(31, 0, 0)
                 print("fail")
                 return "fail"
             elif len(self.angles)==1:
                 robotbody.set_eyes_led(0, 31, 0)
                 return "focus one"
             else:
                 self.focus_middle()
                 robotbody.set_eyes_led(0, 31, 0)
                 print("focus middle")
                 return "focus middle"
             
         #If the timer hasn't run out it should focus on whatever it has found
         else:
             self.focus_on_results()
     else:
         
         #Tests if it is time to end with only one goal post found
         if self.ending and like(self.current_head_position,self.angles[0][0]):
             robotbody.set_eyes_led(0, 31, 0)
             return "focus one"
     
         #Tests if it has found two goal posts
         if len(self.angles)==2 and \
             like(self.current_head_position,(self.angles[0][0]+self.angles[1][0])/2):
             robotbody.set_eyes_led(0, 31, 0)
             print("focus middle")
             return "focus middle"
     
         #Updates the head position, variables, depending on how many goal post it has found
         if not self.ending and like(self.current_head_position,self.wanted_head_position[0],pi/45):
             self.update_values()
예제 #3
0
 def update(self):
     if has_fallen():
         return "fallen"
     
     if not vision.has_new_ball_observation():
         if self.last_observation_of_ball+5<time.time() or self.last_distance>=tan(5*pi/12):
             walk.set_velocity(self.speed, 0, 0)
             robotbody.set_eyes_led(31, 0, 0)
             print("lost ball")
             return "no ball"
     else:
         self.current_head_position = robotbody.get_head_position()
         if like(self.current_head_position,self.wanted_head_position):
             self.update_head_position()
        
             self.last_observation_of_ball=time.time()
             self.last_distance=distance_to_ball()
         
         if self.last_distance>0 and self.last_distance<self.distance:
             print ("standing in front of ball")
             return "done"
             
         if not like(self.current_head_position[0],0,pi/18):
             walk.set_velocity(self.speed, 0.4, self.current_head_position[0])
             
         else:
             walk.set_velocity(self.speed, 0, 0)
 def update(self):
     
     #Tests if the robot has fallen
     if has_fallen():
         return "fallen"
     
     #Stores the current time for tests and updates
     self.current_time=time.time()
     
     #Tests if the robot has lost the ball
     if self.has_lost_ball():
             print("lost ball")
             return "lost ball"
     
     #Test if the robot is standing in front of the ball
     self.distance_to_ball=distance_to_ball()
     if self.distance_to_ball>0 and self.distance_to_ball<self.distance:
         robotbody.set_eyes_led(0, 31, 0)
         print ("standing in front of ball")
         return "done"
     
     #Updates the position of the head
     self.update_head_position()
     
     #Updates the walking direction
     self.update_walk_direction()
 def has_lost_ball(self):
     if self.current_time>=self.lost_ball_timer:
         robotbody.set_eyes_led(31, 0, 0)
         return True
     
     if self.has_new_ball_observation:
         self.lost_ball_timer=self.current_time+7
     return False
 def entry (self):
     #Reset the variables since the last use of the state and
     #sets the eyes to a fancy red colour
     robotbody.set_eyes_led(31, 0, 0)
     self.sitting=False
     self.start_time=None
     
     #Starts the get up motion
     motion.get_up()
    def entry(self):
        #Sets the eyes to a fancy blue
        robotbody.set_eyes_led(0, 0, 31)

        #Starts walking forward with the given speed
        walk.walk_forward(self.speed)
        
        self.lost_ball_timer=time.time()+5
        
        print("See the robot walk")
 def has_lost_ball(self):
     if self.current_time>=self.lost_ball_timer:
         robotbody.set_eyes_led(31, 0, 0)
         return True
     
     elif vision.has_new_ball_observation():
         self.lost_ball_timer=self.current_time+5
         return False
     
     else:
         return False
 def update(self):
     #Tests if the robot has fallen
     if has_fallen():
         return "fallen"
     
     #Test if the last vision of a goal was the opponents
     if self.opponents_goal():
         robotbody.set_eyes_led(0, 31, 0)
         print("fire at opponents goal")
         return "fire"
     else:
         robotbody.set_eyes_led(0, 0, 31)
         print ("turning towards opponents goal")
         return "turn"
    def entry(self):
        #Sets the eyes to a fancy blue
        robotbody.set_eyes_led(0, 0, 31)

        #Starts walking forward with the given speed
        walk.walk_forward(self.speed)
        
        #Sets the head position down to the ground
        set_head_position([0,pi/8])
        
        #How long it will wait until it has concluded that it has lost the ball
        self.lost_ball_timer=time.time()+2
        
        print("See the robot walk")
예제 #11
0
 def update(self):
     
     self.update_head_position()
     
     if vision.has_new_ball_observation():
         walk.turn_left(0)
         robotbody.set_eyes_led(0, 31, 0)
         print("found ball")
         return "done"
     
     if imu.get_angle()[2] > self.start_angle + self.angle:
         walk.turn_left(0)
         robotbody.set_eyes_led(31,0,0)
         print ("can't find the ball")
         return "out of sight"
 def update(self):
     
     #Tests if it has found a ball observation
     if vision.has_new_ball_observation():
         walk.turn_left(0)
         robotbody.set_eyes_led(0, 31, 0)
         print("found ball")
         return "done"
     
     #Tests if it's time to stop turning and accept a failure
     if imu.get_angle()[2] > self.start_angle + self.angle:
         walk.turn_left(0)
         robotbody.set_eyes_led(31,0,0)
         print ("can't find the ball")
         return "out of sight"
     
     #Updates the head position
     self.update_head_position()
 def update(self):
     
     #Tests if the robot has fallen
     if has_fallen():
         return "fallen"
     
     #Stores the value if the robot has a new ball observation for further use
     self.has_new_ball_observation=vision.has_new_ball_observation()
     
     #Stores the current time for further tests
     self.current_time=time.time()
     
     #Tests if the robot has lost the ball
     if self.has_lost_ball():
             print("lost ball")
             return "lost ball"
     
     #Tests if it has finished moving,
     #if the robot already has decided that it had to move
     if self.timer and self.current_time>self.timer:
         robotbody.set_eyes_led(0, 0, 31)
         return "check again"
     
     #If the timer has not started yet.
     #The robot looks for the first ball observation.
     #If it finds one it starts the timer and stores the angles.
     if not self.timer:
         if self.has_new_ball_observation:
             self.start_timer()
     
     else:
         #If the difference between the goal angle and the first ball angle is less
         #then 20 degrees it will tell that it has lined up
         #Otherwise it will start to turn around the ball for some time,
         #depending on the difference
         if like(self.first_ball_angle,self.goal_angle,pi/9):
             robotbody.set_eyes_led(0, 31, 0)
             print("lined up")
             return "lined up"
         
         self.start_turning()
 def update(self):
     
     #Test if the robot has fallen
     if has_fallen():
         return "fallen"
     
     #Stores the current time for further tests
     self.current_time=time.time()
     
     #Stores whether it have found a new ball observation
     self.has_new_ball_observation=vision.has_new_ball_observation()
     
     self.has_new_goal_observation=vision.has_new_goal_observation()
     
     #Stores the current distance to the ball for further tests
     self.distance_to_ball=distance_to_ball()
     
     #Tests if it has lost the ball
     if self.has_lost_ball() or self.to_long_distance():
         print ("lost the ball")
         return "lost ball"
     
     #Test if it has found a goal post
     if self.has_new_goal_observation:
         if like(goal_angle()[0],0,self.alowed_angled_diff):
             robotbody.set_eyes_led(0, 31, 0)
             print("found goal")
             return "done"
     
     #Tests if it is time to abandon the search for a goal
     if self.current_time > self.start_time + self.time:
         robotbody.set_eyes_led(0, 0, 31)
         print("lucky shot")
         return "fail"
     
     #Updates the head position
     self.update_head_position()
     
     #Updates the walking speed for the robot
     self.update_speed()
    def update(self):
        
        #Tests if it has fallen
        if has_fallen():
            return "fallen"
        
        #Stores current time
        self.current_time=time.time()
        
        #Stores whether it has found a new ball observation
        self.has_new_ball_observation=vision.has_new_ball_observation()
        
        #Stores whether it has found a new goal observation
        self.has_new_goal_observation=vision.has_new_goal_observation()
        
        #Stores the distance to the ball
        self.distance_to_ball=distance_to_ball()
        
        #Stores the new angle and type if it has new observation of the goal
        if self.has_new_goal_observation:
            self.goal_angle,self.goal_type=goal_angle_and_type()
        
        #Tests if it has lost the ball
        if self.has_lost_ball() or self.to_long_distance():
            print ("lost the ball")
            return "lost ball"
        
        #Tests the adjustment timer
        if self.adjustment_timer and self.current_time>=self.adjustment_timer:
            robotbody.set_eyes_led(0, 31, 0)
            print("probably looking at goal")
            return "done"
        
        #Test if it has found a goal post
        if (self.has_new_goal_observation and self.looking_at_goal())\
            or self.changed_speed and self.current_time>self.start_time:
            robotbody.set_eyes_led(0, 31, 0)
            print("found goal, " + self.which_goal_type)
            return "done"
        
        #Tests if it is time to abandon the search for a goal
        if self.current_time > self.start_time + self.max_circling_time:
            robotbody.set_eyes_led(0, 0, 31)
            print("lucky shot")
            return "fail"

        
        #Updates the head position
        self.update_head_position()
        
        #Updates the walking speed for the robot
        self.update_speed()
 def exit (self):
     print ("sitting")
     motion.start_walk()
     robotbody.set_eyes_led(0, 0, 31)
예제 #17
0
 def entry(self):
     robotbody.set_eyes_led(self.color[0],self.color[1],self.color[2])