def __init__(self, match_time: int, progress_check_steps: int, progress_check_threshold: int, ball_progress_check_steps: int, ball_progress_check_threshold: int, post_goal_wait_time: int = 3, add_noise_to_initial_position: bool = True): super().__init__() self.match_time = match_time self.post_goal_wait_time = post_goal_wait_time self.add_noise_to_initial_position = add_noise_to_initial_position self.time = match_time self.emitter = self.getEmitter("emitter") self.robot_translation = ROBOT_INITIAL_TRANSLATION.copy() self.robot_rotation = ROBOT_INITIAL_ROTATION.copy() self.robot_translation_fields = {} self.robot_rotation_fields = {} self.robot_in_penalty_counter = {} self.progress_chck = {} for robot in ROBOT_NAMES: robot_node = self.getFromDef(robot) field = robot_node.getField('translation') self.robot_translation_fields[robot] = field field = robot_node.getField('rotation') self.robot_rotation_fields[robot] = field self.robot_in_penalty_counter[robot] = 0 pc = ProgressChecker(progress_check_steps, progress_check_threshold) self.progress_chck[robot] = pc self.ball = self.getFromDef("BALL") self.ball_translation_field = self.ball.getField("translation") bpc = ProgressChecker(ball_progress_check_steps, ball_progress_check_threshold) self.progress_chck['ball'] = bpc self.reset_positions() self._update_positions() self.ball_reset_timer = 0 self.score_blue = self.score_yellow = 0 self.draw_scores(self.score_blue, self.score_yellow)
def test_track_multiple_times(checker: ProgressChecker): checker.track([0.0, 0.0, 0.0]) checker.track([0.01, 0.0, 0.0]) checker.track([0.02, 0.0, 0.0]) assert checker.iterator == 2 assert checker.samples[0] == 0.01 assert checker.samples[1] == 0.01 assert checker.samples[2] == 0 assert checker.prev_position == [0.02, 0.0, 0.0]
def test_no_progress(checker: ProgressChecker): x = 0.0 checker.track([x, 0.0, 0.0]) for _ in range(234): x += 0.002 checker.track([x, 0.0, 0.0]) assert checker.is_progress() checker.track([x + 0.002, 0.0, 0.0]) assert not checker.is_progress()
def test_progress_ok(checker: ProgressChecker): for _ in range(235): checker.track([0.0, 0.0, 0.0]) assert checker.is_progress() checker.track([0.5, 0.0, 0.0]) assert checker.is_progress()
def __init__(self, match_time: int, match_id: int, half_id: int, progress_check_steps: int, progress_check_threshold: int, ball_progress_check_steps: int, ball_progress_check_threshold: int, team_name_blue: str, team_name_yellow: str, initial_score_blue: int, initial_score_yellow: int, penalty_area_allowed_time: int, penalty_area_reset_after: int, post_goal_wait_time: int = 3, initial_position_noise: float = 0.15): super().__init__() self.match_time = match_time self.match_id = match_id self.half_id = half_id self.post_goal_wait_time = post_goal_wait_time self.initial_position_noise = initial_position_noise self.time = match_time # Event message queue to be drawn # List of Tuples of int (time) and string (message) self.event_messages_to_draw: List[Tuple[int, str]] = [] self.eventer = Eventer() self.team_name_blue = team_name_blue self.team_name_yellow = team_name_yellow self.emitter = self.getDevice("emitter") self.ball_stop = 2 self.robot_translation = ROBOT_INITIAL_TRANSLATION.copy() self.robot_rotation = ROBOT_INITIAL_ROTATION.copy() self.robot_nodes = {} self.robot_translation_fields = {} self.robot_rotation_fields = {} self.robot_in_penalty_counter = {} self.progress_chck = {} self.penalty_area_chck = {} for robot in ROBOT_NAMES: robot_node = self.getFromDef(robot) self.robot_nodes[robot] = robot_node field = robot_node.getField('translation') self.robot_translation_fields[robot] = field field = robot_node.getField('rotation') self.robot_rotation_fields[robot] = field self.robot_in_penalty_counter[robot] = 0 self.progress_chck[robot] = ProgressChecker( progress_check_steps, progress_check_threshold) self.penalty_area_chck[robot] = PenaltyAreaChecker( penalty_area_allowed_time, penalty_area_reset_after, ) self.ball = self.getFromDef("BALL") self.ball_translation_field = self.ball.getField("translation") bpc = ProgressChecker(ball_progress_check_steps, ball_progress_check_threshold) self.progress_chck['ball'] = bpc self.reset_positions() self._update_positions() self.ball_reset_timer = 0 self.score_blue = initial_score_blue self.score_yellow = initial_score_yellow # The team that ought to have the kickoff at the next restart self.team_to_kickoff = None self.draw_team_names() self.draw_scores(self.score_blue, self.score_yellow)
def checker() -> ProgressChecker: return ProgressChecker(steps=235, threshold=0.5)
def test_progress_enough_steps(checker: ProgressChecker): checker.iterator = 235 assert not checker.is_progress()
def test_progress_after_initialize(checker: ProgressChecker): assert checker.is_progress()
def test_first_track(checker: ProgressChecker): position = [0.0, 0.0, 0.0] checker.track(position) assert checker.prev_position == position assert checker.samples[0] == 0