From 0174cb599f154f5e1a54291681f07afd4a578c32 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Wed, 22 Apr 2026 11:54:06 +0000 Subject: [PATCH] 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 --- docker-compose.yml | 1 + lidar/Dockerfile | 4 +- lidar/README.md | 96 +++++++++++++++++++++++++ lidar/sllidar_ros2/src/sllidar_node.cpp | 2 +- 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 lidar/README.md diff --git a/docker-compose.yml b/docker-compose.yml index 0094da5..eed8eca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,7 @@ services: context: . dockerfile: lidar/Dockerfile platforms: + - linux/amd64 - linux/arm64 image: raspbot_v2_lidar:latest network_mode: host diff --git a/lidar/Dockerfile b/lidar/Dockerfile index cb1ad42..e4e6279 100644 --- a/lidar/Dockerfile +++ b/lidar/Dockerfile @@ -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 diff --git a/lidar/README.md b/lidar/README.md new file mode 100644 index 0000000..c719b9b --- /dev/null +++ b/lidar/README.md @@ -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 +``` diff --git a/lidar/sllidar_ros2/src/sllidar_node.cpp b/lidar/sllidar_ros2/src/sllidar_node.cpp index 5abfd0f..eedb73a 100644 --- a/lidar/sllidar_ros2/src/sllidar_node.cpp +++ b/lidar/sllidar_ros2/src/sllidar_node.cpp @@ -59,7 +59,7 @@ class SLlidarNode : public rclcpp::Node : Node("sllidar_node") { - scan_pub = this->create_publisher("scan", rclcpp::QoS(rclcpp::KeepLast(10))); + scan_pub = this->create_publisher("scan", rclcpp::QoS(rclcpp::KeepLast(2)).best_effort()); }