def update(self): if has_fallen(): return "fallen" self.current_head_position=robotbody.get_head_position() if like(self.wanted_head_position,self.current_head_position): if self.ending: return "focus one" elif len(self.angles)==0: if vision.has_new_goal_observation(): self.get_goal_observation() self.searching_for_next() elif like(self.current_head_position[0],pi/2): return "fail" else: self.set_next_head_position() elif len(self.angles)==1: if vision.has_new_goal_observation(): self.get_goal_observation() self.focus_middle() else: self.set_next_head_position() else: return "focus middle"
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()
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): if has_fallen(): return "fallen" if vision.has_new_goal_observation(): if like(goal_angle()[0],0): return "done" else: return "standing in front of the goal" self.current_head_position=robotbody.get_head_position() if like(self.current_head_position,pi/2): return "can't find the goal" if like(self.wanted_head_position,self.current_head_position): self.update_head_position()
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): if has_fallen(): return "fallen" if vision.has_new_goal_observation(): if like(goal_angle()[0],0): print("found goal") return "done" self.update_head_position() if distance_to_ball() > 1: self.forward_velocity = self.const_forward_velocity; else: self.forward_velocity = 0 walk.set_velocity(self.forward_velocity, 0.4*self.direction, ball_angle()[0]*1.2) if time.time() > self.start_time + self.time: print("aiming away from our goal") return "done"