irsim.world.object_factory#
Classes#
Factory class for creating various objects in the simulation. |
Module Contents#
- class irsim.world.object_factory.ObjectFactory(world: Any = None)[source]#
Factory class for creating various objects in the simulation.
- world = None#
- create_from_parse(parse: list[dict[str, Any]] | dict[str, Any], obj_type: str = 'robot', group_start_index: int = 0) list[Any][source]#
Create objects from a parsed configuration.
- Parameters:
parse (list or dict) – Parsed configuration data.
obj_type (str) – Type of object to create, ‘robot’ or ‘obstacle’.
group_start_index (int) – Starting index for the group.
- Returns:
List of created objects.
- Return type:
list
- 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][source]#
Create map objects from points.
- Parameters:
points (np.ndarray) – (2, N) array of obstacle cell positions.
reso (np.ndarray) – (2, 1) array of [x_reso, y_reso] cell sizes.
grid_map (np.ndarray, optional) – Grid map array for fast collision detection. If None, no precomputed grid is used.
world_offset (list[float], optional) – World offset [x, y]. If None, no additional world offset is applied.
- Returns:
List of ObstacleMap objects.
- Return type:
list
- 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][source]#
Create multiple objects based on the parameters.
- Parameters:
obj_type (str) – Type of object, ‘robot’ or ‘obstacle’.
number (int) – Number of objects to create.
distribution (dict) – Distribution type for generating states.
state (list) – Initial state for objects.
goal (list) – Goal state for objects.
**kwargs – Additional parameters for object creation.
- Returns:
List of created objects.
- Return type:
list
- create_robot(kinematics: dict[str, Any] | None = None, **kwargs: Any) Any[source]#
Create a robot based on kinematics.
Uses the kinematics registry to look up handler-class metadata (default color, state_dim, description) and creates an
ObjectBasedirectly. Static /Nonekinematics still produce anObjectStatic.- Parameters:
kinematics (dict) – Kinematics configuration.
**kwargs – Additional parameters for robot creation.
- Returns:
An instance of a robot.
- Return type:
- create_obstacle(kinematics: dict[str, Any] | None = None, **kwargs: Any) Any[source]#
Create an obstacle based on kinematics.
Uses the kinematics registry to look up handler-class metadata (default color, state_dim) and creates an
ObjectBasedirectly. Static /Nonekinematics still produce anObjectStatic.- Parameters:
kinematics (dict) – Kinematics configuration.
**kwargs – Additional parameters for obstacle creation.
- Returns:
An instance of an obstacle.
- Return type:
- 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]]][source]#
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
circleandrandomdistributions are derived from the world attached to the factory (self.world). If no world is attached (e.g. in unit tests that instantiateObjectFactory()directly), defaults fall back to a 10x10 world at offset[0, 0].- Parameters:
number (int) – Number of state vectors to generate. Default is 1.
distribution (Dict[str, Any]) –
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.5so 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.
state (List[float]) – Base state vector [x, y, theta] used as a template when
distribution['name'] == 'manual'. Default is [1, 1, 0].goal (List[float]) – Goal state vector [x, y, theta] used when
distribution['name'] == 'manual'. Default is [1, 9, 0].
- 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.- Return type:
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.