RPLidar

Namespace: RpLidar.NET

High-level wrapper that auto-connects, resets, and starts scanning on construction.

Table of Contents

  1. Definition
  2. Constructors
    1. RPLidar(string serialport, int baudrate = 115200)
  3. Events
    1. LidarPointScanEvent
  4. Methods
    1. Stop()
    2. Dispose()
  5. Remarks
  6. See Also

Definition

public class RPLidar : IDisposable

RPLidar wraps RpLidarSerialDevice with sensible defaults. Construction immediately connects to the sensor and begins scanning using ScanMode.Sensitivity. Call Dispose() (or use a using statement) to stop the motor and close the serial port.


Constructors

RPLidar(string serialport, int baudrate = 115200)

Creates a new RPLidar, connects to the sensor, and starts scanning.

Parameter Type Default Description
serialport string Serial port name, e.g. "COM3" or "/dev/ttyUSB0"
baudrate int 115200 Baud rate. RPLidar sensors default to 115 200.

Example

using var lidar = new RPLidar("COM3");
// Scanning has already begun

The constructor is blocking during the initial reset and calibration sequence. Expect ~1–2 seconds before the first LidarPointScanEvent fires.


Events

LidarPointScanEvent

public event LidarPointScanEvenHandler LidarPointScanEvent;

Fired approximately every 400 ms (default ElapsedMilliseconds) with a list of LidarPoint measurements from the current sweep.

Signature

delegate void LidarPointScanEvenHandler(List<LidarPoint> points);
Parameter Type Description
points List<LidarPoint> All measurements in the current event window. Some may have IsValid = false.

Example

lidar.LidarPointScanEvent += points =>
{
    var valid = points.Where(p => p.IsValid).ToList();
    Console.WriteLine($"{valid.Count} valid points this sweep");
};

Methods

Stop()

public void Stop()

Stops the scan and the motor. After calling Stop(), no further events will fire. You may call Dispose() afterwards.


Dispose()

public void Dispose()

Stops scanning, stops the motor, and releases the serial port. Called automatically at the end of a using block.


Remarks

  • RPLidar always uses ScanMode.Sensitivity. For other scan modes or advanced settings, use RpLidarSerialDevice directly.
  • The underlying serial thread is a background thread; your application will exit cleanly even if you forget to call Dispose().
  • All event callbacks are raised on the background scan thread. Marshal to the UI thread if updating UI controls.

See Also


Copyright © 2024 Asheesh Maheshwari. Distributed under the MIT license.

This site uses Just the Docs, a documentation theme for Jekyll.