RPLidar
Namespace: RpLidar.NET
High-level wrapper that auto-connects, resets, and starts scanning on construction.
Table of Contents
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
RPLidaralways usesScanMode.Sensitivity. For other scan modes or advanced settings, useRpLidarSerialDevicedirectly.- 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
- RpLidarSerialDevice — full low-level control
- LidarPoint — the measurement data type
- LidarSettings — configuring scan mode, PWM, and intervals