How to Use GPU Lidar in Cosys-AirSim¶
Cosys-AirSim supports a GPU accelerated Lidar for multirotors and cars. It uses a depth camera that rotates around to simulate a Lidar while exploiting the GPU to do most of the work. Should allow for a large increase in amount of points that can be simulated.
The enablement of a GPU lidar and the other lidar settings can be configured via AirSimSettings json. Please see general sensors for information on configuration of general/shared sensor settings.
The sensor capture can optionally be dispatched asynchronously to the Unreal game thread by enabling AsyncCaptureMode (see the parameter table below). AsyncCaptureMode defaults to enabled for Multirotor vehicles and disabled for all other vehicle types, but can be explicitly set either way for any vehicle type. Real-time debug point drawing (DrawDebugPoints) is not supported while AsyncCaptureMode is enabled, for any vehicle type. Experimenting with this setting can improve performance of the LiDAR model.
note that this LiDAR model is computationally expensive and measurement rates (RotationsPerSecond) above 5 Hz should not be expected.
Enabling GPU lidar on a vehicle¶
- By default, GPU lidars are not enabled. To enable the sensor, set the SensorType and Enabled attributes in settings json.
- Multiple GPU lidars can be enabled on a vehicle. But one has to turn off DrawDebugPoints!
Ignoring glass and other material types¶
One can set an object that should be invisible to LIDAR sensors (such as glass) by giving them an Unreal Tag called LidarIgnore.
GPU Lidar configuration¶
The following parameters can be configured right now via settings json. For some more information check the publication on this topic here.
Server side visualization for debugging¶
By default, the lidar points are not drawn on the viewport. To enable the drawing of hit laser points on the viewport, please enable setting 'DrawDebugPoints' via settings json. Note this does not work while AsyncCaptureMode is enabled (which is the default for Multirotor vehicles, see above) for any vehicle type. This is only for testing purposes and will affect the data slightly. It also needs to be disabled when using multiple Lidar sensors to avoid artifacts!!
e.g.:
You can also tweak the variation of debugging with the 'DrawMode' parameter: - 0 = no coloring - 1 = groundtruth color labels (instance segmentation or other annotation labels depending on settings) - 2 = material - 3 = impact angle - 4 = intensitye.g.:
Client API¶
Use getGPULidarData(sensor name, vehicle name) API to retrieve the GPU Lidar data. The API returns a Point-Cloud as a flat array of floats along with the timestamp of the capture and lidar pose.
- Point-Cloud: The floats represent [x,y,z, rgb, intensity] coordinate for each point hit within the range in the last scan in NED format. The intensity is only calculated when
GenerateIntensityis enabled. The point cloud always holdsMeasurementsPerCyclexNumberOfChannelspoints, a laser that didn't get any reflection gives [0,0,0,0,0]. It is ordered per horizontal step, and within each step it has one point per laser, starting with the lowest laser (VerticalFOVLower). So the laser (channel or ring) of pointiisring = i % NumberOfChannels, with ring 0 the lowest laser. The ROS2 node publishes this as theringfield of the point cloud. - Lidar Pose: Default: sensor pose in the vehicle frame / External: If set to
External(see table) the coordinates will be in either Unreal NED whenExternalLocalisfalseor Local NED (from starting position from vehicle) whenExternalLocalistrue.
The simSetGPULidarPose API allows changing the pose of a GPU lidar sensor at runtime, taking an input pose as a combination of relative position and a quaternion in NED frame (relative to the vehicle, or absolute NED/local-NED per ExternalLocal if the lidar is configured as External). For example:
lidar_pose = airsim.Pose(airsim.Vector3r(0, 0, -1), airsim.to_quaternion(0.261799, 0, 0)) #PRY in radians
client.simSetGPULidarPose("lidar", lidar_pose, "vehicle")
Rgb represents a float32 representation of the RGB8 value that is linked either the instance segmentation system or a different annotation label. See the Image API documentation, Annotation documentation and the instance segmentation documentation.
The float32 comes from binary concatenation of the RGB8 values :rgb = value_segmentation.R << 16 | value_segmentation.G << 8 | value_segmentation.B\
It can be retrieved from the API and converted back to RGB8 with for example the following Python code:
lidar_data = client.getGPULidarData('lidar', 'vehicle')
points = np.array(lidar_data.point_cloud, dtype=np.dtype('f4'))
points = np.reshape(points, (int(points.shape[0] / 5), 5))
rgb_values = points[:, 3].astype(np.uint32)
rgb = np.zeros((np.shape(points)[0], 3))
xyz = points[:, 0:3]
for index, rgb_value in enumerate(rgb_values):
rgb[index, 0] = (rgb_value >> 16) & 0xFF
rgb[index, 1] = (rgb_value >> 8) & 0xFF
rgb[index, 2] = rgb_value & 0xFF
intensity = points[:, 4]
number_of_channels = 32 # NumberOfChannels of this GPU lidar in settings.json
ring = np.arange(points.shape[0]) % number_of_channels # 0 is the lowest laser