コード例 #1
0
ファイル: states.py プロジェクト: E-Hansson/TDDD63-Humanoids
 def update(self):
     
     self.current_time=time.time()
     
     if has_fallen():
         return "fallen"
     
     #if self.current_time>=self.lost_ball_timer:
         #print ("lost ball")
         #return "lost ball"
     
     if self.timer and self.current_time>self.timer:
         return "check again"
     
     if not self.timer:
         if vision.has_new_ball_observation():
             self.first_ball_angle=ball_angle()[0]
             self.last_ball_angle=self.first_ball_angle
             self.timer=time.time()+fabs(self.first_ball_angle)*10
             self.lost_ball_timer=self.current_time+10
     
     else:
         if like(self.first_ball_angle,self.goal_angle,pi/9):
             print("lined up")
             return "lined up"
         
         else:
             set_head_position(ball_angle())
                 
         if self.first_ball_angle<0:
             walk.set_velocity(0, -0.4, self.last_ball_angle)
         else:
             walk.set_velocity(0, 0.4, self.last_ball_angle)
コード例 #2
0
ファイル: states.py プロジェクト: E-Hansson/TDDD63-Humanoids
 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)
コード例 #3
0
 def update(self):
     
     if has_fallen():
         return("fallen")
     
     self.update_head_position()
     
     if vision.has_new_ball_observation():
         return ("done")
コード例 #4
0
 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
コード例 #5
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()
コード例 #6
0
 def update(self):
     
     if has_fallen():
         return "fallen"
     
     self.current_time=time.time()
     
     if vision.has_new_ball_observation():
         self.lost_ball_timer=self.current_time+2
     
     elif self.current_time>self.lost_ball_timer:
         return "lost ball"
     
     if distance_to_ball()<=2.1:
         return "done"
コード例 #7
0
ファイル: states.py プロジェクト: E-Hansson/TDDD63-Humanoids
 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"
コード例 #8
0
 def update(self):
     if has_fallen():
         return("fallen")
     
     self.update_traveled_time()
     
     self.update_head_position()
             
     if vision.has_new_ball_observation():
         self.update_last()
         self.left_or_right()
         
     elif self.last_observation+self.accepted_out_of_sight_time<time.time():
         return ("out of sight")
             
     self.walk_sideways()
コード例 #9
0
 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()
コード例 #10
0
 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"
コード例 #11
0
 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()
コード例 #12
0
 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()