### Connect and Scan with RPLIDAR via Serial Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Example demonstrating how to connect to an RPLIDAR device using a serial port, retrieve device information and health status, start scanning, and process scan data. ```python 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() ``` -------------------------------- ### Running PyRPLidarSDK Examples Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Execute example scripts to demonstrate advanced scanning, data analysis, quality filtering, and obstacle detection. Examples can be run with different connection types (serial or UDP) and custom parameters. ```bash # 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 ``` -------------------------------- ### Install pyrplidarsdk from Source Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Clone the repository and install the package in development mode or build and install it. ```bash # 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 . ``` -------------------------------- ### Install pyrplidarsdk from PyPI Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Use this command to install the latest version of the pyrplidarsdk package from the Python Package Index. ```bash pip install pyrplidarsdk ``` -------------------------------- ### Connect to RPLIDAR via UDP Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Example demonstrating how to create a driver instance for a UDP connection to an RPLIDAR device. The subsequent connection and scanning logic remains the same as for serial connections. ```python import pyrplidarsdk # Create driver instance for UDP connection driver = pyrplidarsdk.RplidarDriver(ip_address="192.168.1.100") # Rest of the code is the same... ``` -------------------------------- ### PyRPLidarSDK Project Structure Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Overview of the PyRPLidarSDK project directory layout, highlighting the Python package, C++ wrappers, example scripts, and build configuration files. ```text 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 ``` -------------------------------- ### DeviceInfo Structure Source: https://pypi.org/project/pyrplidarsdk Structure containing device information. ```APIDOC ## DeviceInfo Structure ### Description Device information structure. ### Fields - **model** (int): Device model number - **firmware_version** (int): Firmware version - **hardware_version** (int): Hardware version - **serial_number** (str): Device serial number (hex string) ``` -------------------------------- ### DeviceInfo Structure Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Structure for holding RPLIDAR device information. ```APIDOC ## DeviceInfo Structure ### Description Structure for holding RPLIDAR device information. ### Fields - **model** (int): Device model number - **firmware_version** (int): Firmware version - **hardware_version** (int): Hardware version - **serial_number** (str): Device serial number (hex string) ``` -------------------------------- ### Scan Analysis and Obstacle Detection Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Compute statistical summaries of scan data, detect potential obstacles within defined parameters, and find the closest or farthest points in a scan. These utilities are useful for understanding the environment and identifying specific features. ```python 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) ``` -------------------------------- ### RplidarDriver Constructor Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Initializes the RplidarDriver for connecting to RPLIDAR devices via serial or UDP. ```APIDOC ## RplidarDriver Constructor ### Description Initializes the RplidarDriver for connecting to RPLIDAR devices via serial or UDP. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Constructor ### Endpoint N/A ### Parameters - **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) ### Request Example ```python # Serial connection driver = pyrplidarsdk.RplidarDriver(port="/dev/ttyUSB0") # UDP connection driver = pyrplidarsdk.RplidarDriver(ip_address="192.168.1.100") ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A ``` -------------------------------- ### RplidarDriver Methods Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Methods for controlling RPLIDAR devices and retrieving data. ```APIDOC ## RplidarDriver Methods ### connect() #### Description Connects to the RPLIDAR device. #### Method `connect` #### Parameters None #### Return Value - `bool`: True if connection is successful, False otherwise. ### disconnect() #### Description Disconnects from the RPLIDAR device. #### Method `disconnect` #### Parameters None #### Return Value None ### get_device_info() #### Description Retrieves information about the connected RPLIDAR device. #### Method `get_device_info` #### Parameters None #### Return Value - `DeviceInfo | None`: An object containing device information if successful, otherwise None. ### get_health() #### Description Retrieves the health status of the RPLIDAR device. #### Method `get_health` #### Parameters None #### Return Value - `DeviceHealth | None`: An object containing device health status if successful, otherwise None. ### start_scan() #### Description Starts the laser scanning process on the RPLIDAR device. #### Method `start_scan` #### Parameters None #### Return Value - `bool`: True if scanning started successfully, False otherwise. ### stop_scan() #### Description Stops the laser scanning process on the RPLIDAR device. #### Method `stop_scan` #### Parameters None #### Return Value None ### get_scan_data() #### Description Retrieves the latest scan data from the RPLIDAR device. #### Method `get_scan_data` #### Parameters None #### Return Value - `tuple[list[float], list[float], list[int]] | None`: A tuple containing lists of angles, ranges, and qualities if data is available, otherwise None. ``` -------------------------------- ### Data Conversion and Processing Utilities Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Utilize these functions for converting between coordinate systems (polar to Cartesian and vice-versa), changing angle units, converting data to NumPy arrays, smoothing noisy range data, and downsampling scans. Ensure necessary data (angles, ranges, qualities) is available. ```python 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) ``` -------------------------------- ### DeviceHealth Structure Source: https://pypi.org/project/pyrplidarsdk Structure containing device health information. ```APIDOC ## DeviceHealth Structure ### Description Device health information. ### Fields - **status** (int): Health status code - **error_code** (int): Error code if any ``` -------------------------------- ### Filtering and Quality Control Utilities Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Apply these filters to refine LIDAR data based on distance range, signal quality, or angular sector. These functions help in isolating relevant data points for further analysis. ```python 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) ``` -------------------------------- ### DeviceHealth Structure Source: https://pypi.org/project/pyrplidarsdk/0.1.2 Structure for holding RPLIDAR device health information. ```APIDOC ## DeviceHealth Structure ### Description Structure for holding RPLIDAR device health information. ### Fields - **status** (int): Health status code - **error_code** (int): Error code if any ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.