Skip to content

Add a new LiDAR

RGLUnityPlugin (RGL) comes with a number of the most popular LiDARs model definitions and ready-to-use prefabs. However, there is a way to create your custom LiDAR. This section describes how to add a new LiDAR model that works with RGL, then create a prefab for it and add it to the scene.

Supported LiDARs

Not all lidar types are supported by RGL. Unfortunately, in the case of MEMs LiDARs, there is a non-repetitive phenomenon - for this reason, the current implementation is not able to reproduce their work.

1. Add new LiDAR model

The example shows the addition of a LiDAR named NewLidarModel.

To add a new LiDAR model, perform the following steps:

  1. Add its name to the LidarModels.cs at the end of the enumeration. The order of enums must not be changed to keep existing prefabs working.

    lidar_models

  2. If the LiDAR has a non-uniform laser array construction (e.g. different linear / angular spacing between lasers), add an entry to the LaserArrayLibrary, otherwise, skip this step.

    Coordinate system

    Keep in mind that Unity has a left-handed coordinate system, while most of the lidar's manuals use a right-handed coordinate system. In that case, reverse sign of the values of the angles.

    lidar_array

  3. Add an entry to LidarConfigurationLibrary. If the LiDAR has a uniform laser generate a uniform one using static method LaserArray.Uniform() - just like the RangeMeter.

    lidar_configuration

  4. Done. New LiDAR preset should be available via Unity Inspector.

    done

2. Create new LiDAR prefab

  1. Create an empty object and name it appropriately according to the LiDAR model.
  2. Attach script LidarSensor.cs to created object.
  3. Set the new added LiDAR model in Model Preset field, check if the configuration loads correctly. You can now customize it however you like.
  4. (Optional) Attach script PointCloudVisualization.cs for visualization purposes.
  5. For publishing point cloud via ROS2 attach script RglLidarPublisher.cs script to created object.
  6. Set the topics on which you want the data to be published and their frame.
  7. Save the prefab in the project.

3. Test your prefab

  1. Create a new scene (remember to add the SceneManager) or use one of the existing sample scenes.
  2. Add the prepared LiDAR prefab by drag the prefab file and drop it into a scene

  3. A LiDAR GameObject should be instantiated automatically

  4. Now you can run the scene and check how your LiDAR works.

Success

We encourage you to develop a vehicle using the new LiDAR you have added - learn how to do this here.