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 update_speed(self):
     self.distance_to_ball=distance_to_ball()
     if self.distance_to_ball> pi*3:
         self.forward_velocity = self.const_forward_velocity;
     elif self.distance_to_ball< pi and self.distance_to_ball>0:
         self.forward_velocity = -self.const_forward_velocity
     else:
         self.forward_velocity = 0
         
     walk.set_velocity(self.forward_velocity, self.circling_velocity, ball_angle()[0])
    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 update(self):
     
     #Tests if it has fallen
     if has_fallen():
         return "fallen"
     
     #Stores the current time for further tests
     self.current_time=time.time()
     
     #Updates the lost ball timer if it has a new ball observation
     if vision.has_new_ball_observation():
         self.lost_ball_timer=self.current_time+2
     
     #Test if it has lost the ball
     elif self.current_time>self.lost_ball_timer:
         return "lost ball"
     
     #Test if it is close enought to the ball
     if distance_to_ball()<=self.distance_to_ball:
         return "done"