Manage sllidar_ros2 as a git subtree and apply QoS fix

- Add m5p3nc3r/sllidar_ros2 fork as a git subtree at lidar/sllidar_ros2/
- Dockerfile now COPYs source from the workspace instead of cloning at
  build time; git is no longer a build dependency
- Set /scan publisher QoS to BEST_EFFORT (depth 2) for Nav2/RViz2 compat
- Add lidar/README.md documenting the subtree workflow
- Remove lidar/sllidar_ros2/ from .gitignore (no longer needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 11:54:06 +00:00
parent 3304573d28
commit 0174cb599f
4 changed files with 100 additions and 3 deletions
+1
View File
@@ -23,6 +23,7 @@ services:
context: .
dockerfile: lidar/Dockerfile
platforms:
- linux/amd64
- linux/arm64
image: raspbot_v2_lidar:latest
network_mode: host
+2 -2
View File
@@ -7,12 +7,12 @@ SHELL ["/bin/bash", "-c"]
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-colcon-common-extensions \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /ws
RUN git clone --depth 1 https://github.com/slamtec/sllidar_ros2.git src/sllidar_ros2
# Source is managed as a git subtree — copy directly from the workspace
COPY lidar/sllidar_ros2/ src/sllidar_ros2/
RUN source /opt/ros/${ROS_DISTRO}/setup.bash && \
colcon build --packages-select sllidar_ros2
+96
View File
@@ -0,0 +1,96 @@
# RPLIDAR A1 — LIDAR Container
ROS 2 container for the Slamtec RPLIDAR A1, built on top of a fork of the
official `sllidar_ros2` driver.
---
## How the build works
The driver source lives in `lidar/sllidar_ros2/` as a **git subtree** of this
repository. The [Dockerfile](Dockerfile) copies it directly from the
workspace — no network access is required at build time.
```
Workspace repo Docker build
────────────────────────── ──────────────────────────────────────────
lidar/sllidar_ros2/ ───> COPY lidar/sllidar_ros2/ src/sllidar_ros2/
(git subtree of fork) colcon build --packages-select sllidar_ros2
```
The upstream fork is maintained at:
https://github.com/m5p3nc3r/sllidar_ros2
---
## Development workflow
### Pulling upstream changes into the workspace
```bash
git subtree pull --prefix=lidar/sllidar_ros2 sllidar_ros2 main --squash
```
This fetches the latest commits from the fork, squashes them into a single
merge commit, and updates `lidar/sllidar_ros2/` in the workspace.
### Making local changes
Edit files inside `lidar/sllidar_ros2/` as normal, then commit them to the
workspace repo:
```bash
git add lidar/sllidar_ros2/
git commit -m "lidar: describe the change"
```
### Pushing changes back to the fork
```bash
git subtree push --prefix=lidar/sllidar_ros2 sllidar_ros2 main
```
This replays only the commits that touched `lidar/sllidar_ros2/` and pushes
them to the fork's `main` branch.
### First-time setup on a fresh clone
The subtree files are committed in the workspace repo, so a `git clone` of
this repo is all that is needed — there is no separate step to initialise the
subtree. To be able to pull or push to the fork later, add the remote:
```bash
git remote add sllidar_ros2 https://github.com/m5p3nc3r/sllidar_ros2.git
```
---
## Changes relative to upstream
| File | Change |
|---|---|
| `src/sllidar_node.cpp` | `/scan` publisher QoS set to `BEST_EFFORT` with depth 2. Required for compatibility with Nav2 and RViz2, which subscribe to `/scan` with `BEST_EFFORT`. The upstream default (`RELIABLE`) causes those consumers to receive no data. |
The upstream Slamtec repository is at:
https://github.com/slamtec/sllidar_ros2
---
## Published topics
| Topic | Type | Description |
|---|---|---|
| `/scan` | `sensor_msgs/LaserScan` | 360° laser scan, `BEST_EFFORT` QoS, depth 2 |
## Device
The RPLIDAR A1 connects via USB serial at `/dev/ttyUSB0` (default), 115200 baud.
The container receives access to that device via the `devices` mapping in
[docker-compose.yml](../docker-compose.yml). To use a different port, set
`LIDAR_PORT` in your `.env` file:
```bash
LIDAR_PORT=/dev/ttyUSB1
```
+1 -1
View File
@@ -59,7 +59,7 @@ class SLlidarNode : public rclcpp::Node
: Node("sllidar_node")
{
scan_pub = this->create_publisher<sensor_msgs::msg::LaserScan>("scan", rclcpp::QoS(rclcpp::KeepLast(10)));
scan_pub = this->create_publisher<sensor_msgs::msg::LaserScan>("scan", rclcpp::QoS(rclcpp::KeepLast(2)).best_effort());
}