Skip to content

Commit

Permalink
Merge branch 'IntelRealSense:ros2-development' into remove_l500_sr300
Browse files Browse the repository at this point in the history
  • Loading branch information
SamerKhshiboun committed Sep 4, 2023
2 parents 8405872 + 07d7025 commit e14f121
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 72 deletions.
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -183,6 +184,74 @@

<hr>

<h3 id="camera-name-and-namespace">
Camera Name And Camera Namespace
</h3>

### 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
```


<hr>


<h3 id="parameters">
Parameters
<h3>
Expand Down Expand Up @@ -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`
- ***<stream_name>*_frame_id**, ***<stream_name>*_optical_frame_id**, **aligned_depth_to_*<stream_name>*_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**:
Expand Down
6 changes: 3 additions & 3 deletions realsense2_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/src/realsense_node_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
File renamed without changes.
34 changes: 0 additions & 34 deletions realsense2_camera/src/ros_param_backend_dashing.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions realsense2_camera/src/ros_param_backend_rolling.cpp

This file was deleted.

6 changes: 6 additions & 0 deletions realsense2_camera/src/rs_node_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ void BaseRealSenseNode::startPublishers(const std::vector<stream_profile>& profi
if (sensor.rs2::sensor::is<rs2::depth_sensor>())
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";

Expand Down Expand Up @@ -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<realsense2_camera_msgs::msg::RGBD>("~/rgbd",
rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(qos), qos));
}
Expand Down Expand Up @@ -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<realsense2_camera_msgs::srv::DeviceInfo>(
"~/device_info",
[&](const realsense2_camera_msgs::srv::DeviceInfo::Request::SharedPtr req,
Expand Down

0 comments on commit e14f121

Please sign in to comment.