Пример #1
0
def get_robots(supervisor: Supervisor,
               *,
               skip_missing: bool = False) -> List[Tuple[int, Node]]:
    """
    Get a list of (zone id, robot node) tuples.

    By default this raises a `ValueError` if it fails to fetch a robot node for
    a given zone, however this behaviour can be altered if the caller wishes to
    instead skip the missing nodes. This should only be done if the caller has
    already validated that the node ids being used for the lookups are
    definitely valid (and that therefore missing nodes are expected rather than
    a signal of an internal error).
    """

    robots = []  # List[Tuple[int, Supervisor]]

    for webots_id_str, zone_id in controller_utils.ROBOT_IDS_TO_CORNERS.items(
    ):
        robot = supervisor.getFromId(int(webots_id_str))
        if robot is None:
            if skip_missing:
                continue

            msg = "Failed to get Webots node for zone {} (id: {})".format(
                zone_id,
                webots_id_str,
            )
            print(msg)
            raise ValueError(msg)

        robots.append((zone_id, robot))

    return robots
def get_robots(supervisor: Supervisor) -> List[Tuple[int, Node]]:
    robots = []  # List[Tuple[int, Supervisor]]

    for webots_id_str, zone_id in sr_controller.ROBOT_IDS_TO_CORNERS.items():
        robot = supervisor.getFromId(int(webots_id_str))
        if robot is None:
            msg = "Failed to get Webots node for zone {} (id: {})".format(
                zone_id,
                webots_id_str,
            )
            print(msg)
            raise ValueError(msg)

        robots.append((zone_id, robot))

    return robots
def remove_unused_robots(supervisor: Supervisor) -> None:
    for webots_id_str, zone_id in sr_controller.ROBOT_IDS_TO_CORNERS.items():
        if sr_controller.get_zone_robot_file_path(zone_id).exists():
            continue

        # Remove the robot
        robot = supervisor.getFromId(int(webots_id_str))
        if robot is None:
            msg = "Failed to get Webots node for zone {} (id: {})".format(
                zone_id,
                webots_id_str,
            )
            print(msg)
            raise ValueError(msg)

        robot.remove()