irsim.world.sensors.lidar2d#
Classes#
Simulates a 2D Lidar sensor for detecting obstacles in the environment. |
Module Contents#
- class irsim.world.sensors.lidar2d.Lidar2D(state: numpy.ndarray | None = None, obj_id: int = 0, range_min: float = 0, range_max: float = 10, angle_range: float = pi, number: int = 100, scan_time: float = 0.1, noise: bool = False, std: float = 0.2, angle_std: float = 0.02, offset: list[float] | None = None, alpha: float = 0.3, has_velocity: bool = False, **kwargs)[源代码]#
Simulates a 2D Lidar sensor for detecting obstacles in the environment.
- 参数:
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. WrapTo2Pi is applied.
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.
Initialize the Lidar2D sensor.
- sensor_type = 'lidar2d'#
- range_min = 0#
- range_max = 10#
- angle_range = 0.0#
- angle_min = -0.0#
- angle_max = 0.0#
- angle_inc = 0.0#
- number = 100#
- scan_time = 0.1#
- noise = False#
- std = 0.2#
- angle_std = 0.02#
- offset#
- alpha#
- has_velocity = False#
- velocity#
- time_inc = 0.0#
- range_data#
- angle_list#
- color#
- obj_id = 0#
- parent: irsim.world.object_base.ObjectBase | None = None#
- plot_patch_list = []#
- plot_line_list = []#
- plot_text_list = []#
- init_geometry(state)[源代码]#
Initialize the Lidar's scanning geometry.
- 参数:
state (np.ndarray) -- Current state of the sensor.
- step(state)[源代码]#
Update the Lidar's state and process intersections with environment objects.
- 参数:
state (np.ndarray) -- New state of the sensor.
- laser_geometry_process(lidar_geometry)[源代码]#
Find the intersected objects and return the intersected indices with the lidar geometry
- 参数:
lidar_geometry (shapely.geometry.MultiLineString) -- The geometry of the lidar.
- 返回:
The indices of the intersected objects.
- 返回类型:
list
- calculate_range_vel(intersect_index)[源代码]#
Calculate the range data and velocities from intersected geometries.
- 参数:
intersect_index (list) -- List of intersected object indices.
- get_scan()[源代码]#
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
- 返回:
Scan data including angles, ranges, and velocities.
- 返回类型:
dict
- plot(ax, state: numpy.ndarray | None = None, **kwargs)[源代码]#
Plot the Lidar's detected lines on a given axis.
- property state: numpy.ndarray#
Get the current state of the lidar sensor.
- 返回:
Current state of the sensor.
- 返回类型:
np.ndarray
- set_laser_color(laser_indices, laser_color: str = 'blue', alpha: float = 0.3)[源代码]#
Set a specific color of the selected lasers.
- 参数:
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.