Skip to main content

Python wrapper for RPLIDAR SDK using nanobind

Project description

PyRPLIDARSDK

A high-performance Python wrapper for the Slamtec RPLIDAR SDK using nanobind.

PyRPLIDARSDK provides a fast, memory-efficient Python interface to RPLIDAR series 2D laser range scanners, supporting both serial and UDP connections with comprehensive data processing utilities.

Installation

Prerequisites

  • Python 3.10 or higher
  • NumPy
  • C++ compiler with C++17 support (for building from source)

From PyPI

pip install pyrplidarsdk

From Source

# Clone the repository with submodules
git clone --recursive https://github.com/dexmate-ai/pyrplidarsdk.git
cd pyrplidarsdk

# Install in development mode
pip install -e .

# Or build and install
pip install .

Quick Start

Serial Connection

import pyrplidarsdk
import time

# Create driver instance for serial connection
driver = pyrplidarsdk.RplidarDriver(port="/dev/ttyUSB0")

# Connect to the device
if not driver.connect():
    print("Failed to connect!")
    exit(1)

# Get device information
info = driver.get_device_info()
if info:
    print(f"Connected to RPLIDAR model {info.model}")
    print(f"Firmware: {info.firmware_version}")
    print(f"Hardware: {info.hardware_version}")
    print(f"Serial: {info.serial_number}")

# Check device health
health = driver.get_health()
if health:
    print(f"Device health: {health.status}")

# Start scanning
if driver.start_scan():
    print("Scanning started...")
    
    try:
        for i in range(10):  # Get 10 scans
            scan_data = driver.get_scan_data()
            if scan_data:
                angles, ranges, qualities = scan_data
                print(f"Scan {i+1}: {len(angles)} points")
            time.sleep(0.1)
    finally:
        driver.stop_scan()
        driver.disconnect()

UDP Connection

import pyrplidarsdk

# Create driver instance for UDP connection
driver = pyrplidarsdk.RplidarDriver(ip_address="192.168.1.100")

# Rest of the code is the same...

API Reference

RplidarDriver

Main class for controlling RPLIDAR devices.

Constructor

RplidarDriver(port=None, ip_address=None, baudrate=1000000, udp_port=8089)
  • port (str, optional): Serial port path (e.g., "/dev/ttyUSB0", "COM3")
  • ip_address (str, optional): IP address for UDP connection
  • baudrate (int): Serial baudrate (default: 1000000)
  • udp_port (int): UDP port (default: 8089)

Methods

  • connect() -> bool: Connect to the device
  • disconnect(): Disconnect from the device
  • get_device_info() -> DeviceInfo | None: Get device information
  • get_health() -> DeviceHealth | None: Get device health status
  • start_scan() -> bool: Start laser scanning
  • stop_scan(): Stop laser scanning
  • get_scan_data() -> tuple[list[float], list[float], list[int]] | None: Get scan data

DeviceInfo

Device information structure.

  • model (int): Device model number
  • firmware_version (int): Firmware version
  • hardware_version (int): Hardware version
  • serial_number (str): Device serial number (hex string)

DeviceHealth

Device health information.

  • status (int): Health status code
  • error_code (int): Error code if any

Utility Functions

The package includes comprehensive utility functions in pyrplidarsdk.utils for high-performance data processing:

Data Conversion & Processing

from pyrplidarsdk.utils import (
    polar_to_cartesian,
    cartesian_to_polar,
    angles_to_degrees,
    angles_to_radians,
    to_numpy_arrays,
    smooth_ranges,
    downsample_scan
)

# Convert between coordinate systems
x_coords, y_coords = polar_to_cartesian(angles, ranges)
angles_polar, ranges_polar = cartesian_to_polar(x_coords, y_coords)

# Convert angle units
angles_deg = angles_to_degrees(angles)
angles_rad = angles_to_radians(angles_deg)

# Convert to NumPy arrays for efficient processing
angles_np, ranges_np, qualities_np = to_numpy_arrays(angles, ranges, qualities)

# Smooth noisy range data
smoothed_ranges = smooth_ranges(ranges, window_size=5)

# Downsample for reduced data size
downsampled = downsample_scan(angles, ranges, qualities, factor=2)

Filtering & Quality Control

from pyrplidarsdk.utils import (
    filter_by_range,
    filter_by_quality,
    filter_by_angle
)

# Filter by distance range
filtered = filter_by_range(angles, ranges, qualities, min_range=0.1, max_range=12.0)

# Filter by quality threshold
high_quality = filter_by_quality(angles, ranges, qualities, min_quality=50)

# Filter by angular sector
sector_data = filter_by_angle(angles, ranges, qualities, min_angle=0, max_angle=180)

Analysis & Detection

from pyrplidarsdk.utils import (
    compute_scan_statistics,
    detect_obstacles,
    find_closest_point,
    find_farthest_point
)

# Compute comprehensive statistics
stats = compute_scan_statistics(angles, ranges, qualities)
print(f"Mean range: {stats['mean_range']:.2f}m")
print(f"Valid points: {stats['valid_points']}")

# Detect obstacles within specified parameters
obstacles = detect_obstacles(
    angles, ranges, qualities,
    min_distance=0.2,
    max_distance=2.0,
    min_angle=-45,
    max_angle=45,
    min_quality=30
)

# Find closest and farthest points
closest = find_closest_point(angles, ranges, qualities)
farthest = find_farthest_point(angles, ranges, qualities)

Examples

The examples/ directory contains comprehensive demonstrations:

  • simple_scan.py: Advanced scanning with data analysis, quality filtering, and obstacle detection
  • realtime_plot.py: Real-time visualization of LIDAR data with matplotlib

Run examples with:

# Basic scanning
python examples/simple_scan.py --port /dev/ttyUSB0

# With analysis and obstacle detection
python examples/simple_scan.py --port /dev/ttyUSB0 --analysis --detect-obstacles

# UDP connection with custom parameters
python examples/simple_scan.py --ip 192.168.1.100 --min-quality 50 --max-range 10.0

Project Structure

pyrplidarsdk/
├── pyrplidarsdk/          # Python package
│   ├── __init__.py        # Package initialization and exports
│   └── utils.py           # Vectorized NumPy utilities for data processing
├── src/                   # C++ source files
│   └── rplidar_wrapper.cpp # nanobind wrapper for RPLIDAR SDK
├── rplidar_sdk/           # RPLIDAR SDK submodule
├── examples/              # Example scripts
│   ├── simple_scan.py     # Advanced scanning example
│   └── realtime_plot.py   # Real-time visualization
└── CMakeLists.txt         # Build configuration

Performance Features

  • nanobind Integration: Minimal overhead Python-C++ bindings
  • Vectorized Operations: NumPy-based utilities for efficient batch processing
  • Zero-Copy Data Transfer: Direct memory sharing between C++ and Python where possible
  • Optimized Data Structures: Efficient handling of large scan datasets
  • Multi-platform Support: Linux (x86_64, aarch64) with planned Windows/macOS support

License

MIT License - see LICENSE file for details.

Support

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

Acknowledgments

  • Slamtec for the comprehensive RPLIDAR SDK
  • nanobind for the excellent Python-C++ binding framework
  • The open-source robotics community for continuous feedback and support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (106.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (100.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (106.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (100.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (107.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (101.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (107.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (101.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d51cd8fc02e480701d069526be193f2040643d7b1033dab096ffefccd9b6538b
MD5 a97c12cbe9fe830f574a7a6c36987cbe
BLAKE2b-256 cc5b468dda201b1dc1286e0e8034cf1de0a6750062160e5e526be1794f0efb42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5f02f671ddb5474dde64a8c81c60724ee8ecdd26df964dbf600a32bdc92782ae
MD5 e46a59a2acc1ccd5aed7a79f87bfdc7b
BLAKE2b-256 fe1b743007b0f19581a27752f1f281d2ba49898a9713a8a09547e4a735bb15d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ce8a394ce721b7c7bccff9a8a378e85018a57658cca52c2889e1d19626cfdcc
MD5 3c197c82bfa327a1610b6bb5818b1efb
BLAKE2b-256 de746cf0f5540ea1cf7b34bd42b4ac1c18529aca2829ab161121bf63a61cf6f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2a5a9069cbb3cd131fc7ae4f44b0700c213e9221ec871ee81cfe1e0a55643d93
MD5 3fc86b718ff69c1492da4dce063851d5
BLAKE2b-256 e92c2e56a91b101a7582912126e3022c4d55643ff6c7e510d1984aa9987bf318

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5db887a5220b6ab1994f9010b6011ce42a16b00fede877969184ba6c18d3e14
MD5 19542ac67ecafde1c06f1f7d7b1c2b94
BLAKE2b-256 060a33495f0e5e476cf214792880892a587a0804617ee3581fa5153666cf1871

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f52cfba110b40ce0575b7062103f8ab21307f9c907a603e4fb61bafd5da9b070
MD5 517970b23555444e76fb2bacb2f02eaa
BLAKE2b-256 e762c010a4c37b0674416d85002b77e01ce53e80625dc6bbadd91986d86d0c66

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ff55062ef97880b30af1bc17223255af6c80284c97c9a03b84040fe82c8b087d
MD5 c92adcad0db76feb9820506f2b428dfb
BLAKE2b-256 4b904a3d420316f242126e6712819c5c7f918dc50e80b5c64c6da5457d53797b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 86de4dafb2aee158afe252b4556759e8417e41994aa036acf37259465423d2da
MD5 890652ffca1dddcde0ef53f563b8d392
BLAKE2b-256 e6c75e8a3ef91e6494c1efc5453ae8470a35d3c956dc27ab099b09fbd35fac33

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrplidarsdk-0.1.2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: pypi.yml on dexmate-ai/pyrplidarsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page