From a553dcce5cf36a8f2c3ce5f424a3cac9e9da1e89 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 09:34:33 +0000 Subject: [PATCH 1/6] Fix fast_lio for jazzy build --- Dockerfile | 5 ++++- patches/apply_patches.sh | 1 + patches/fast_lio.patch | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 patches/fast_lio.patch diff --git a/Dockerfile b/Dockerfile index 8f2efb3..29bcd29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,9 @@ RUN cd ./src/upstream/livox_ros_driver2 && \ ln -sfn launch_ROS2 launch && \ ln -sfn package_ROS2.xml package.xml +RUN cd ./src/upsstream/FAST_LIO && \ + git submodule update --init + # Apply patches to upstream # RUN ./patches/apply_patches.sh @@ -58,7 +61,7 @@ RUN cd src/upstream/livox_sdk && \ # Build the workspace with symlink install RUN . /opt/ros/jazzy/setup.sh && \ colcon build --symlink-install \ - --packages-ignore unitree_lidar_ros2 unitree_lidar_ros unitree_lidar_sdk fast_lio \ + --packages-ignore unitree_lidar_ros2 unitree_lidar_ros unitree_lidar_sdk \ --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy # Source the overlay on container startup diff --git a/patches/apply_patches.sh b/patches/apply_patches.sh index ffc15ac..9347098 100755 --- a/patches/apply_patches.sh +++ b/patches/apply_patches.sh @@ -25,3 +25,4 @@ apply_patch_once() { apply_patch_once "$ROOT_DIR/src/upstream/livox_sdk" "$PATCH_DIR/livox_sdk.patch" apply_patch_once "$ROOT_DIR/src/upstream/slam_gmapping" "$PATCH_DIR/slam_gmapping.patch" +apply_patch_once "$ROOT_DIR/src/upstream/FAST_LIO" "$PATCH_DIR/fast_lio.patch" diff --git a/patches/fast_lio.patch b/patches/fast_lio.patch new file mode 100644 index 0000000..494cbc3 --- /dev/null +++ b/patches/fast_lio.patch @@ -0,0 +1,26 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index be3040b..4931c35 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,17 +5,16 @@ if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) + endif() + +-ADD_COMPILE_OPTIONS(-std=c++14) +-ADD_COMPILE_OPTIONS(-std=c++14) +-set(CMAKE_CXX_FLAGS "-std=c++14 -O3") ++ADD_COMPILE_OPTIONS(-std=c++17) ++set(CMAKE_CXX_FLAGS "-std=c++17 -O3") + + add_definitions(-DROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\") + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions") +-set(CMAKE_CXX_STANDARD 14) ++set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -std=c++0x -std=c++14 -fexceptions") ++set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -fexceptions") + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + message("Current CPU archtecture: ${CMAKE_SYSTEM_PROCESSOR}") From aae2455b68655ba50ac29f0cc221cc864404fb6f Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 10:05:14 +0000 Subject: [PATCH 2/6] Fix unilidar_sdk2 for jazzy colcon build --- Dockerfile | 1 - patches/apply_patches.sh | 1 + patches/unilidar_sdk2.patch | 105 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 patches/unilidar_sdk2.patch diff --git a/Dockerfile b/Dockerfile index 29bcd29..a030010 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,6 @@ RUN cd src/upstream/livox_sdk && \ # Build the workspace with symlink install RUN . /opt/ros/jazzy/setup.sh && \ colcon build --symlink-install \ - --packages-ignore unitree_lidar_ros2 unitree_lidar_ros unitree_lidar_sdk \ --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy # Source the overlay on container startup diff --git a/patches/apply_patches.sh b/patches/apply_patches.sh index 9347098..7063509 100755 --- a/patches/apply_patches.sh +++ b/patches/apply_patches.sh @@ -26,3 +26,4 @@ apply_patch_once() { apply_patch_once "$ROOT_DIR/src/upstream/livox_sdk" "$PATCH_DIR/livox_sdk.patch" apply_patch_once "$ROOT_DIR/src/upstream/slam_gmapping" "$PATCH_DIR/slam_gmapping.patch" apply_patch_once "$ROOT_DIR/src/upstream/FAST_LIO" "$PATCH_DIR/fast_lio.patch" +apply_patch_once "$ROOT_DIR/src/upstream/unilidar_sdk2" "$PATCH_DIR/unilidar_sdk2.patch" diff --git a/patches/unilidar_sdk2.patch b/patches/unilidar_sdk2.patch new file mode 100644 index 0000000..e57c358 --- /dev/null +++ b/patches/unilidar_sdk2.patch @@ -0,0 +1,105 @@ +diff --git a/unitree_lidar_ros2/src/unitree_lidar_ros2/CMakeLists.txt b/unitree_lidar_ros2/src/unitree_lidar_ros2/CMakeLists.txt +index 041ef0d..dd57d47 100644 +--- a/unitree_lidar_ros2/src/unitree_lidar_ros2/CMakeLists.txt ++++ b/unitree_lidar_ros2/src/unitree_lidar_ros2/CMakeLists.txt +@@ -23,16 +23,15 @@ find_package(pcl_conversions REQUIRED) + find_package(PCL REQUIRED) + find_package(tf2_ros REQUIRED) + find_package(sensor_msgs REQUIRED) ++find_package(unitree_lidar_sdk REQUIRED) + + include_directories( + ${PCL_INCLUDE_DIRS} + include +- ../../../unitree_lidar_sdk/include + ) + + link_directories( + ${PCL_LIBRARY_DIRS} +- ../../../unitree_lidar_sdk/lib/${CMAKE_SYSTEM_PROCESSOR} + ) + + add_definitions(${PCL_DEFINITIONS}) +@@ -42,7 +41,6 @@ add_executable(unitree_lidar_ros2_node src/unitree_lidar_ros2_node.cpp) + target_link_libraries( unitree_lidar_ros2_node + ${Boost_SYSTEM_LIBRARY} + ${PCL_LIBRARIES} +- libunilidar_sdk2.a + ) + + ament_target_dependencies( +@@ -52,6 +50,7 @@ ament_target_dependencies( + geometry_msgs + tf2_ros + pcl_conversions ++ unitree_lidar_sdk + ) + + install(TARGETS +diff --git a/unitree_lidar_ros2/src/unitree_lidar_ros2/package.xml b/unitree_lidar_ros2/src/unitree_lidar_ros2/package.xml +index 74539aa..b5febb2 100644 +--- a/unitree_lidar_ros2/src/unitree_lidar_ros2/package.xml ++++ b/unitree_lidar_ros2/src/unitree_lidar_ros2/package.xml +@@ -21,6 +21,7 @@ + + geometry_msgs + tf2_ros ++ unitree_lidar_sdk + + + ament_cmake +diff --git a/unitree_lidar_sdk/CMakeLists.txt b/unitree_lidar_sdk/CMakeLists.txt +index 80af9c9..0d9a334 100644 +--- a/unitree_lidar_sdk/CMakeLists.txt ++++ b/unitree_lidar_sdk/CMakeLists.txt +@@ -1,39 +1,14 @@ +-cmake_minimum_required(VERSION 3.0) ++cmake_minimum_required(VERSION 3.5) + project(unitree_lidar_sdk) + +-set(CMAKE_BUILD_TYPE "Release") +-set(CMAKE_CXX_FLAGS "-std=c++17") +-set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb") +-set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -DNDEBUG") ++find_package(ament_cmake REQUIRED) + +-include_directories(include) ++# Install the SDK headers and the architecture-specific prebuilt static library. ++install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME}) ++install(FILES lib/${CMAKE_SYSTEM_PROCESSOR}/libunilidar_sdk2.a DESTINATION lib) + +-link_directories(lib/${CMAKE_SYSTEM_PROCESSOR}) ++# Export them so ament packages can consume the SDK via find_package(). ++ament_export_include_directories(include/${PROJECT_NAME}) ++ament_export_libraries(unilidar_sdk2) + +-SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/${CMAKE_SYSTEM_PROCESSOR}) +- +-add_executable(example_lidar_udp +- examples/example_lidar_udp.cpp +-) +-target_link_libraries(example_lidar_udp libunilidar_sdk2.a ) +- +-add_executable(example_lidar_serial +- examples/example_lidar_serial.cpp +-) +-target_link_libraries(example_lidar_serial libunilidar_sdk2.a ) +- +-add_executable(set_ip_address +- examples/set_ip_address.cpp +-) +-target_link_libraries(set_ip_address libunilidar_sdk2.a ) +- +-add_executable(set_to_serial_mode +- examples/set_to_serial_mode.cpp +-) +-target_link_libraries(set_to_serial_mode libunilidar_sdk2.a ) +- +-add_executable(set_to_udp_mode +- examples/set_to_udp_mode.cpp +-) +-target_link_libraries(set_to_udp_mode libunilidar_sdk2.a ) +\ No newline at end of file ++ament_package() +\ No newline at end of file From 54f71524f586d69880de67f7612dda28d623b0bb Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 10:23:25 +0000 Subject: [PATCH 3/6] Patch to add symlinks to livox_ros_driver2 --- Dockerfile | 19 +++---------------- patches/apply_patches.sh | 1 + patches/livox_ros_driver2.patch | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 patches/livox_ros_driver2.patch diff --git a/Dockerfile b/Dockerfile index a030010..01bd2e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,27 +8,14 @@ COPY src ./src/ COPY patches ./patches/ COPY upstream.jazzy.repos ./upstream.jazzy.repos -# Stage any dual ROS1/ROS2 packages (e.g. livox_ros_driver2) for ROS2 without -# modifying their upstream source: generate package.xml from package_ROS2.xml so -# colcon can discover them. The ROS2 build is selected via -DROS_EDITION below. -# RUN for d in $(find /ros2_ws/src -type f -name package_ROS2.xml -exec dirname {} \;); do \ -# cp -f "$d/package_ROS2.xml" "$d/package.xml"; \ -# done - # Import all upstream repostories RUN vcs import ./src/upstream < ./upstream.jazzy.repos -# Fixup the livox package for ros2 build -RUN cd ./src/upstream/livox_ros_driver2 && \ - rm -rf launch package.xml && \ - ln -sfn launch_ROS2 launch && \ - ln -sfn package_ROS2.xml package.xml - -RUN cd ./src/upsstream/FAST_LIO && \ +RUN cd ./src/upstream/FAST_LIO && \ git submodule update --init # Apply patches to upstream -# RUN ./patches/apply_patches.sh +RUN ./patches/apply_patches.sh # system deps from frozen rosdep manifest — no rosdep at build or startup # NOTE: There should be a check in your CI that this file is up to date. @@ -61,7 +48,7 @@ RUN cd src/upstream/livox_sdk && \ # Build the workspace with symlink install RUN . /opt/ros/jazzy/setup.sh && \ colcon build --symlink-install \ - --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy + li --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy # Source the overlay on container startup RUN echo "source /opt/ros/jazzy/setup.bash" >> /root/.bashrc && \ diff --git a/patches/apply_patches.sh b/patches/apply_patches.sh index 7063509..5bb5c6b 100755 --- a/patches/apply_patches.sh +++ b/patches/apply_patches.sh @@ -27,3 +27,4 @@ apply_patch_once "$ROOT_DIR/src/upstream/livox_sdk" "$PATCH_DIR/livox_sdk.patch" apply_patch_once "$ROOT_DIR/src/upstream/slam_gmapping" "$PATCH_DIR/slam_gmapping.patch" apply_patch_once "$ROOT_DIR/src/upstream/FAST_LIO" "$PATCH_DIR/fast_lio.patch" apply_patch_once "$ROOT_DIR/src/upstream/unilidar_sdk2" "$PATCH_DIR/unilidar_sdk2.patch" +apply_patch_once "$ROOT_DIR/src/upstream/livox_ros_driver2" "$PATCH_DIR/livox_ros_driver2.patch" diff --git a/patches/livox_ros_driver2.patch b/patches/livox_ros_driver2.patch new file mode 100644 index 0000000..44512c9 --- /dev/null +++ b/patches/livox_ros_driver2.patch @@ -0,0 +1,16 @@ +diff --git a/launch b/launch +new file mode 120000 +index 0000000..163fb01 +--- /dev/null ++++ b/launch +@@ -0,0 +1 @@ ++launch_ROS2 +\ No newline at end of file +diff --git a/package.xml b/package.xml +new file mode 120000 +index 0000000..36804a4 +--- /dev/null ++++ b/package.xml +@@ -0,0 +1 @@ ++package_ROS2.xml +\ No newline at end of file From 2e7eba5fc4c7032ada105b05b32eebb94aaa6b78 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 10:42:40 +0000 Subject: [PATCH 4/6] Get fast_lio cmake execute the git submodule init --- Dockerfile | 13 ++----------- patches/fast_lio.patch | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 01bd2e0..2a94d15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,9 +11,6 @@ COPY upstream.jazzy.repos ./upstream.jazzy.repos # Import all upstream repostories RUN vcs import ./src/upstream < ./upstream.jazzy.repos -RUN cd ./src/upstream/FAST_LIO && \ - git submodule update --init - # Apply patches to upstream RUN ./patches/apply_patches.sh @@ -38,17 +35,11 @@ RUN apt-get update && \ rosdep install --from-paths src --ignore-src -r -y && \ rm -rf /var/lib/apt/lists/* -RUN cd src/upstream/livox_sdk && \ - mkdir -p build && \ - cd build && rm -rf * && \ - cmake .. -DCMAKE_BUILD_TYPE=Release && \ - make -j && \ - make install - # Build the workspace with symlink install +# livox_sdk is now an ament_cmake package built by colcon (no manual /usr/local install needed). RUN . /opt/ros/jazzy/setup.sh && \ colcon build --symlink-install \ - li --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy + --cmake-args -DROS_EDITION=ROS2 -DDISTRO_ROS=jazzy # Source the overlay on container startup RUN echo "source /opt/ros/jazzy/setup.bash" >> /root/.bashrc && \ diff --git a/patches/fast_lio.patch b/patches/fast_lio.patch index 494cbc3..3a68c9b 100644 --- a/patches/fast_lio.patch +++ b/patches/fast_lio.patch @@ -1,14 +1,37 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index be3040b..4931c35 100644 +index be3040b..3176847 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -5,17 +5,16 @@ if(NOT CMAKE_BUILD_TYPE) +@@ -5,17 +5,39 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -ADD_COMPILE_OPTIONS(-std=c++14) -ADD_COMPILE_OPTIONS(-std=c++14) -set(CMAKE_CXX_FLAGS "-std=c++14 -O3") ++# Ensure the bundled ikd-Tree submodule (include/ikd-Tree/ikd_Tree.cpp) is present. ++# Auto-initialize it when building from a git checkout; otherwise fail with guidance. ++if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/ikd-Tree/ikd_Tree.cpp") ++ find_package(Git QUIET) ++ if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") ++ message(STATUS "fast_lio: initializing git submodule include/ikd-Tree") ++ execute_process( ++ COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ++ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ++ RESULT_VARIABLE GIT_SUBMOD_RESULT) ++ if(NOT GIT_SUBMOD_RESULT EQUAL "0") ++ message(FATAL_ERROR ++ "git submodule update --init failed with ${GIT_SUBMOD_RESULT}. " ++ "Run it manually in ${CMAKE_CURRENT_SOURCE_DIR}.") ++ endif() ++ endif() ++ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/ikd-Tree/ikd_Tree.cpp") ++ message(FATAL_ERROR ++ "include/ikd-Tree/ikd_Tree.cpp is missing and could not be fetched automatically " ++ "(no git checkout available). Run: git submodule update --init --recursive") ++ endif() ++endif() ++ +ADD_COMPILE_OPTIONS(-std=c++17) +set(CMAKE_CXX_FLAGS "-std=c++17 -O3") From b0dfa63fb73e1a7446b5ddeea610104f21288273 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 11:36:53 +0000 Subject: [PATCH 5/6] Update the livox patches. --- patches/livox_ros_driver2.patch | 12 ++++++++++++ patches/livox_sdk.patch | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/patches/livox_ros_driver2.patch b/patches/livox_ros_driver2.patch index 44512c9..39e0e99 100644 --- a/patches/livox_ros_driver2.patch +++ b/patches/livox_ros_driver2.patch @@ -14,3 +14,15 @@ index 0000000..36804a4 @@ -0,0 +1 @@ +package_ROS2.xml \ No newline at end of file +diff --git a/package_ROS2.xml b/package_ROS2.xml +index 96f5762..c66785b 100644 +--- a/package_ROS2.xml ++++ b/package_ROS2.xml +@@ -28,6 +28,7 @@ + + git + apr ++ livox_sdk2 + + + ament_cmake diff --git a/patches/livox_sdk.patch b/patches/livox_sdk.patch index 3738761..fe33a0f 100644 --- a/patches/livox_sdk.patch +++ b/patches/livox_sdk.patch @@ -1,3 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 05f84c5..4fb6f31 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,7 +1,9 @@ +-cmake_minimum_required(VERSION 3.0) ++cmake_minimum_required(VERSION 3.5) + + project(livox_sdk2) + ++find_package(ament_cmake REQUIRED) ++ + set(CMAKE_CXX_STANDARD 11) + + message(STATUS "main project dir: " ${PROJECT_SOURCE_DIR}) +@@ -18,3 +20,9 @@ endif(UNIX) + + add_subdirectory(sdk_core) + add_subdirectory(samples) ++ ++# Export the installed headers/libraries so ament packages (e.g. livox_ros_driver2) ++# find the SDK from the colcon install space via CMAKE_PREFIX_PATH. ++ament_export_include_directories(include) ++ament_export_libraries(livox_lidar_sdk_shared) ++ament_package() diff --git a/sdk_core/comm/define.h b/sdk_core/comm/define.h index 0872328..28d989b 100644 --- a/sdk_core/comm/define.h From 577453a5533a612f0ca13e3ceae8961a62b679de Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Fri, 17 Jul 2026 14:38:53 +0000 Subject: [PATCH 6/6] Fix patch application in container. --- Dockerfile | 2 +- patches/apply_patches.sh | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a94d15..74233e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY patches ./patches/ COPY upstream.jazzy.repos ./upstream.jazzy.repos # Import all upstream repostories -RUN vcs import ./src/upstream < ./upstream.jazzy.repos +RUN mkdir -p src/upstream && vcs import ./src/upstream < ./upstream.jazzy.repos # Apply patches to upstream RUN ./patches/apply_patches.sh diff --git a/patches/apply_patches.sh b/patches/apply_patches.sh index 5bb5c6b..bd6d339 100755 --- a/patches/apply_patches.sh +++ b/patches/apply_patches.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash set -u -ROOT_DIR="/workspaces/agv_pro_ros2" +PATCH_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(dirname "$PATCH_DIR")" PATCH_DIR="$ROOT_DIR/patches" apply_patch_once() { @@ -23,8 +24,8 @@ apply_patch_once() { || git -C "$target_dir" apply --reverse --check "$patch_file" >/dev/null 2>&1 } -apply_patch_once "$ROOT_DIR/src/upstream/livox_sdk" "$PATCH_DIR/livox_sdk.patch" -apply_patch_once "$ROOT_DIR/src/upstream/slam_gmapping" "$PATCH_DIR/slam_gmapping.patch" apply_patch_once "$ROOT_DIR/src/upstream/FAST_LIO" "$PATCH_DIR/fast_lio.patch" -apply_patch_once "$ROOT_DIR/src/upstream/unilidar_sdk2" "$PATCH_DIR/unilidar_sdk2.patch" +apply_patch_once "$ROOT_DIR/src/upstream/livox_sdk" "$PATCH_DIR/livox_sdk.patch" apply_patch_once "$ROOT_DIR/src/upstream/livox_ros_driver2" "$PATCH_DIR/livox_ros_driver2.patch" +apply_patch_once "$ROOT_DIR/src/upstream/slam_gmapping" "$PATCH_DIR/slam_gmapping.patch" +apply_patch_once "$ROOT_DIR/src/upstream/unilidar_sdk2" "$PATCH_DIR/unilidar_sdk2.patch"