RoboSense rslidar_sdk

repository·main·Indexed 20 days ago

https://github.com/robosense-lidar/rslidar_sdk

A specialized SDK for RoboSense LiDAR sensors providing drivers and integration layers for ROS and ROS2 on Ubuntu. It supports a wide range of models including RS-LiDAR-16, RS-LiDAR-32, RS-Bpearl, RS-Helios, RS-Ruby, RS-LiDAR-M series, and others. The SDK supports multiple point cloud data formats (XYZI, XYZIRT, XYZIF, XYZIRTF) and provides functionality for online LiDAR data streaming, packet recording, and legacy rosbag playback support.

Tokens
26.7K
Snippets
78
Records
104
Agent score
71%

What's inside rslidar_sdk

  1. Overview of rslidar_sdk

    main

    rslidar_sdk is a LiDAR driver package for Ubuntu environments provided by RoboSense. It serves two primary purposes:

    1. ROS/ROS2 Integration: Provides extensions for ROS and ROS2 to allow users to visualize point clouds using tools like RViz.
    2. Custom Development: Includes the rs_driver kernel, which can be used as a base if you need to integrate the LiDAR driver into your own custom engineering projects.

    Supported LiDAR Models

    • RS-LiDAR-16, RS-LiDAR-32
    • RS-Bpearl, RS-Helios, RS-Helios-16P
    • RS-Ruby series (128, 80, 48, Plus-128, Plus-80, Plus-48)
    • RS-LiDAR-M series (M1, M2, M3)
    • RS-LiDAR-E1, RS-LiDAR-MX, RS-LiDAR-AIRY, RS-LiDAR-AIRYLITE-ETH, RS-LiDAR-EMX, RS-LiDAR-FAIRY

    Supported Point Types

    • XYZI: x, y, z, intensity
    • XYZIRT: x, y, z, intensity, ring, timestamp
  2. Core functionality of rslidar_sdk

    main

    rslidar_sdk is a ROS/ROS2-based LiDAR driver that relies on rs_driver to receive and parse MSOP/DIFOP packets. Its primary functions include:

    • Point Cloud and IMU Data Generation: Obtains data from live LiDARs or PCAP files and publishes them via ROS topics /rslidar_points and /rslidar_imu_data.
    • Raw Packet Publishing: Obtains raw MSOP/DIFOP/IMU packets from live LiDARs and publishes them via the /rslidar_packets topic (useful for recording to rosbag).
    • Packet-to-PointCloud Conversion: Receives MSOP/DIFOP/IMU packets from the /rslidar_packets topic (e.g., replaying a rosbag), parses them, and publishes the resulting point clouds to /rslidar_points.
  3. Understand the structure of config.yaml

    main

    The rslidar_sdk uses a configuration file named config.yaml located in rslidar_sdk/config. This file is indentation sensitive.

    It is structured into two main sections:

    1. common: Contains settings shared by all LiDARs in the system (e.g., data source, global publishing settings).
    2. lidar: A list of child nodes where each node contains specific configuration for an individual LiDAR device.

    This structure allows rslidar_sdk to support multi-LiDAR setups by defining global behavior once and individual hardware parameters per device.

    common:
      msg_source: 1
      send_packet_ros: false
      send_point_cloud_ros: false
    
    lidar:
      - driver:
          lidar_type: RSM1
          msop_port: 6699
          # ... other lidar specific settings
        ros:
          ros_frame_id: rslidar
  4. Supported LiDAR models and Point Types

    main

    rslidar_sdk supports a wide range of RoboSense LiDAR models and two specific point cloud data formats.

    Supported LiDAR Models:

    • RS-LiDAR-16, RS-LiDAR-32
    • RS-Bpearl, RS-Helios, RS-Helios-16P
    • RS-Ruby series (128, 80, 48, and Plus variants)
    • RS-LiDAR-M series (M1, M2, M3)
    • RS-LiDAR-E1, RS-LiDAR-MX, RS-LiDAR-AIRY, RS-LiDAR-AIRYLITE-ETH, RS-LiDAR-EMX, RS-LiDAR-FAIRY

    Supported Point Types:

    • XYZI: x, y, z, intensity
    • XYZIRT: x, y, z, intensity, ring, timestamp
  5. How SourceDriver processes LiDAR and PCAP data

    main

    The SourceDriver is the primary implementation for SourceType::MSG_FROM_LIDAR and SourceType::MSG_FROM_PCAP. It manages the lifecycle of data from the rs_driver (LidarDriver) to the destinations.

    Key Workflow:

    1. Initialization: init() reads the YAML config, creates the appropriate LidarDriver instance, and starts two dedicated processing threads: point_cloud_handle_thread_ and imu_data_process_thread_.
    2. Data Ingestion: The driver uses getPointCloud() and getImuData() to manage memory via free/pending queues. When the driver fills a buffer, it calls putPointCloud() or putImuData() to queue the data.
    3. Processing:
      • processPointCloud(): Pulls from the queue and calls sendPointCloud() on all registered DestinationPointCloud instances.
      • processImuData(): Pulls from the queue and calls sendImuData() on all registered DestinationPointCloud instances.
    4. Packet Handling: Packets are retrieved on-demand. When a DestinationPacket is registered via regPacketCallback(), the driver starts receiving packets via putPacket().
  6. How SourcePacketRos converts ROS packets to PointClouds

    main

    The SourcePacketRos class is used when the input source is a ROS topic (SourceType::MSG_FROM_ROS_PACKET). It inherits from SourceDriver to leverage its parsing capabilities.

    Workflow:

    1. Initialization: init() sets the source type to MSG_FROM_ROS_PACKET. This configures the underlying LidarDriver to use InputType::RAW_PACKET and receive data via feedPacket.
    2. Subscription: It creates a ROS subscriber (pkt_sub_) to the topic specified in the YAML (default: /rslidar_packets).
    3. Parsing: When a packet is received via putPacket(), it is passed to LidarDriver::decodePacket(). The SourceDriver logic then handles the resulting point cloud and IMU data generation as usual.
  7. Manage multiple data sources with NodeManager

    main

    The NodeManager is the top-level controller that manages one or more Source instances. All sources managed by a single NodeManager must be of the same type.

    Configuration via config.yaml:

    • msg_source: Defines the source type (MSG_FROM_LIDAR, MSG_FROM_ROS_PACKET, or MSG_FROM_PCAP).
    • send_point_cloud_ros: Boolean; if true, creates and registers a DestinationPointCloudRos instance.
    • send_packet_ros: Boolean; if true, creates and registers a DestinationPacketRos instance.

    Lifecycle:

    • init(): Parses the YAML, instantiates the appropriate Source (e.g., SourceDriver or SourcePacketRos), sets up destinations, and adds them to the sources_ array.
    • start(): Iterates through all managed sources_ and calls their start() method.
  8. Understand the Source and Destination abstraction model

    main

    The SDK uses a producer-consumer model based on Source and Destination interfaces:

    • Source: Defines the input interface. It can ingest data from three types:
      • MSG_FROM_LIDAR (1): Live LiDAR hardware.
      • MSG_FROM_ROS_PACKET (2): Packets received via a ROS topic.
      • MSG_FROM_PCAP (3): Data from a PCAP file.
    • DestinationPointCloud: An interface for sending PointCloud and IMU data to a target.
    • DestinationPacket: An interface for sending MSOP/DIFOP packets to a target.

    Data flows from a Source to one or more registered Destination instances via callback vectors (pc_cb_vec_ for point clouds and pkt_cb_vec_ for packets).

    enum SourceType
    {
      MSG_FROM_LIDAR = 1,
      MSG_FROM_ROS_PACKET = 2,
      MSG_FROM_PCAP = 3,
    };
  9. Manage LiDAR frame splitting modes

    main

    The split_frame_mode parameter controls how LiDAR frames are partitioned.

    • 1: Split frames based on the split_angle (in degrees).
    • 2: Split frames based on a fixed number of blocks.
    • 3: Split frames based on the num_blks_split parameter.

    Related Parameters:

    • split_angle: Used only when split_frame_mode = 1.
    • num_blks_split: Used only when split_frame_mode = 3.
  10. Connect to an online LiDAR and stream data to ROS

    main

    To connect to a live (online) LiDAR and stream point cloud data to ROS, you must identify the correct network ports, configure the config.yaml file to source data from the network, and then run the SDK.

    Prerequisites:

    • Ensure the LiDAR is physically connected and your computer's IP address is configured according to the LiDAR user manual.
    • Identify the MSOP and DIFOP port numbers. The default values are typically 6699 and 7788 respectively. You can verify these using tools like Wireshark.
    # Follow the steps in the configuration section to set up config.yaml
    # Then run the program
    ./rslidar_sdk
  11. Configure User and Tail layers in PCAP data

    main

    If custom layers have been added to the MSOP/DIFOP UDP data, the rs_driver can strip them automatically if you provide their sizes in bytes.

    • USER_LAYER: A layer added before the MSOP/DIFOP data. Use user_layer_bytes to specify its size.
    • TAIL_LAYER: A layer added after the MSOP/DIFOP data. Use tail_layer_bytes to specify its size.
    lidar:
      - driver:
          lidar_type: RSAIRY           
          pcap_path: /home/robosense/lidar.pcap
          msop_port: 6699             
          difop_port: 7788
          imu_port: 6688  
          user_layer_bytes: 8
          tail_layer_bytes: 4