world#
irsim.world#
- class irsim.world.world.World(name: str | None = 'world', height: float = 10, width: float = 10, step_time: float = 0.1, sample_time: float = 0.1, offset: list = [0, 0], control_mode: str = 'auto', collision_mode: str = 'stop', obstacle_map=None, mdownsample: int = 1, plot: dict = {}, status: str = 'None', **kwargs)[source]#
Bases:
objectRepresents the main simulation environment, managing objects and maps.
- name#
Name of the world.
- Type:
str
- height#
Height of the world.
- Type:
float
- width#
Width of the world.
- Type:
float
- step_time#
Time interval between steps.
- Type:
float
- sample_time#
Time interval between samples.
- Type:
float
- offset#
Offset for the world’s position.
- Type:
list
- control_mode#
Control mode (‘auto’ or ‘keyboard’).
- Type:
str
- collision_mode#
Collision mode (‘stop’, ‘reactive’, ‘unobstructed’).
- Type:
str
- obstacle_map#
Image file for the obstacle map.
- mdownsample#
Downsampling factor for the obstacle map.
- Type:
int
- status#
Status of the world and objects.
- plot#
Plot configuration for the world.
- gen_grid_map(obstacle_map, mdownsample=1)[source]#
Generate a grid map for obstacles.
- Parameters:
obstacle_map – Path to the obstacle map image.
mdownsample (int) – Downsampling factor.
- Returns:
Grid map, obstacle indices, and positions.
- Return type:
tuple
- get_map(resolution: float = 0.1, obstacle_list: list = [])[source]#
Get the map of the world with the given resolution.
- property time#
Get the current simulation time.
- Returns:
Current time based on steps and step_time.
- Return type:
float
- property buffer_reso#
Get the maximum resolution of the world.
- Returns:
Maximum resolution.
- Return type:
float
irsim.world.object_factory#
- class irsim.world.object_factory.ObjectFactory[source]#
Bases:
objectFactory class for creating various objects in the simulation.
- create_from_parse(parse, obj_type='robot')[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’.
- Returns:
List of created objects.
- Return type:
list
- create_from_map(points, reso=0.1)[source]#
Create map objects from points.
- Parameters:
points (list) – List of points.
reso (float) – Resolution of the map.
- Returns:
List of ObstacleMap objects.
- Return type:
list
- create_object(obj_type: str = 'robot', number: int = 1, distribution: dict = {'name': 'manual'}, state: list = [1, 1, 0], goal: list = None, **kwargs)[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={}, **kwargs)[source]#
Create a robot based on kinematics.
- Parameters:
kinematics (dict) – Kinematics configuration.
**kwargs – Additional parameters for robot creation.
- Returns:
An instance of a robot.
- Return type:
Robot
- create_obstacle(kinematics={}, **kwargs)[source]#
Create a obstacle based on kinematics.
- Parameters:
kinematics (dict) – Kinematics configuration.
**kwargs – Additional parameters for robot creation.
- Returns:
An instance of an obstacle.
- Return type:
Obstacle
- generate_state_list(number=1, distribution={'name': 'manual'}, state=[1, 1, 0], goal=[1, 9, 0])[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.
- Parameters:
state (Optional[List[float]]) – Base state vector [x, y, theta] to use as a template for generating states. If None, default values will be used.
number (int) – Number of state vectors to generate.
distribution (Dict[str, Any]) –
Configuration dictionary specifying the distribution method and its parameters. - ‘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.
’radius’ (float): Radius of the circle.
- For ‘random’:
’range_low’ (List[float]): Lower bounds for random state values.
’range_high’ (List[float]): Upper bounds for random state values.
- Returns:
A list containing generated state vectors and goal vectors for objects.
- Return type:
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.
- class irsim.world.object_base.ObjectInfo(id: int, shape: str, kinematics: str, role: str, color: str, static: bool, goal: numpy.ndarray, vel_min: numpy.ndarray, vel_max: numpy.ndarray, acce: numpy.ndarray, angle_range: numpy.ndarray, goal_threshold: float, wheelbase: float, G: numpy.ndarray, h: numpy.ndarray, cone_type: str, convex_flag: bool)[source]#
Bases:
object- id: int#
- shape: str#
- kinematics: str#
- role: str#
- color: str#
- static: bool#
- goal: ndarray#
- vel_min: ndarray#
- vel_max: ndarray#
- acce: ndarray#
- angle_range: ndarray#
- goal_threshold: float#
- wheelbase: float#
- G: ndarray#
- h: ndarray#
- cone_type: str#
- convex_flag: bool#
- class irsim.world.object_base.ObstacleInfo(center: numpy.ndarray, vertex: numpy.ndarray, velocity: numpy.ndarray, radius: float, G: numpy.ndarray, h: numpy.ndarray, cone_type: str, convex_flag: bool)[source]#
Bases:
object- center: ndarray#
- vertex: ndarray#
- velocity: ndarray#
- radius: float#
- G: ndarray#
- h: ndarray#
- cone_type: str#
- convex_flag: bool#
- class irsim.world.object_base.ObjectBase(shape: dict | None = None, kinematics: dict | None = None, state: list = [0, 0, 0], velocity: list = [0, 0], goal: list | None = None, role: str = 'obstacle', color: str = 'k', static: bool = False, vel_min: list = [-1, -1], vel_max: list = [1, 1], acce: list = [inf, inf], angle_range: list = [-3.141592653589793, 3.141592653589793], behavior: dict | None = None, goal_threshold: float = 0.1, sensors: dict | None = None, arrive_mode: str = 'position', description: str | None = None, group: int = 0, state_dim: int | None = None, vel_dim: int | None = None, unobstructed: bool = False, fov: float | None = None, fov_radius: float | None = None, **kwargs)[source]#
Bases:
objectBase class representing a generic object in the robot simulator.
This class encapsulates common attributes and behaviors for all objects, including robots and obstacles, managing their state, velocity, goals, and kinematics.
- Parameters:
shape (dict) – Parameters defining the shape of the object for geometry creation. The dictionary should contain keys and values required by the GeometryFactory to create the object’s geometry, such as ‘type’ (e.g., ‘circle’, ‘rectangle’) and associated parameters. Defaults to None.
kinematics (dict) – Parameters defining the kinematics of the object. Includes kinematic model and any necessary parameters. If None, no kinematics model is applied. Defaults to None.
state (list of float) – Initial state vector [x, y, theta, …]. The state can have more dimensions depending on state_dim. Excess dimensions are truncated, and missing dimensions are filled with zeros. Defaults to [0, 0, 0].
velocity (list of float) – Initial velocity vector [vx, vy] or according to the kinematics model. Defaults to [0, 0].
goal (list of float or list of list of float) – Goal state vector [x, y, theta, …] or [[x, y, theta], [x, y, theta], …] for multiple goals Used by behaviors to determine the desired movement. Defaults to [10, 10, 0].
role (str) – Role of the object in the simulation, e.g., “robot” or “obstacle”. Defaults to “obstacle”.
color (str) – Color of the object when plotted. Defaults to “k” (black).
static (bool) – Indicates if the object is static (does not move). Defaults to False.
vel_min (list of float) – Minimum velocity limits for each control dimension. Used to constrain the object’s velocity. Defaults to [-1, -1].
vel_max (list of float) – Maximum velocity limits for each control dimension. Used to constrain the object’s velocity. Defaults to [1, 1].
acce (list of float) – Acceleration limits, specifying the maximum change in velocity per time step. Defaults to [inf, inf].
angle_range (list of float) – Allowed range of orientation angles [min, max] in radians. The object’s orientation will be wrapped within this range. Defaults to [-pi, pi].
behavior (dict or str) – Behavioral mode or configuration of the object. Can be a behavior name (str) or a dictionary with behavior parameters. If None, default behavior is applied. Defaults to {‘name’: ‘dash’}, moving to the goal directly.
goal_threshold (float) – Threshold distance to determine if the object has reached its goal. When the object is within this distance to the goal, it’s considered to have arrived. Defaults to 0.1.
sensors (list of dict) – List of sensor configurations attached to the object. Each sensor configuration is a dictionary specifying sensor type and parameters. Defaults to None.
arrive_mode (str) – Mode for arrival detection, either “position” or “state”. Determines how arrival at the goal is evaluated. Defaults to “position”.
description (str) – Description or label for the object. Can be used for identification or attaching images in plotting. Defaults to None.
group (int) – Group identifier for organizational purposes, allowing objects to be grouped. Defaults to 0.
state_dim (int) – Dimension of the state vector. If None, it is inferred from the class attribute state_shape. Defaults to None.
vel_dim (int) – Dimension of the velocity vector. If None, it is inferred from the class attribute vel_shape. Defaults to None.
unobstructed (bool) – Indicates if the object should be considered to have an unobstructed path, ignoring obstacles in certain scenarios. Defaults to False.
fov (float) – Field of view angles in radians for the object’s sensors. Defaults to None. If set lidar, the default value is angle range of lidar.
fov_radius (float) – Field of view radius for the object’s sensors. Defaults to None. If set lidar, the default value is range_max of lidar.
**kwargs –
Additional keyword arguments for extended functionality. plot (dict): Plotting options for the object.
May include ‘show_goal’, ‘show_text’, ‘show_arrow’, ‘show_uncertainty’, ‘show_trajectory’, ‘trail_freq’, etc.
- Raises:
ValueError – If dimension parameters do not match the provided shapes or if input parameters are invalid.
- state_dim#
Dimension of the state vector.
- Type:
int
- state_shape#
Shape of the state array.
- Type:
tuple
- vel_dim#
Dimension of the velocity vector.
- Type:
int
- vel_shape#
Shape of the velocity array.
- Type:
tuple
- state#
Current state of the object.
- Type:
np.ndarray
- _init_state#
Initial state of the object.
- Type:
np.ndarray
- _velocity#
Current velocity of the object.
- Type:
np.ndarray
- _init_velocity#
Initial velocity of the object.
- Type:
np.ndarray
- _goal#
Goal state of the object.
- Type:
np.ndarray
- _init_goal#
Initial goal state of the object.
- Type:
np.ndarray
- _geometry#
Geometry representation of the object.
- Type:
any
- group#
Group identifier for the object.
- Type:
int
- stop_flag#
Flag indicating if the object should stop.
- Type:
bool
- arrive_flag#
Flag indicating if the object has arrived at the goal.
- Type:
bool
- collision_flag#
Flag indicating a collision has occurred.
- Type:
bool
- unobstructed#
Indicates if the object has an unobstructed path.
- Type:
bool
- static#
Indicates if the object is static.
- Type:
bool
- vel_min#
Minimum velocity limits.
- Type:
np.ndarray
- vel_max#
Maximum velocity limits.
- Type:
np.ndarray
- color#
Color of the object.
- Type:
str
- role#
Role of the object (e.g., “robot”, “obstacle”).
- Type:
str
- info#
Information container for the object.
- Type:
- wheelbase#
Distance between the front and rear wheels. Specified for ackermann robots.
- Type:
float
- fov#
Field of view angles in radians.
- Type:
float
- fov_radius#
Field of view radius.
- Type:
float
- id_iter = count(0)#
- state_shape = (3, 1)#
- vel_shape = (2, 1)#
- step(velocity: ndarray | None = None, **kwargs: any)[source]#
Perform a simulation step, updating the object’s state.
- Parameters:
velocity (np.ndarray, optional) – Desired velocity for the step.
**kwargs – Additional parameters.
- Returns:
The new state of the object.
- Return type:
np.ndarray
- check_status()[source]#
Check the current status of the object, including arrival and collision detection.
This method evaluates collision detection and sets stop flags based on the collision mode. It also handles different collision modes like ‘stop’, ‘reactive’, ‘unobstructed’, etc.
- check_arrive_status()[source]#
Check if the object has arrived at its goal position.
The arrival detection depends on the arrive_mode setting: - “state”: Compares full state (x, y, theta) - “position”: Compares only position (x, y)
Updates the arrive_flag and handles multiple goals by removing completed ones.
- check_collision_status()[source]#
Check if the object is in collision with other objects in the environment.
This method queries possible collision objects from the geometry tree and checks for intersections. It logs collision warnings for robots and updates the collision_flag and collision_obj list.
- check_collision(obj)[source]#
Check collision with another object.
- Parameters:
obj (ObjectBase) – Another object to check collision with.
- Returns:
True if collision occurs, False otherwise.
- Return type:
bool
- gen_behavior_vel(velocity: ndarray | None = None) ndarray[source]#
Generate behavior-influenced velocity for the object.
This method adjusts the desired velocity based on the object’s behavior configurations. If no desired velocity is provided (velocity is None), the method may generate a default velocity or issue warnings based on the object’s role and behavior settings.
- Parameters:
velocity (Optional[np.ndarray]) – Desired velocity vector. If None, the method determines the velocity based on behavior configurations. Defaults to None.
- Returns:
Velocity vector adjusted based on behavior configurations and constraints.
- Return type:
np.ndarray
- Raises:
Warning – If velocity is None and no behavior configuration is set for a robot.
- pre_process()[source]#
Perform pre-processing before stepping the object.
This method is called before velocity generation and state updates. Can be overridden by subclasses to implement custom pre-processing logic.
- post_process()[source]#
Perform post-processing after stepping the object.
This method is called after state updates and sensor updates. Can be overridden by subclasses to implement custom post-processing logic.
- mid_process(state: ndarray)[source]#
Process state in the middle of a step. Make sure the state is within the desired dimension.
- Parameters:
state (np.ndarray) – State vector.
- Returns:
Processed state.
- Return type:
np.ndarray
- get_lidar_scan()[source]#
Get the lidar scan of the object.
- Returns:
Lidar scan data containing range and angle information.
- Return type:
dict
- get_lidar_points()[source]#
Get the lidar scan points of the object.
- Returns:
Array of lidar scan points.
- Return type:
np.ndarray
- get_lidar_offset()[source]#
Get the lidar offset relative to the object.
- Returns:
Lidar offset [x, y, theta] relative to the object center.
- Return type:
list
- get_fov_detected_objects()[source]#
Detect the env objects that in the field of view.
- Returns:
The objects that in the field of view of the object.
- Return type:
list
- fov_detect_object(detected_object: ObjectBase)[source]#
Detect whether the input object is in the field of view.
- Parameters:
object – The object that to be detected.
- Returns:
Whether the object is in the field of view.
- Return type:
bool
- set_state(state: list | ndarray = [0, 0, 0], init: bool = False)[source]#
Set the state of the object.
- Parameters:
state – The state of the object [x, y, theta].
init (bool) – Whether to set the initial state (default False).
- set_velocity(velocity: list | ndarray = [0, 0], init: bool = False)[source]#
Set the velocity of the object.
- Parameters:
velocity – The velocity of the object. Depending on the kinematics model.
init (bool) – Whether to set the initial velocity (default False).
- set_random_goal(obstacle_list, init: bool = False, free: bool = True, goal_check_radius: float = 0.2, range_limits: list = None, max_attempts: int = 100)[source]#
Set random goal(s) in the environment. If free set to True, the goal will be placed only in the free from obstacles part of the environment.
- Parameters:
obstacle_list – List of objects in the environment
init (bool) – Whether to set the initial goal (default False).
free (bool) – Whether to check that goal is placed in a position free of obstacles.
goal_check_radius (float) – Radius in which to check if the goal is free of obstacles.
range_limits (list) – List of lower and upper bound range limits in which to set the random goal position.
max_attempts (int) – Max number of attempts to place the goal in a position free of obstacles.
- set_goal(goal: list | ndarray = [10, 10, 0], init: bool = False)[source]#
Set the goal of the object.
- Parameters:
goal – The goal of the object [x, y, theta] or [[x, y, theta], [x, y, theta], …]
init (bool) – Whether to set the initial goal (default False).
- set_laser_color(laser_indices, laser_color: str = 'cyan', alpha: float = 0.3)[source]#
Set the color of the lasers.
- Parameters:
laser_indices (list) – The indices of the lasers to set the color.
laser_color (str) – The color to set the lasers. Default is ‘cyan’.
alpha (float) – The transparency of the lasers. Default is 0.3.
- input_state_check(state: list, dim: int = 3)[source]#
Check and adjust the state to match the desired dimension.
- Parameters:
state (list) – State of the object.
dim (int) – Desired dimension. Defaults to 3.
- Returns:
Adjusted state.
- Return type:
list
- plot(ax, state: ndarray | None = None, vertices: ndarray | None = None, **kwargs)[source]#
Plot the object on the given axis.
- Parameters:
ax – Matplotlib axis object for plotting.
state – State vector [x, y, theta, …] defining object position and orientation.
vertices – Vertices array defining object shape for polygon/rectangle objects.
**kwargs – Plotting configuration options.
- plot_object(ax, state: ndarray | None = None, vertices: ndarray | None = None, **kwargs)[source]#
Plot the object itself in the specified coordinate system.
- Parameters:
ax – Matplotlib axis object
state – State of the object (x, y, r_phi) defining position and orientation. If None, uses the object’s current state. Defaults to None.
vertices – Vertices of the object [[x1, y1], [x2, y2], …] for polygon and rectangle shapes. If None, uses the object’s current vertices. Defaults to None.
**kwargs – Additional plotting options - obj_linestyle (str): Line style for object outline, defaults to ‘-’ - obj_zorder (int): Drawing layer order, defaults to 3 if object is robot, 1 if object is the obstacle. - obj_color (str): Color of the object, defaults to ‘k’ (black). - obj_alpha (float): Transparency of the object, defaults to 1.0.
- Returns:
None
- Raises:
ValueError – When object shape is not supported
- plot_object_image(ax, state: ndarray | None = None, vertices: ndarray | None = None, description: str = None, **kwargs)[source]#
Plot the object using an image file based on the description.
- Parameters:
ax – Matplotlib axis object for plotting.
state (Optional[np.ndarray]) – State of the object (x, y, r_phi) defining position and orientation. If None, uses the object’s current state. Defaults to None.
vertices (Optional[np.ndarray]) – Vertices of the object for positioning the image. If None, uses the object’s current vertices. Defaults to None.
description (str) – Path or name of the image file to display. Defaults to None.
**kwargs – Additional plotting options (currently unused).
Note
The image file is searched in the world/description/ directory relative to the project root. The image is rotated and positioned according to the object’s state and vertices.
- plot_trajectory(ax, trajectory: list | None = None, keep_length: int = 0, **kwargs)[source]#
Plot the trajectory path of the object using the specified trajectory data.
- Parameters:
ax – Matplotlib axis.
trajectory – List of trajectory points to plot, where each point is a numpy array [x, y, theta, …]. If None, uses self.trajectory. Defaults to None.
keep_length (int) – Number of steps to keep from the end of trajectory. If 0, plots entire trajectory. Defaults to 0.
**kwargs – Additional plotting options: traj_color (str): Color of the trajectory line. traj_style (str): Line style of the trajectory. traj_width (float): Width of the trajectory line. traj_alpha (float): Transparency of the trajectory line. traj_zorder (int): Zorder of the trajectory.
- plot_goal(ax, goal_state: ndarray | None = None, vertices: ndarray | None = None, goal_color: str | None = None, goal_zorder: int | None = 1, goal_alpha: float | None = 0.5, **kwargs)[source]#
Plot the goal position of the object in the specified coordinate system.
- Parameters:
ax – Matplotlib axis.
goal_state – State of the goal (x, y, r_phi) defining goal position and orientation. If None, uses [0, 0, 0]. Defaults to None.
vertices – Vertices for polygon/rectangle goal shapes. If None, uses original_vertices. Defaults to None.
goal_color (str) – Color of the goal marker. Defaults to be the color of the object.
goal_zorder (int) – Zorder of the goal marker. Defaults to 1.
goal_alpha (float) – Transparency of the goal marker. Defaults to 0.5.
- plot_text(ax, state: ndarray | None = None, **kwargs)[source]#
Plot the text label of the object at the specified position.
- Parameters:
ax – Matplotlib axis.
state – State of the object (x, y, r_phi) to determine text position. If None, uses the object’s current state. Defaults to None.
**kwargs –
Additional plotting options. text_color (str): Color of the text, default is ‘k’. text_size (int): Font size of the text, default is 10. text_position (list): Position offset from object center [dx, dy],
default is [-radius-0.1, radius+0.1].
text_zorder (int): Zorder of the text. Defaults to 2. text_alpha (float): Transparency of the text. Defaults to 1.
- plot_arrow(ax, state: ndarray | None = None, velocity: ndarray | None = None, arrow_length: float = 0.4, arrow_width: float = 0.6, arrow_color: str | None = None, arrow_zorder: int = 3, **kwargs)[source]#
Plot an arrow indicating the velocity orientation of the object at the specified position.
- Parameters:
ax – Matplotlib axis.
state – State of the object (x, y, r_phi) to determine arrow position. If None, uses the object’s current state. Defaults to None.
velocity – Velocity of the object to determine arrow direction. If None, uses the object’s current velocity_xy. Defaults to None.
arrow_length (float) – Length of the arrow. Defaults to 0.4.
arrow_width (float) – Width of the arrow. Defaults to 0.6.
arrow_color (str) – Color of the arrow. Defaults to “gold”.
arrow_zorder (int) – Z-order for drawing layer. Defaults to 4.
- plot_trail(ax, state: ndarray | None = None, vertices: ndarray | None = None, **kwargs)[source]#
Plot the trail/outline of the object at the specified position for visualization purposes.
- Parameters:
ax – Matplotlib axis.
state – State of the object (x, y, r_phi) to determine trail position and orientation. If None, uses the object’s current state. Defaults to None.
vertices – Vertices of the object for polygon and rectangle trail shapes. If None, uses the object’s current vertices. Defaults to None.
**kwargs – Additional plotting options: trail_type (str): Type of trail shape, defaults to object’s shape. trail_edgecolor (str): Edge color of the trail. trail_linewidth (float): Line width of the trail edge. trail_alpha (float): Transparency of the trail. trail_fill (bool): Whether to fill the trail shape. trail_color (str): Fill color of the trail. trail_zorder (int): Z-order of the trail.
- plot_fov(ax, **kwargs)[source]#
Plot the field of view of the object. Creates FOV wedge at origin, will be positioned using transforms in step_plot.
- Parameters:
ax – Matplotlib axis.
**kwargs – Additional plotting options. fov_color (str): Color of the field of view. Default is ‘lightblue’. fov_edge_color (str): Edge color of the field of view. Default is ‘blue’. fov_zorder (int): Z-order of the field of view. Default is 1. fov_alpha (float): Transparency of the field of view. Default is 0.5.
- plot_clear(all: bool = False)[source]#
Clear all plotted elements from the axis.
- Parameters:
all (bool) – If True, also clears trail elements. If False, keeps trail elements. Defaults to False.
- done()[source]#
Check if the object has completed its task.
- Returns:
True if the task is done, False otherwise.
- Return type:
bool
- get_vel_range() tuple[ndarray, ndarray][source]#
Get the velocity range considering acceleration limits.
- Returns:
Minimum and maximum velocities.
- Return type:
tuple
- get_info() ObjectInfo[source]#
Get object information.
- Returns:
Information about the object.
- Return type:
- get_obstacle_info() ObstacleInfo[source]#
Get information about the object as an obstacle.
- Returns:
Obstacle-related information, including state, vertices, velocity, and radius.
- Return type:
- get_init_Gh() tuple[ndarray, ndarray][source]#
Get the initial generalized inequality matrices G and h for the convex object.
- Returns:
Tuple containing initial G matrix and h vector.
- Return type:
tuple[np.ndarray, np.ndarray]
- get_Gh() tuple[ndarray, ndarray][source]#
Get the generalized inequality matrices G and h for the convex object.
- Returns:
Tuple containing G matrix and h vector.
- Return type:
tuple[np.ndarray, np.ndarray]
- property name: str#
Get the name of the object.
- Returns:
The name of the object.
- Return type:
str
- property abbr: str#
Get the abbreviation of the object.
- Returns:
The abbreviation of the object.
- Return type:
str
- property shape: str#
Get the shape name of the object.
- Returns:
The shape name of the object.
- Return type:
str
- property z: float#
Get the z coordinate of the object. For 3D object, the z coordinate is the height of the object, for 2D object, the z coordinate is 0.
- Returns:
The z coordinate of the object.
- Return type:
float
- property kinematics: str#
Get the kinematics name of the object.
- Returns:
The kinematics name of the object.
- Return type:
str
- property geometry: BaseGeometry#
Get the geometry Instance of the object.
- Returns:
The geometry of the object.
- Return type:
shapely.geometry.base.BaseGeometry
- property centroid: ndarray#
Get the centroid of the object.
- Returns:
The centroid of the object.
- Return type:
np.ndarray
- property id: int#
Get the id of the object.
- Returns:
The id of the object.
- Return type:
int
- property state: ndarray#
Get the state of the object.
- Returns:
The state of the object.
- Return type:
np.ndarray
- property init_state: ndarray#
Get the initial state of the object.
- Returns:
The initial state of the object.
- Return type:
np.ndarray
- property velocity: ndarray#
Get the velocity of the object.
- Returns:
The velocity of the object.
- Return type:
np.ndarray
- property goal: ndarray#
Get the goal of the object.
- Returns:
The goal of the object.
- Return type:
np.ndarray
- property goal_vertices: ndarray#
Get the goal vertices of the object.
- Returns:
The goal vertices of the object.
- Return type:
np.ndarray
- property position: ndarray#
Get the position of the object.
- Returns:
The position of the object .
- Return type:
np.ndarray
- property radius: float#
Get the radius of the object.
- Returns:
The radius of the object.
- Return type:
float
- property length: float#
Get the length of the object.
- Returns:
The length of the object.
- Return type:
float
- property width: float#
Get the width of the object.
- Returns:
The width of the object.
- Return type:
float
- property wheelbase: float#
Get the wheelbase of the object.
- Returns:
The wheelbase of the object.
- Return type:
float
- property radius_extend: float#
Get the radius of the object with a buffer.
- Returns:
The radius of the object with a buffer.
- Return type:
float
- property arrive: bool#
Get the arrive flag of the object.
- Returns:
The arrive flag of the object.
- Return type:
bool
- property collision: bool#
Get the collision flag of the object.
- Returns:
The collision flag of the object.
- Return type:
bool
- property vertices: ndarray#
Get the vertices of the object.
- Returns:
The vertices of the object.
- Return type:
np.ndarray
- property original_vertices: ndarray#
Get the original vertices of the object.
- Returns:
The original vertices of the object before any transformations.
- Return type:
np.ndarray
- property original_geometry: BaseGeometry#
Get the original geometry of the object.
- Returns:
The original geometry of the object.
- Return type:
shapely.geometry.base.BaseGeometry
- property original_centroid: ndarray#
Get the center of the object.
- Returns:
The center of the object.
- Return type:
np.ndarray
- property original_state: ndarray#
Get the original state of the object from the original centroid.
- Returns:
The original state of the object.
- Return type:
np.ndarray (3,1)
- property external_objects#
Get the environment objects that are not the self object.
- Returns:
The environment objects that are not the self object.
- Return type:
list
- property ego_object#
Get the ego object (this object itself).
- Returns:
The ego object (this object).
- Return type:
- property possible_collision_objects#
Get the possible collision objects of the object from the geometry tree.
- Returns:
The possible collision objects that could collide with this object.
- Return type:
list
- property desired_omni_vel#
Calculate the desired omnidirectional velocity.
- Parameters:
goal_threshold (float) – Threshold for goal proximity.
- Returns:
Desired velocity [vx, vy].
- Return type:
np.ndarray
- property rvo_neighbors#
Get the list of RVO neighbors. :returns: List of RVO neighbor states [x, y, vx, vy, radius]. :rtype: list
- property rvo_neighbor_state#
Get the RVO state for this object.
- Returns:
State [x, y, vx, vy, radius].
- Return type:
list
- property rvo_state#
Get the full RVO state including desired velocity.
- Returns:
State [x, y, vx, vy, radius, vx_des, vy_des, theta].
- Return type:
list
- property velocity_xy#
Get the velocity in x and y directions.
- Returns:
Velocity [vx, vy].
- Return type:
(2*1) np.ndarray
- property beh_config#
Get the behavior configuration of the object.
- Returns:
The behavior configuration of the object.
- Return type:
dict
- property logger#
Get the logger of the env_param.
- Returns:
The logger associated in the env_param.
- Return type:
Logger
- property heading#
Get the heading of the object.
- Returns:
The heading of the object.
- Return type:
float
- property orientation#
Get the orientation of the object.
- Returns:
The orientation angle of the object in radians.
- Return type:
float
irsim.world.sensor_factory#
- class irsim.world.sensors.lidar2d.Lidar2D(state: ndarray = None, obj_id: int = 0, range_min: float = 0, range_max: float = 10, angle_range: float = 3.141592653589793, number: int = 100, scan_time: float = 0.1, noise: bool = False, std: float = 0.2, angle_std: float = 0.02, offset: list[float] = [0, 0, 0], alpha: float = 0.3, has_velocity: bool = False, **kwargs)[source]#
Bases:
objectSimulates a 2D Lidar sensor for detecting obstacles in the environment.
- Parameters:
state (np.ndarray) – Initial state of the sensor.
obj_id (int) – ID of the associated object.
range_min (float) – Minimum detection range.
range_max (float) – Maximum detection range.
angle_range (float) – Total angle range of the sensor.
number (int) – Number of laser beams.
scan_time (float) – Time taken for one complete scan.
noise (bool) – Whether noise is added to measurements.
std (float) – Standard deviation for range noise.
angle_std (float) – Standard deviation for angle noise.
offset (list) – Offset of the sensor from the object’s position.
alpha (float) – Transparency for plotting.
has_velocity (bool) – Whether the sensor measures velocity.
**kwargs – Additional arguments. color (str): Color of the sensor.
- Attr:
sensor_type (str): Type of sensor (“lidar2d”). Default is “lidar2d”.
range_min (float): Minimum detection range in meters. Default is 0.
range_max (float): Maximum detection range in meters. Default is 10.
angle_range (float): Total angle range of the sensor in radians. Default is pi.
angle_min (float): Starting angle of the sensor’s scan relative to the forward direction in radians. Calculated as -angle_range / 2.
angle_max (float): Ending angle of the sensor’s scan relative to the forward direction in radians. Calculated as angle_range / 2.
angle_inc (float): Angular increment between each laser beam in radians. Calculated as angle_range / number.
number (int): Number of laser beams. Default is 100.
scan_time (float): Time taken to complete one full scan in seconds. Default is 0.1.
noise (bool): Whether to add noise to the measurements. Default is False.
std (float): Standard deviation for range noise in meters. Effective only if noise is True. Default is 0.2.
angle_std (float): Standard deviation for angle noise in radians. Effective only if noise is True. Default is 0.02.
offset (np.ndarray): Offset of the sensor relative to the object’s position, formatted as [x, y, theta]. Default is [0, 0, 0].
lidar_origin (np.ndarray): Origin position of the Lidar sensor, considering offset and the object’s state.
alpha (float): Transparency level for plotting the laser beams. Default is 0.3.
has_velocity (bool): Whether the sensor measures the velocity of detected points. Default is False.
velocity (np.ndarray): Velocity data for each laser beam, formatted as (2, number) array. Effective only if has_velocity is True. Initialized to zeros.
time_inc (float): Time increment for each scan, simulating the sensor’s time resolution. Default is 5e-4.
range_data (np.ndarray): Array storing range data for each laser beam. Initialized to range_max for all beams.
angle_list (np.ndarray): Array of angles corresponding to each laser beam, distributed linearly from angle_min to angle_max.
color (str): Color of the sensor’s representation in visualizations. Default is “r” (red).
obj_id (int): ID of the associated object, used to differentiate between multiple sensors or objects in the environment. Default is 0.
plot_patch_list (list): List storing plot patches (e.g., line collections) for visualization purposes.
plot_line_list (list): List storing plot lines for visualization purposes.
plot_text_list (list): List storing plot text elements for visualization purposes.
- init_geometry(state)[source]#
Initialize the Lidar’s scanning geometry.
- Parameters:
state (np.ndarray) – Current state of the sensor.
- step(state)[source]#
Update the Lidar’s state and process intersections with environment objects.
- Parameters:
state (np.ndarray) – New state of the sensor.
- laser_geometry_process(lidar_geometry)[source]#
Find the intersected objects and return the intersected indices with the lidar geometry
- Parameters:
lidar_geometry (shapely.geometry.MultiLineString) – The geometry of the lidar.
- Returns:
The indices of the intersected objects.
- Return type:
list
- calculate_range_vel(intersect_index)[source]#
Calculate the range data and velocities from intersected geometries.
- Parameters:
intersect_index (list) – List of intersected object indices.
- get_scan()[source]#
Get the 2D lidar scan data. refer to the ros topic scan: http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/LaserScan.html
- Returns:
Scan data including angles, ranges, and velocities.
- Return type:
dict
- get_points()[source]#
Convert scan data to a point cloud.
- Returns:
Point cloud (2xN).
- Return type:
np.ndarray
- plot(ax, state: ndarray | None = None, **kwargs)[source]#
Plot the Lidar’s detected lines on a given axis.
- property state: ndarray#
Get the current state of the lidar sensor.
- Returns:
Current state of the sensor.
- Return type:
np.ndarray
- set_laser_color(laser_indices, laser_color: str = 'blue', alpha: float = 0.3)[source]#
Set a specific color of the selected lasers.
- Parameters:
laser_indices (list) – The indices of the lasers to set the color.
laser_color (str) – The color to set the selected lasers. Default is ‘blue’.
alpha (float) – The transparency of the lasers. Default is 0.3.