irsim.world.object_factory ========================== .. py:module:: irsim.world.object_factory Classes ------- .. autoapisummary:: irsim.world.object_factory.ObjectFactory Module Contents --------------- .. py:class:: ObjectFactory(world: Any = None) Factory class for creating various objects in the simulation. .. py:attribute:: world :value: None .. py:method:: create_from_parse(parse: list[dict[str, Any]] | dict[str, Any], obj_type: str = 'robot', group_start_index: int = 0) -> list[Any] Create objects from a parsed configuration. :param parse: Parsed configuration data. :type parse: list or dict :param obj_type: Type of object to create, 'robot' or 'obstacle'. :type obj_type: str :param group_start_index: Starting index for the group. :type group_start_index: int :returns: List of created objects. :rtype: list .. py:method:: create_from_map(points: numpy.ndarray, reso: numpy.ndarray | None = None, grid_map: numpy.ndarray | None = None, world_offset: list[float] | None = None) -> list[Any] Create map objects from points. :param points: (2, N) array of obstacle cell positions. :type points: np.ndarray :param reso: (2, 1) array of [x_reso, y_reso] cell sizes. :type reso: np.ndarray :param grid_map: Grid map array for fast collision detection. If None, no precomputed grid is used. :type grid_map: np.ndarray, optional :param world_offset: World offset [x, y]. If None, no additional world offset is applied. :type world_offset: list[float], optional :returns: List of ObstacleMap objects. :rtype: list .. py:method:: create_object(obj_type: str = 'robot', number: int = 1, distribution: dict[str, Any] | None = None, state: list[float] | None = None, goal: list[float] | None = None, **kwargs: Any) -> list[Any] Create multiple objects based on the parameters. :param obj_type: Type of object, 'robot' or 'obstacle'. :type obj_type: str :param number: Number of objects to create. :type number: int :param distribution: Distribution type for generating states. :type distribution: dict :param state: Initial state for objects. :type state: list :param goal: Goal state for objects. :type goal: list :param \*\*kwargs: Additional parameters for object creation. :returns: List of created objects. :rtype: list .. py:method:: create_robot(kinematics: dict[str, Any] | None = None, **kwargs: Any) -> Any Create a robot based on kinematics. Uses the kinematics registry to look up handler-class metadata (default color, state_dim, description) and creates an ``ObjectBase`` directly. Static / ``None`` kinematics still produce an ``ObjectStatic``. :param kinematics: Kinematics configuration. :type kinematics: dict :param \*\*kwargs: Additional parameters for robot creation. :returns: An instance of a robot. :rtype: ObjectBase .. py:method:: create_obstacle(kinematics: dict[str, Any] | None = None, **kwargs: Any) -> Any Create an obstacle based on kinematics. Uses the kinematics registry to look up handler-class metadata (default color, state_dim) and creates an ``ObjectBase`` directly. Static / ``None`` kinematics still produce an ``ObjectStatic``. :param kinematics: Kinematics configuration. :type kinematics: dict :param \*\*kwargs: Additional parameters for obstacle creation. :returns: An instance of an obstacle. :rtype: ObjectBase .. py:method:: generate_state_list(number: int = 1, distribution: dict[str, Any] | None = None, state: list[float] | None = None, goal: list[float] | None = None) -> tuple[list[list[float]], list[list[float]]] Generate a list of state vectors for multiple objects based on the specified distribution method. This function creates initial states for multiple objects in the simulation environment. It supports various distribution methods such as 'manual', 'circle', and 'random' to position the objects according to specific patterns or randomness. Defaults for the ``circle`` and ``random`` distributions are derived from the world attached to the factory (``self.world``). If no world is attached (e.g. in unit tests that instantiate ``ObjectFactory()`` directly), defaults fall back to a 10x10 world at offset ``[0, 0]``. :param number: Number of state vectors to generate. Default is 1. :type number: int :param distribution: Configuration dictionary specifying the distribution method and its parameters. Default is {"name": "manual"}. - 'name' (str): Name of the distribution method. Supported values are: - 'manual': States are specified manually. - 'circle': States are arranged in a circular pattern. - 'random': States are placed at random positions. - Additional parameters depend on the distribution method: - For 'manual': Manually specified states and goal. - For 'circle': - 'center' (List[float]): Center coordinates [x, y] of the circle. Default is the world center ``[offset_x + width / 2, offset_y + height / 2]``. - 'radius' (float): Radius of the circle. Default is ``min(width, height) / 2 - 0.5`` so the circle sits inside the world with a small margin. - For 'random': - 'range_low' (List[float]): Lower bounds ``[x, y, theta]`` for random state values. Default is ``[offset_x + 0.5, offset_y + 0.5, -pi]`` (the world bounds inset by 0.5). - 'range_high' (List[float]): Upper bounds ``[x, y, theta]`` for random state values. Default is ``[offset_x + width - 0.5, offset_y + height - 0.5, pi]``. - 'min_distance' (float): Minimum pairwise xy distance between sampled points. Default is 1.0. :type distribution: Dict[str, Any] :param state: Base state vector [x, y, theta] used as a template when ``distribution['name'] == 'manual'``. Default is [1, 1, 0]. :type state: List[float] :param goal: Goal state vector [x, y, theta] used when ``distribution['name'] == 'manual'``. Default is [1, 9, 0]. :type goal: List[float] :returns: A pair ``(state_list, goal_list)`` where each element is a list of 3-element state vectors ``[x, y, theta]`` for every generated object. :rtype: tuple[list[list[float]], list[list[float]]] :raises ValueError: If the distribution method specified in 'name' is not supported or if required parameters for a distribution method are missing.