Refactoring RPLidar S3 Driver: From Vendor SDK to Modern ROS2 Node (Part 1)
Why I decided to refactor the official RPLidar SDK. A deep dive into issues with vendor-provided robotics software and the plan to modernize it.
Opening
Problem Identification
While employing the RPLidar S3 in a production environment, I discovered a critical issue: it lacks support for ROS2 Lifecycle management. Upon further inspection of the package directory, I uncovered several other indicators of poor software quality. This experience served as the catalyst for initiating this refactoring project.
The Reality of Vendor-Provided SDKs
One might assume that official code provided by hardware vendors is production-ready. However, relying on it “as-is” is often a mistake. Fundamentally, LiDAR manufacturers are hardware sellers, not software companies. Consequently, it is rare to find vendor-provided code that satisfies modern robotics standards.
Specifically, it is difficult to find an SDK that simultaneously meets the following three criteria:
- Linux Compatibility (Environment)
- ROS2 Native Support (Middleware)
- Modern C++ Standards (Language)
Preliminary Research
Repository Investigation
Before diving into the code, I prioritize gathering background materials. While a comprehensive approach might involve analyzing the vendor’s market presence or community discussions, I will focus solely on the GitHub repository to expedite the process. Reviewing official documentation is invariably the most effective first step.
Analyzing the README
Upon navigating to the repository, the primary task is to examine the README.md. It is crucial to verify that the selected branch matches the target hardware version before proceeding. During this process, I discovered a key detail: the Core SDK is managed in a separate repository from the ROS2 wrapper.
Discrepancy: SDK vs. ROS2 Repository
I noticed an inconsistency in the commit timestamps between the SDK included in the ROS2 repository and the standalone SDK repository. To ascertain the exact differences, I performed a direct code comparison using Meld. The analysis confirmed that the codebases are identical, with the exception of a single line
Profiling the Codebase
The “One-Line” Discrepancy
As mentioned earlier, comparing the two repositories revealed that they were identical except for a single line of code. The difference lies in how nullptr is handled.
1
2
- Result<nullptr_t> ans = SL_RESULT_OK; // Original SDK
+ Result<std::nullptr_t> ans = SL_RESULT_OK; // ROS2 Version
The ROS2 repository incorporates std::nullptr_t, which complies with Modern C++ standards. Conversely, the original SDK relies on a legacy style, likely causing build warnings or errors on newer compilers commonly used in ROS2 environments (e.g., GCC 11+).
Commit History Analysis
Beyond the code itself, the commit history provides insight into the vendor’s software management maturity:
- Version Control Fragmentation: The lack of synchronization between the SDK and ROS2 repositories suggests that Git is not being used as a centralized version control system.
- Poor Commit Hygiene: Commit messages deviate from standard conventions (e.g., Conventional Commits), often described vaguely as “bug fix” or “maintenance.”
- Irregular Updates: The commit frequency is sporadic, indicating a lack of continuous integration or active development.
Inference
It is highly probable that the ROS2 version was patched ad-hoc by a developer encountering build failures on a modern Linux system, without feeding this improvement back into the main SDK repository. This reinforces the conclusion that the provided software is merely a “demo toolkit” rather than a production-ready driver.
Planning
License Verification
Open-source availability does not imply unrestricted usage. Depending on the specific license terms, usage may be limited to inspection only, or commercial deployment might be prohibited. Fortunately, this SDK is governed by the [BSD-2-Clause License]. This permissive license allows for modification and commercial use, provided that the original copyright notice is retained.
Assessment & Decision
My evaluation concludes that the official code fails to support ROS2 native features (such as Lifecycle management). Furthermore, the code quality is subpar, updates are infrequent, and there is no roadmap for refactoring. While searching for community-maintained alternatives is an option, I have decided to refactor the codebase to strictly adhere to my architectural standards.
Given the context, the official SDK serves merely as a “Reference Implementation.” It is akin to a Swiss Army Knife: designed to demonstrate every hardware feature, but lacking the efficiency and specialization required for a production-level robotics stack.
Preview: Anti-Pattern Analysis & Modern C++ Design
In the next post, I will proceed with the actual implementation:
- Architectural Analysis: Dissecting the hierarchy and intent of the legacy code.
- Problem Identification: Analyzing critical issues within the existing ROS2 node structure.
- Redesign: Re-architecting the driver to comply with Modern C++ and ROS2 Official Standards.


