@@ -183,3 +183,87 @@ These functions are called in the update function and draw function of the vehic
183183 axes.set_xlim(self .spec.x_lim.min_value(), self .spec.x_lim.max_value())
184184 axes.set_ylim(self .spec.y_lim.min_value(), self .spec.y_lim.max_value())
185185```
186+
187+ ### 3.3.6 LiDAR Sensing Simulation
188+ The object sesning with 2D LiDAR can be simulated by executing the following sample program. A single 2D LiDAR senses multiple obstacles and the point cloud data is generated.
189+ [ lidar_obstacle_sensing.py] ( /src/simulations/perception/lidar_obstacle_sensing/lidar_obstacle_sensing.py )
190+ ``` python
191+ """
192+ lidar_obstacle_sensing.py
193+
194+ Author: Shisato Yano
195+ """
196+
197+ # import path setting
198+ import numpy as np
199+ import sys
200+ from pathlib import Path
201+
202+ abs_dir_path = str (Path(__file__ ).absolute().parent)
203+ relative_path = " /../../../components/"
204+
205+ sys.path.append(abs_dir_path + relative_path + " visualization" )
206+ sys.path.append(abs_dir_path + relative_path + " state" )
207+ sys.path.append(abs_dir_path + relative_path + " vehicle" )
208+ sys.path.append(abs_dir_path + relative_path + " obstacle" )
209+ sys.path.append(abs_dir_path + relative_path + " sensors" )
210+ sys.path.append(abs_dir_path + relative_path + " sensors/lidar" )
211+
212+
213+ # import component modules
214+ from global_xy_visualizer import GlobalXYVisualizer
215+ from min_max import MinMax
216+ from time_parameters import TimeParameters
217+ from vehicle_specification import VehicleSpecification
218+ from state import State
219+ from four_wheels_vehicle import FourWheelsVehicle
220+ from obstacle import Obstacle
221+ from obstacle_list import ObstacleList
222+ from sensors import Sensors
223+ from sensor_parameters import SensorParameters
224+ from omni_directional_lidar import OmniDirectionalLidar
225+
226+
227+ # flag to show plot figure
228+ # when executed as unit test, this flag is set as false
229+ show_plot = True
230+
231+
232+ def main ():
233+ """
234+ Main process function
235+ """
236+
237+ # set simulation parameters
238+ x_lim, y_lim = MinMax(- 30 , 30 ), MinMax(- 30 , 30 )
239+ vis = GlobalXYVisualizer(x_lim, y_lim, TimeParameters(span_sec = 20 ))
240+
241+ # create obstacle instances
242+ obst_list = ObstacleList()
243+ obst1 = Obstacle(State(x_m = - 5.0 , y_m = 15.0 , speed_mps = 1.0 ), yaw_rate_rps = np.deg2rad(10 ), width_m = 1.0 )
244+ obst_list.add_obstacle(obst1)
245+ obst2 = Obstacle(State(x_m = - 15.0 , y_m = - 15.0 ), length_m = 10.0 , width_m = 5.0 )
246+ obst_list.add_obstacle(obst2)
247+ obst3 = Obstacle(State(x_m = 20.0 ), yaw_rate_rps = np.deg2rad(15 ))
248+ obst_list.add_obstacle(obst3)
249+ vis.add_object(obst_list)
250+
251+ # create vehicle instance
252+ spec = VehicleSpecification(area_size = 30.0 ) # spec instance
253+ lidar = OmniDirectionalLidar(obst_list, SensorParameters(lon_m = spec.wheel_base_m/ 2 )) # lidar instance
254+ vehicle = FourWheelsVehicle(State(color = spec.color), spec, sensors = Sensors(lidar = lidar)) # set state, spec, lidar as arguments
255+ vis.add_object(vehicle)
256+
257+ # plot figure is not shown when executed as unit test
258+ if not show_plot: vis.not_show_plot()
259+
260+ # show plot figure
261+ vis.draw()
262+
263+
264+ # execute main process
265+ if __name__ == " __main__" :
266+ main()
267+
268+ ```
269+ ![ ] ( /src/simulations/perception/lidar_obstacle_sensing/lidar_obstacle_sensing.gif )
0 commit comments