docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Use SystemGraph to create a new 2D sensor

    Overview

    This guide describes the creation and setup of a 2D sensor from a new project in the Unity Editor.

    Set up the system graph

    Create a new system graph

    To create a new sensor graph:

    1. In the Editor, go to Assets > Create > System > System Graph

      New System Graph

    2. Name the system graph 2DLidarTest.

    3. The system graph window should open automatically. To open manually, go to the Project tab and double-click the system graph.

    Create the required nodes

    1. In an empty area on the system graph, right-click and select Create Node.

      A list of node types displays in the drop-down menu. You can also use the search box to find matching terms.

      Create New Node

    2. Use Create Node to add the following nodes to your graph:

      • Lidar Controller node.
      • Photosensor v2 node.
      • DC Motor node.
      • Frame Bundler node.
      • PhotosensorToPointCloud v2 node.
      • Point cloud viewer node.
    3. After creating the nodes, arrange them in the order listed above. For best results, place the DC Motor node under the Photosensor v2 node. Node arrangement

      Refer to the node layout image for more detail.

    Create the properties

    1. Under the Properties tab, select the add button ( + ) and then select UInt.

      Add Property

    2. Enter the name SamplingRate.

    3. Expand the SamplingRate attributes and enter a default value of 2500.

      Sampling Rate Property

    4. Use the add button ( + ) to create another property, and then select Float .

    5. Rename the property to RotationRate.

    6. Expand the RotationRate attributes and enter a default value of 5.

    Connect the properties

    1. Drag each property from the Properties window to the left side of the Lidar Controller node.

    2. Connect the SamplingRate property to the Sampling rate port on the node.

    3. Connect the RotationRate property to the RotationRate port on the node.

      Lidar Controller Connections

    Connect the nodes in the system graph

    1. On the Photosensor v2 node, connect the SamplingRequest ports.

      Photosensor Connections

    2. Connect the MotorSpeed port on the Lidar Controller node to the RPM port on the DC Motor node.

      Lidar Controller/DC Motor Connections

    3. On the Frame Bundler node, connect the ports from the following nodes:

      • Photosensor v2 node:
        • RawData to RawData
        • OutTranscode to InTranscode
      • Lidar Controller node:
        • FrameWidth to TriggersPerFrame
        • FrameHeight to SamplesPerTrigger

      Frame Bundler Connections

      Refer to the node connections image for more detail.

    4. Connect the Frame and OutTranscode ports on the Frame Bundler node to the Frame and InTranscode ports on the PhotosensorToPointCloud v2 node, respectively.

      Photosensor To Point Cloud Connections

    5. Connect the PointCloud ports from the PhotosensorToPointCloud v2 node to the Point cloud viewer node.

      Point Cloud Viewer Connections

      After connecting all nodes, refer to the graph node diagram to make sure all corrections are correct.

    Configure the Scheduler

    1. In the Scheduler panel, double-click the DC Motor node to open the Scheduler bar.

    2. In the Scheduler bar, select Use ClockSource frequency.

    3. Select the exit icon to close the Scheduler bar.

      Frequency Exit Button

    4. In the Scheduler panel, double-click the Lidar Controller node.

    5. In the Scheduler bar, select Use ClockSource frequency.

    6. Select the exit icon to close the Scheduler bar.

    7. In the System Graph window, select Save Asset to save your changes.

      Save Asset

    Create the sensor

    After you have completed the setup of the system graph for your 2D sensor, you can now create the sensor for the scene.

    To create the sensor:

    1. In the Hierarchy window, right-click and select Create Empty.

    2. Name the GameObject 2D Lidar.

    3. Right-click the 2D Lidar GameObject and select 3D Object > Capsule to create a child GameObject.

    4. Select the Capsule GameObject and in the Transform component, set the Scale to 0.2 for X, Y, and Z.

      Note

      If the scale isn't set correctly, the sensor will scan the interior of the capsule.

      Sensor Transform

    Configure the sensor

    1. Select the 2D Lidar GameObject.

    2. With it selected, click Add Component in the Inspector window, then select System Graph Component.

    3. In the System Graph Component, select System Graph Asset and attach the 2DLidarTest system graph.

    4. Select the Capsule GameObject.

    5. Select Add Component, then select Camera Sensing Component.

      Note

      The Camera Sensing Component must be set on the moving part of the Lidar. In this tutorial, it’s the Capsule GameObject.

    Bind the system graph components

    In the System Graph Component of the 2D Lidar GameObject, under Bindings, do the following:

    1. Bind the 2D Lidar GameObject to the following:
      • Photosensor v2 > Reference frame
      • Point cloud viewer > Transform
    2. Bind the Capsule GameObject to the following:
      • Photosensor v2 > Sensing
      • DC Motor > Object to move

    System Graph Component

    Test your sensor

    After completing the above steps, your sensor should now be ready to test. Create some GameObjects around the 2D Lidar for the sensor to hit.

    Getting Started Scene

    The following steps will help to verify all components are working on your 2D Lidar:

    1. In the Hierarchy window, right-click and select 3D Object > Cube.

    2. Select the following GameObjects, and change the Position in the Transform component to the following:

      GameObject X axis Y axis Z axis
      Cube 0.25 0 -2.5
      2D Lidar 0.5 0.15 -6.5
      Main Camera 0 0.7 -8
    3. Enter Play mode.

    If the setup is correct, the Game view should look like this:

    Getting Started Scene

    Select the Capsule GameObject in the Hierarchy window. If the point cloud is visible and there is constant movement on the Y axis of the Rotation transform in the Inspector window, then the simulation is working.

    Getting Started Scene

    Congratulations on your first custom sensor emulation on Unity SensorSDK!

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)