def main() -> None:
    robot_mode = controller_utils.get_robot_mode()
    robot_zone = get_robot_zone()
    robot_file = get_robot_file(robot_zone, robot_mode).resolve()
    log_filename = controller_utils.get_robot_log_filename(robot_zone)

    controller_utils.tee_streams(
        robot_file.parent / log_filename,
        prefix=f'{robot_zone}| ',
    )

    if robot_zone == 0:
        # Only print once, but rely on Zone 0 always being run to ensure this is
        # always printed somewhere.
        print_simulation_version()

    print("Using {} for Zone {}".format(robot_file, robot_zone))

    # Pass through the various data our library needs
    os.environ['SR_ROBOT_ZONE'] = str(robot_zone)
    os.environ['SR_ROBOT_MODE'] = robot_mode
    os.environ['SR_ROBOT_FILE'] = str(robot_file)

    # Swith to running the competitor code
    reconfigure_environment(robot_file)

    runpy.run_path(str(robot_file))
Пример #2
0
def move_walls_after(seconds: int) -> None:
    robot = Supervisor()
    timestep = robot.getBasicTimeStep()
    walls = [
        webots_utils.node_from_def(robot, 'west_moving_wall'),
        webots_utils.node_from_def(robot, 'west_moving_triangle'),
        webots_utils.node_from_def(robot, 'east_moving_wall'),
        webots_utils.node_from_def(robot, 'east_moving_triangle'),
    ]

    if controller_utils.get_robot_mode() == 'comp':
        # Interact with the supervisor "robot" to wait for the start of the match.
        while robot.getCustomData() != 'start':
            robot.step(int(timestep))

    # wait for the walls to start moving in ms
    robot.step(seconds * 1000)

    print('Moving arena walls')  # noqa: T001
    for wall in walls:
        wall.setVelocity(LINEAR_DOWNWARDS)

    # wait for the walls to reach their final location
    robot.step(1000)

    for wall in walls:
        wall.resetPhysics()
Пример #3
0
    def schedule_lighting(self) -> None:
        if controller_utils.get_robot_mode() != 'comp':
            return

        print('Scheduled cues:')  # noqa: T001
        for cue in self.cue_stack:
            print(cue)  # noqa: T001

        # run pre-start snap changes
        for cue in self.cue_stack.copy():
            if cue.start_time == 0 and cue.fade_time is None:
                self.start_lighting_effect(cue)
                self.cue_stack.remove(cue)

        # Interact with the supervisor "robot" to wait for the start of the match.
        while self._robot.getCustomData() != 'start':
            self._robot.step(int(self.timestep))

        self.start_offset = self._robot.getTime()

        while self.cue_stack:
            for cue in self.cue_stack.copy():
                if (
                    cue.start_time >= 0 and
                    self.current_match_time() >= cue.start_time
                ):  # cue relative to start
                    self.start_lighting_effect(cue)
                    self.cue_stack.remove(cue)
                elif (
                    cue.start_time < 0 and
                    self.remaining_match_time() <= -(cue.start_time)
                ):  # cue relative to end
                    self.start_lighting_effect(cue)
                    self.cue_stack.remove(cue)

            self.do_lighting_step()
            self._robot.step(int(self.timestep))
Пример #4
0
        for station_code, emitter in self._emitters.items():
            emitter.send(
                struct.pack(
                    "!2sb",
                    station_code.encode("ASCII"),
                    int(self._claim_log.get_claimant(station_code)),
                ), )

    def main(self) -> None:
        timestep = self._robot.getBasicTimeStep()
        steps_per_broadcast = (1 / BROADCASTS_PER_SECOND) / (timestep / 1000)
        counter = 0
        while True:
            counter += 1
            self.receive_robot_captures()
            current_time = self._robot.getTime()
            self._claim_timer.tick(current_time)
            if counter > steps_per_broadcast:
                self.transmit_pulses()
                counter = 0
            self._robot.step(int(timestep))


if __name__ == "__main__":
    claim_log = ClaimLog(
        record_arena_actions=(controller_utils.get_match_file().exists()
                              and controller_utils.get_robot_mode() == 'comp'))
    attached_territories = AttachedTerritories(claim_log)
    territory_controller = TerritoryController(claim_log, attached_territories)
    territory_controller.main()
Пример #5
0
def quit_if_development_mode() -> None:
    if controller_utils.get_robot_mode() != 'comp':
        print("Development mode, exiting competition supervisor")
        exit()