diff --git a/README.md b/README.md index 6bfa8e1f93..73f710315d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ * [Installation](#installation) * [Usage](#usage) * [Starting the camera node](#start-camera-node) + * [Camera name and namespace](#camera-name-and-namespace) * [Parameters](#parameters) * [ROS2-vs-Optical Coordination Systems](#coordination) * [TF from coordinate A to coordinate B](#tfs) @@ -183,6 +184,74 @@
+

+ Camera Name And Camera Namespace +

+ +### Usage +User can set the camera name and camera namespace, to distinguish between cameras and platforms, which helps identifying the right nodes and topics to work with. + +### Example +- If user have multiple cameras (might be of the same model) and multiple robots then user can choose to launch/run his nodes on this way. +- For the first robot and first camera he will run/launch it with these parameters: + - camera_namespace: + - robot1 + - camera_name + - D455_1 + + - With ros2 launch (via command line or by editing these two parameters in the launch file): + + ```ros2 launch realsense2_camera rs_launch.py camera_namespace:=robot1 camera_name:=D455_1``` + + - With ros2 run (using remapping mechanisim [Reference](https://docs.ros.org/en/humble/How-To-Guides/Node-arguments.html)): + + ```ros2 run realsense2_camera realsense2_camera_node --ros-args -r __node:=D455_1 -r __ns:=robot1``` + + - Result + ``` + > ros2 node list + /robot1/D455_1 + + > ros2 topic list + /robot1/D455_1/color/camera_info + /robot1/D455_1/color/image_raw + /robot1/D455_1/color/metadata + /robot1/D455_1/depth/camera_info + /robot1/D455_1/depth/image_rect_raw + /robot1/D455_1/depth/metadata + /robot1/D455_1/extrinsics/depth_to_color + /robot1/D455_1/imu + + > ros2 service list + /robot1/D455_1/device_info + ``` + +### Default behavior if non of these parameters are given: + - camera_namespace:=camera + - camera_name:=camera + +``` +> ros2 node list +/camera/camera + +> ros2 topic list +/camera/camera/color/camera_info +/camera/camera/color/image_raw +/camera/camera/color/metadata +/camera/camera/depth/camera_info +/camera/camera/depth/image_rect_raw +/camera/camera/depth/metadata +/camera/camera/extrinsics/depth_to_color +/camera/camera/imu + +> ros2 service list +/camera/camera/device_info +``` + + +
+ +

Parameters

@@ -268,7 +337,6 @@ - On occasions the device was not closed properly and due to firmware issues needs to reset. - If set to true, the device will reset prior to usage. - For example: `initial_reset:=true` -- ****_frame_id**, ****_optical_frame_id**, **aligned_depth_to_**_frame_id**: Specify the different frame_id for the different frames. Especially important when using multiple cameras. - **base_frame_id**: defines the frame_id all static transformations refers to. - **unite_imu_method**: diff --git a/realsense2_camera/CMakeLists.txt b/realsense2_camera/CMakeLists.txt index 96c51f249d..503db8d57c 100644 --- a/realsense2_camera/CMakeLists.txt +++ b/realsense2_camera/CMakeLists.txt @@ -147,15 +147,15 @@ endif() if("$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_foxy.cpp) + set(SOURCES "${SOURCES}" src/ros_param_backend.cpp) elseif("$ENV{ROS_DISTRO}" STREQUAL "iron") message(STATUS "Build for ROS2 Iron") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIRON") - set(SOURCES "${SOURCES}" src/ros_param_backend_foxy.cpp) + set(SOURCES "${SOURCES}" src/ros_param_backend.cpp) elseif("$ENV{ROS_DISTRO}" STREQUAL "rolling") message(STATUS "Build for ROS2 Rolling") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DROLLING") - set(SOURCES "${SOURCES}" src/ros_param_backend_rolling.cpp) + set(SOURCES "${SOURCES}" src/ros_param_backend.cpp) else() message(FATAL_ERROR "Unsupported ROS Distribution: " "$ENV{ROS_DISTRO}") endif() diff --git a/realsense2_camera/include/constants.h b/realsense2_camera/include/constants.h index a9321d9190..0f99fee585 100644 --- a/realsense2_camera/include/constants.h +++ b/realsense2_camera/include/constants.h @@ -31,7 +31,7 @@ #define ROS_WARN(...) RCLCPP_WARN(_logger, __VA_ARGS__) #define ROS_ERROR(...) RCLCPP_ERROR(_logger, __VA_ARGS__) -// Based on: https://docs.ros2.org/foxy/api/rclcpp/logging_8hpp.html +// Based on: https://docs.ros2.org/latest/api/rclcpp/logging_8hpp.html #define ROS_DEBUG_STREAM(msg) RCLCPP_DEBUG_STREAM(_logger, msg) #define ROS_INFO_STREAM(msg) RCLCPP_INFO_STREAM(_logger, msg) #define ROS_WARN_STREAM(msg) RCLCPP_WARN_STREAM(_logger, msg) diff --git a/realsense2_camera/src/realsense_node_factory.cpp b/realsense2_camera/src/realsense_node_factory.cpp index d57ff44e54..e53b459551 100644 --- a/realsense2_camera/src/realsense_node_factory.cpp +++ b/realsense2_camera/src/realsense_node_factory.cpp @@ -31,7 +31,7 @@ using namespace realsense2_camera; constexpr auto realsense_ros_camera_version = REALSENSE_ROS_EMBEDDED_VERSION_STR; RealSenseNodeFactory::RealSenseNodeFactory(const rclcpp::NodeOptions & node_options) : - Node("camera", "/", node_options), + Node("camera", "/camera", node_options), _logger(this->get_logger()) { init(); diff --git a/realsense2_camera/src/ros_param_backend_foxy.cpp b/realsense2_camera/src/ros_param_backend.cpp similarity index 100% rename from realsense2_camera/src/ros_param_backend_foxy.cpp rename to realsense2_camera/src/ros_param_backend.cpp diff --git a/realsense2_camera/src/ros_param_backend_dashing.cpp b/realsense2_camera/src/ros_param_backend_dashing.cpp deleted file mode 100644 index 8ecf8e7e8f..0000000000 --- a/realsense2_camera/src/ros_param_backend_dashing.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023 Intel Corporation. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "ros_param_backend.h" - -namespace realsense2_camera -{ - void ParametersBackend::add_on_set_parameters_callback(ros2_param_callback_type callback) - { - rclcpp::Node::OnParametersSetCallbackType prev_callback = _node.set_on_parameters_set_callback(callback); - if (prev_callback) - { - rclcpp::Node::OnParametersSetCallbackType prev_callback = _node.set_on_parameters_set_callback(prev_callback); - std::stringstream msg; - msg << "Cannot set another callback to current node: " << _node.get_name(); - throw std::runtime_error(msg.str()); - } - } - - ParametersBackend::~ParametersBackend() - { - } -} diff --git a/realsense2_camera/src/ros_param_backend_rolling.cpp b/realsense2_camera/src/ros_param_backend_rolling.cpp deleted file mode 100644 index e3998e9808..0000000000 --- a/realsense2_camera/src/ros_param_backend_rolling.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2023 Intel Corporation. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "ros_param_backend.h" - -namespace realsense2_camera -{ - void ParametersBackend::add_on_set_parameters_callback(ros2_param_callback_type callback) - { - _ros_callback = _node.add_on_set_parameters_callback(callback); - } - - ParametersBackend::~ParametersBackend() - { - if (_ros_callback) - { - _node.remove_on_set_parameters_callback((rclcpp::node_interfaces::OnSetParametersCallbackHandle*)(_ros_callback.get())); - _ros_callback.reset(); - } - } -} diff --git a/realsense2_camera/src/rs_node_setup.cpp b/realsense2_camera/src/rs_node_setup.cpp index 5a8a4653ba..1f45c6f620 100755 --- a/realsense2_camera/src/rs_node_setup.cpp +++ b/realsense2_camera/src/rs_node_setup.cpp @@ -225,6 +225,8 @@ void BaseRealSenseNode::startPublishers(const std::vector& profi if (sensor.rs2::sensor::is()) rectified_image = true; + // adding "~/" to the topic name will add node namespace and node name to the topic + // see "Private Namespace Substitution Character" section on https://design.ros2.org/articles/topic_and_service_names.html image_raw << "~/" << stream_name << "/image_" << ((rectified_image)?"rect_":"") << "raw"; camera_info << "~/" << stream_name << "/camera_info"; @@ -309,6 +311,8 @@ void BaseRealSenseNode::startRGBDPublisherIfNeeded() { rmw_qos_profile_t qos = _use_intra_process ? qos_string_to_qos(DEFAULT_QOS) : qos_string_to_qos(IMAGE_QOS); + // adding "~/" to the topic name will add node namespace and node name to the topic + // see "Private Namespace Substitution Character" section on https://design.ros2.org/articles/topic_and_service_names.html _rgbd_publisher = _node.create_publisher("~/rgbd", rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(qos), qos)); } @@ -396,6 +400,8 @@ void BaseRealSenseNode::updateSensors() void BaseRealSenseNode::publishServices() { + // adding "~/" to the service name will add node namespace and node name to the service + // see "Private Namespace Substitution Character" section on https://design.ros2.org/articles/topic_and_service_names.html _device_info_srv = _node.create_service( "~/device_info", [&](const realsense2_camera_msgs::srv::DeviceInfo::Request::SharedPtr req,