From 314948be490cf78fe55358974eeb7d2ade1819d0 Mon Sep 17 00:00:00 2001 From: SamerKhshiboun Date: Sun, 31 Mar 2024 06:04:32 +0000 Subject: [PATCH 1/3] revert from installation for foxy distro on ubuntu 20 --- .github/workflows/main.yml | 36 +++++++++++++++---- README.md | 17 ++++++--- realsense2_camera/CMakeLists.txt | 6 +++- realsense2_camera/package.xml | 22 ++++++------ realsense2_camera/src/base_realsense_node.cpp | 7 ++++ realsense2_camera/src/dynamic_params.cpp | 6 +++- 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90de07232c..db9b619f72 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - ros_distro: [rolling, iron, humble] + ros_distro: [rolling, iron, humble, foxy] include: - ros_distro: 'rolling' os: ubuntu-22.04 @@ -33,6 +33,8 @@ jobs: os: ubuntu-22.04 - ros_distro: 'humble' os: ubuntu-22.04 + - ros_distro: 'foxy' + os: ubuntu-20.04 steps: @@ -50,13 +52,27 @@ jobs: cd ${{github.workspace}}/ros2/src/realsense-ros/scripts ./pr_check.sh - - name: build ROS2 + # setup-ros@v0.6 is the last version supporting foxy (EOL) + # setup-ros@v0.7 is needed to support humble/iron/rolling + # so, seperating steps with if conditions + - name: build ROS2 for foxy + if: ${{ matrix.ros_distro == 'foxy' }} + uses: ros-tooling/setup-ros@v0.6 + with: + required-ros-distributions: ${{ matrix.ros_distro }} + - name: build ROS2 for humble/iron/rolling + if: ${{ matrix.ros_distro != 'foxy' }} uses: ros-tooling/setup-ros@v0.7 with: required-ros-distributions: ${{ matrix.ros_distro }} - - name: Build RealSense SDK 2.0 from source + - name: Build RealSense SDK 2.0 (development branch) from source run: | + + # libusb-1.0-0-dev is needed for librealsense build in ubuntu 20.04 + # This apt install command will be ignored in ubuntu 22.04 as libusb-1.0-0-dev already installed there + sudo apt install -y libusb-1.0-0-dev + cd ${{github.workspace}} git clone https://github.com/IntelRealSense/librealsense.git -b development cd librealsense @@ -68,13 +84,13 @@ jobs: sudo make -j10 sudo make install - - name: Build RealSense ROS2 Wrapper - run: | + - name: Build RealSense ROS2 Wrapper from source + run: | echo "source /opt/ros/${{ matrix.ros_distro }}/setup.bash" >> ${{github.workspace}}/.bashrc source ${{github.workspace}}/.bashrc cd ${{github.workspace}}/ros2 echo "================= ROSDEP UPDATE =====================" - rosdep update --rosdistro ${{ matrix.ros_distro }} + rosdep update --rosdistro ${{ matrix.ros_distro }} --include-eol-distros echo "================= ROSDEP INSTALL ====================" rosdep install -i --reinstall --from-path src --rosdistro ${{ matrix.ros_distro }} --skip-keys=librealsense2 -y echo "================== COLCON BUILD ======================" @@ -103,10 +119,16 @@ jobs: cd ${{github.workspace}}/ros2 source ${{github.workspace}}/.bashrc . install/local_setup.bash + # the next command might be needed for foxy distro, since this package is not installed + # by default in ubuntu 20.04. For other distro, the apt install command will be ignored. + sudo apt install -y ros-${{matrix.ros_distro}}-sensor-msgs-py python3 src/realsense-ros/realsense2_camera/scripts/rs2_test.py non_existent_file + # don't run integration tests for foxy since some testing dependecies packages like + # tf_ros_py are not avaialble + # TODO: check when we can run integration tests on rolling - name: Run integration tests - if: ${{ matrix.ros_distro != 'rolling'}} + if: ${{ matrix.ros_distro != 'rolling' && matrix.ros_distro != 'foxy' }} run: | cd ${{github.workspace}}/ros2 source ${{github.workspace}}/.bashrc diff --git a/README.md b/README.md index c5b8abf6a4..529ae1fbc0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ [![rolling][rolling-badge]][rolling] [![iron][iron-badge]][iron] [![humble][humble-badge]][humble] +[![foxy][foxy-badge]][foxy] [![ubuntu22][ubuntu22-badge]][ubuntu22] [![ubuntu20][ubuntu20-badge]][ubuntu20] @@ -90,12 +91,15 @@ - #### Ubuntu 22.04: - [ROS2 Iron](https://docs.ros.org/en/iron/Installation/Ubuntu-Install-Debians.html) - [ROS2 Humble](https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html) + #### Ubuntu 20.04 + - [ROS2 Foxy](https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html)
Step 2: Install latest Intel® RealSense™ SDK 2.0 + **Please choose only one option from the 3 options below (in order to prevent multiple versions installation and workspace conflicts)** - #### Option 1: Install librealsense2 debian package from Intel servers @@ -103,7 +107,7 @@ - Otherwise, install from [Linux Debian Installation Guide](https://github.com/IntelRealSense/librealsense/blob/master/doc/distribution_linux.md#installing-the-packages) - In this case treat yourself as a developer: make sure to follow the instructions to also install librealsense2-dev and librealsense2-dkms packages -- #### Option 2: Install librealsense2 (without graphical tools and examples) debian package from ROS servers: +- #### Option 2: Install librealsense2 (without graphical tools and examples) debian package from ROS servers (Foxy EOL distro is not supported by this option): - [Configure](http://wiki.ros.org/Installation/Ubuntu/Sources) your Ubuntu repositories - Install all realsense ROS packages by ```sudo apt install ros--librealsense2*``` - For example, for Humble distro: ```sudo apt install ros-humble-librealsense2*``` @@ -119,7 +123,7 @@ Step 3: Install Intel® RealSense™ ROS2 wrapper -#### Option 1: Install debian package from ROS servers +#### Option 1: Install debian package from ROS servers (Foxy EOL distro is not supported by this option): - [Configure](http://wiki.ros.org/Installation/Ubuntu/Sources) your Ubuntu repositories - Install all realsense ROS packages by ```sudo apt install ros--realsense2-*``` - For example, for Humble distro: ```sudo apt install ros-humble-realsense2-*``` @@ -153,7 +157,7 @@ - Source environment ```bash - ROS_DISTRO= # set your ROS_DISTRO: iron, humble + ROS_DISTRO= # set your ROS_DISTRO: iron, humble, foxy source /opt/ros/$ROS_DISTRO/setup.bash cd ~/ros2_ws . install/local_setup.bash @@ -172,14 +176,17 @@ - #### Windows 10/11 + **Please choose only one option from the two options below (in order to prevent multiple versions installation and workspace conflicts)** + - Manual install from ROS2 formal documentation: - [ROS2 Iron](https://docs.ros.org/en/iron/Installation/Windows-Install-Binary.html) - [ROS2 Humble](https://docs.ros.org/en/humble/Installation/Windows-Install-Binary.html) + - [ROS2 Foxy](https://docs.ros.org/en/foxy/Installation/Windows-Install-Binary.html) - Microsoft IOT binary installation: - https://ms-iot.github.io/ROSOnWindows/GettingStarted/SetupRos2.html - Pay attention that the examples of install are for Foxy distro (which is not supported anymore by RealSense ROS2 Wrapper) - - Please replace the word "Foxy" with Humble or Iron, as you choose + - Please replace the word "Foxy" with Humble or Iron, depends on the chosen distro.
@@ -676,6 +683,8 @@ ros2 launch realsense2_camera rs_intra_process_demo_launch.py intra_process_comm [rolling-badge]: https://img.shields.io/badge/-ROLLING-orange?style=flat-square&logo=ros [rolling]: https://docs.ros.org/en/rolling/index.html +[foxy-badge]: https://img.shields.io/badge/-foxy-orange?style=flat-square&logo=ros +[foxy]: https://docs.ros.org/en/foxy/index.html [humble-badge]: https://img.shields.io/badge/-HUMBLE-orange?style=flat-square&logo=ros [humble]: https://docs.ros.org/en/humble/index.html [iron-badge]: https://img.shields.io/badge/-IRON-orange?style=flat-square&logo=ros diff --git a/realsense2_camera/CMakeLists.txt b/realsense2_camera/CMakeLists.txt index cf2331e611..a838364f8d 100644 --- a/realsense2_camera/CMakeLists.txt +++ b/realsense2_camera/CMakeLists.txt @@ -154,7 +154,11 @@ endif() if(NOT DEFINED ENV{ROS_DISTRO}) message(FATAL_ERROR "ROS_DISTRO is not defined." ) endif() -if("$ENV{ROS_DISTRO}" STREQUAL "humble") +if("$ENV{ROS_DISTRO}" STREQUAL "foxy") + message(STATUS "Build for ROS2 Foxy") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFOXY") + set(SOURCES "${SOURCES}" src/ros_param_backend.cpp) +elseif("$ENV{ROS_DISTRO}" STREQUAL "humble") message(STATUS "Build for ROS2 Humble") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHUMBLE") set(SOURCES "${SOURCES}" src/ros_param_backend.cpp) diff --git a/realsense2_camera/package.xml b/realsense2_camera/package.xml index 6db46cff68..9ff26e3d55 100644 --- a/realsense2_camera/package.xml +++ b/realsense2_camera/package.xml @@ -28,17 +28,17 @@ tf2 tf2_ros diagnostic_updater - ament_cmake_gtest - launch_testing - ament_cmake_pytest - launch_pytest - sensor_msgs_py - python3-numpy - python3-tqdm - sensor_msgs_py - python3-requests - tf2_ros_py - ros2topic + ament_cmake_gtest + launch_testing + ament_cmake_pytest + launch_pytest + sensor_msgs_py + python3-numpy + python3-tqdm + sensor_msgs_py + python3-requests + tf2_ros_py + ros2topic launch_ros ros_environment diff --git a/realsense2_camera/src/base_realsense_node.cpp b/realsense2_camera/src/base_realsense_node.cpp index 4e7a508525..4b88ec7df1 100755 --- a/realsense2_camera/src/base_realsense_node.cpp +++ b/realsense2_camera/src/base_realsense_node.cpp @@ -690,7 +690,14 @@ rclcpp::Time BaseRealSenseNode::frameSystemTimeSec(rs2::frame frame) { double elapsed_camera_ns = millisecondsToNanoseconds(timestamp_ms - _camera_time_base); + /* + Fixing deprecated-declarations compilation error for EOL distro (foxy) + */ +#if defined(FOXY) + auto duration = rclcpp::Duration(elapsed_camera_ns); +#else auto duration = rclcpp::Duration::from_nanoseconds(elapsed_camera_ns); +#endif return rclcpp::Time(_ros_time_base + duration); } diff --git a/realsense2_camera/src/dynamic_params.cpp b/realsense2_camera/src/dynamic_params.cpp index 52a521240d..ef7d73cd9e 100644 --- a/realsense2_camera/src/dynamic_params.cpp +++ b/realsense2_camera/src/dynamic_params.cpp @@ -115,7 +115,11 @@ namespace realsense2_camera try { ROS_DEBUG_STREAM("setParam::Setting parameter: " << param_name); - descriptor.dynamic_typing=true; // Without this, undeclare_parameter() throws error. +#if defined(FOXY) + //do nothing for old versions (foxy) +#else + descriptor.dynamic_typing=true; +#endif if (!_node.get_parameter(param_name, result_value)) { result_value = _node.declare_parameter(param_name, initial_value, descriptor); From d80ccf4c95594eb97245663d0add8a47ebdb9458 Mon Sep 17 00:00:00 2001 From: SamerKhshiboun Date: Sun, 7 Apr 2024 18:35:08 +0000 Subject: [PATCH 2/3] fix compilation warning: stream_type may be used uninitialized --- realsense2_camera/src/ros_sensor.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/realsense2_camera/src/ros_sensor.cpp b/realsense2_camera/src/ros_sensor.cpp index 0c939f0f2d..f0a5aa5331 100644 --- a/realsense2_camera/src/ros_sensor.cpp +++ b/realsense2_camera/src/ros_sensor.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include using namespace realsense2_camera; using namespace rs2; @@ -409,7 +410,7 @@ void RosSensor::set_sensor_auto_exposure_roi() { try { - rs2_stream stream_type; + rs2_stream stream_type = RS2_STREAM_ANY; if (this->rs2::sensor::is()) { stream_type = RS2_STREAM_DEPTH; @@ -418,6 +419,7 @@ void RosSensor::set_sensor_auto_exposure_roi() { stream_type = RS2_STREAM_COLOR; } + assert(stream_type != RS2_STREAM_ANY); int width = std::dynamic_pointer_cast(_profile_managers[0])->getWidth(stream_type); int height = std::dynamic_pointer_cast(_profile_managers[0])->getHeight(stream_type); @@ -451,7 +453,7 @@ void RosSensor::registerAutoExposureROIOptions() if (this->rs2::sensor::is()) { - rs2_stream stream_type; + rs2_stream stream_type = RS2_STREAM_ANY; if (this->rs2::sensor::is()) { stream_type = RS2_STREAM_DEPTH; @@ -460,7 +462,8 @@ void RosSensor::registerAutoExposureROIOptions() { stream_type = RS2_STREAM_COLOR; } - + assert(stream_type != RS2_STREAM_ANY); + int width = std::dynamic_pointer_cast(_profile_managers[0])->getWidth(stream_type); int height = std::dynamic_pointer_cast(_profile_managers[0])->getHeight(stream_type); From a75c2e2a88b1b00bbc1f091965130cbbdc12d090 Mon Sep 17 00:00:00 2001 From: SamerKhshiboun Date: Sun, 7 Apr 2024 18:45:46 +0000 Subject: [PATCH 3/3] fetch string from output substitution object for foxy --- realsense2_camera/launch/rs_launch.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/realsense2_camera/launch/rs_launch.py b/realsense2_camera/launch/rs_launch.py index 0fa7938ae1..bdbdfd0ac8 100644 --- a/realsense2_camera/launch/rs_launch.py +++ b/realsense2_camera/launch/rs_launch.py @@ -98,6 +98,14 @@ def yaml_to_dict(path_to_yaml): def launch_setup(context, params, param_name_suffix=''): _config_file = LaunchConfiguration('config_file' + param_name_suffix).perform(context) params_from_file = {} if _config_file == "''" else yaml_to_dict(_config_file) + + _output = LaunchConfiguration('output' + param_name_suffix) + if(os.getenv('ROS_DISTRO') == 'foxy'): + # Foxy doesn't support output as substitution object (LaunchConfiguration object) + # but supports it as string, so we fetch the string from this substitution object + # see related PR that was merged for humble, iron, rolling: https://github.com/ros2/launch/pull/577 + _output = context.perform_substitution(_output) + return [ launch_ros.actions.Node( package='realsense2_camera', @@ -105,7 +113,7 @@ def launch_setup(context, params, param_name_suffix=''): name=LaunchConfiguration('camera_name' + param_name_suffix), executable='realsense2_camera_node', parameters=[params, params_from_file], - output=LaunchConfiguration('output' + param_name_suffix), + output=_output, arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level' + param_name_suffix)], emulate_tty=True, )