Skip to content

Commit

Permalink
updated examples and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun-Prasad-V committed Sep 18, 2023
1 parent fd9a686 commit 4e850c0
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 84 deletions.
12 changes: 12 additions & 0 deletions realsense2_camera/examples/align_depth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Align Depth to Color
This example shows how to start the camera node and align depth stream to color stream.
```
ros2 launch realsense2_camera rs_align_depth_launch.py
```

The aligned image will be published to the topic "/aligned_depth_to_color/image_raw"

Also, align depth to color can enabled by following cmd:
```
ros2 launch realsense2_camera rs_launch.py align_depth.enable:=true"
```
123 changes: 123 additions & 0 deletions realsense2_camera/examples/dual_camera/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Launching Dual RS ROS2 nodes
The following example lanches two RS ROS2 nodes.
```
ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:=<serial number of the first camera> serial_no2:=<serial number of the second camera>
```

## Example:
Let's say the serial numbers of two RS cameras are 207322251310 and 234422060144.
```
ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:="'207322251310'" serial_no2:="'234422060144'"
```
or
```
ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:=_207322251310 serial_no2:=_234422060144
```

## How to know the serial number?
Method 1: Using the rs-enumerate-devices tool
```
rs-enumerate-devices | grep "Serial Number"
```

Method 2: Connect single camera and run
```
ros2 launch realsense2_camera rs_launch.py
```
and look for the serial number in the log printed to screen under "[INFO][...] Device Serial No:".

# Using Multiple RS camera by launching each in differnet terminals
Make sure you set a different name and namespace for each camera.

Terminal 1:
```
ros2 launch realsense2_camera rs_launch.py serial_no:="'207322251310'" camera_name:='camera1' camera_namespace:='camera1'
```
Terminal 2:
```
ros2 launch realsense2_camera rs_launch.py serial_no:="'234422060144'" camera_name:='camera2' camera_namespace:='camera2'
```

# Multiple cameras showing a semi-unified pointcloud
The D430 series of RealSense cameras use stereo based algorithm to calculate depth. This mean, a couple of cameras can operate on the same scene. For the purpose of this demonstration, let's say 2 cameras can be coupled to look at the same scene from 2 different points of view. See image:

![multi_cameras](https://user-images.githubusercontent.com/127019120/268692789-1b3d5d8b-a41f-4a97-995d-81d44b4bcacb.jpg)

The schematic settings could be described as:
X--------------------------------->cam_2
|&emsp;&emsp;&emsp;&emsp;(70 cm)
|
|
|&ensp;(60 cm)
|
|
/
cam_1

The cameras have no data regarding their relative position. That’s up to a third party program to set. To simplify things, the coordinate system of cam_1 can be considered as the refernce coordinate system for the whole scene.

The estimated translation of cam_2 from cam_1 is 70(cm) on X-axis and 60(cm) on Y-axis. Also, the estimated yaw angle of cam_2 relative to cam_1 as 90(degrees) clockwise. These are the initial parameters to be set for setting the transformation between the 2 cameras as follows:

```
ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:=_207322251310 serial_no2:=_234422060144 tf.translation.x:=0.7 tf.translation.y:=0.6 tf.translation.z:=0.0 tf.rotation.yaw:=-90.0 tf.rotation.pitch:=0.0 tf.rotation.roll:=0.0
```

If the unified pointcloud result is not good, follow the below steps to fine-tune the calibaration.

## Visualizing the pointclouds and fine-tune the camera calibration
Launch 2 cameras in separate terminals:

**Terminal 1:**
```
ros2 launch realsense2_camera rs_launch.py serial_no:="'207322251310'" camera_name:='camera1' camera_namespace:='camera1'
```
**Terminal 2:**
```
ros2 launch realsense2_camera rs_launch.py serial_no:="'234422060144'" camera_name:='camera2' camera_namespace:='camera2'
```
**Terminal 3:**
```
rviz2
```
Open rviz and set '“Fixed Frame'” to “camera1_link”
Add Pointcloud2-> By topic -> /camera1/camera1/depth/color/points
Add Pointcloud2 -> By topic -> /camera2/camera2/depth/color/points

**Terminal 4:**
Run the 'set_cams_transforms.py' tool. It can be used to fine-tune the calibaration.
```
python src/realsense-ros/realsense2_camera/scripts/set_cams_transforms.py camera1_link camera2_link 0.7 0.6 0 -90 0 0
```

**Instructions printed by the tool:**
```
Using default file /home/user_name/ros2_ws/src/realsense-ros/realsense2_camera/scripts/_set_cams_info_file.txt
Use given initial values.
Press the following keys to change mode: x, y, z, (a)zimuth, (p)itch, (r)oll
For each mode, press 6 to increase by step and 4 to decrease
Press + to multiply step by 2 or - to divide
Press Q to quit
```

Note that the tool prints the path of the current configuration file. It saves its last configuration automatically, all the time, to be used on the next run.

After a lot of fiddling around, unified pointcloud looked better with the following calibaration:
```
x = 0.75
y = 0.575
z = 0
azimuth = -91.25
pitch = 0.75
roll = 0
```

Now, use the above results in the launch file:
```
ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:=_207322251310 serial_no2:=_234422060144 tf.translation.x:=0.75 tf.translation.y:=0.575 tf.translation.z:=0.0 tf.rotation.yaw:=-91.25 tf.rotation.pitch:=0.75 tf.rotation.roll:=0.0
```

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# For each device, the parameter name was changed to include an index.
# For example: to set camera_name for device1 set parameter camera_name1.
# command line example:
# ros2 launch realsense2_camera rs_dual_camera_launch.py camera_name1:=D400 device_type2:=l5. device_type1:=d4..
# ros2 launch realsense2_camera rs_dual_camera_launch.py serial_no1:=<serial number of 1st camera> serial_no2:=<serial number of 2nd camera>

"""Launch realsense2_camera node."""
import copy
Expand Down Expand Up @@ -68,7 +68,7 @@ def duplicate_params(general_params, posix):
return local_params

def launch_static_transform_publisher_node(context : LaunchContext):
# dummy static transformation from camera1 to camera2
# Static transformation from camera1 to camera2
node = launch_ros.actions.Node(
name = "my_static_transform_publisher",
package = "tf2_ros",
Expand Down Expand Up @@ -104,6 +104,6 @@ def generate_launch_description():
namespace='',
executable='rviz2',
name='rviz2',
arguments=['-d', [ThisLaunchFileDir(), '/dual_camera_pointcloud.rviz']]
arguments=['-d', [ThisLaunchFileDir(), '/rviz/dual_camera_pointcloud.rviz']]
)
])
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Visualization Manager:
Filter size: 10
History Policy: Keep Last
Reliability Policy: Reliable
Value: /camera1/depth/color/points
Value: /camera1/camera1/depth/color/points
Use Fixed Frame: true
Use rainbow: true
Value: true
Expand Down Expand Up @@ -108,7 +108,7 @@ Visualization Manager:
Filter size: 10
History Policy: Keep Last
Reliability Policy: Reliable
Value: /camera2/depth/color/points
Value: /camera2/camera2/depth/color/points
Use Fixed Frame: true
Use rainbow: true
Value: true
Expand Down
17 changes: 17 additions & 0 deletions realsense2_camera/examples/launch_from_rosbag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Launching RS ROS2 node from rosbag File
The following example allows streaming a rosbag file, saved by Intel RealSense Viewer, instead of streaming live with a camera. It can be used for testing and repetition of the same sequence.
```
ros2 launch realsense2_camera rs_launch_from_rosbag.py
```
By default, the 'rs_launch_from_rosbag.py' launch file uses the "/rosbag/D435i_Depth_and_IMU_Stands_still.bag" rosbag file.

User can also provide a different rosbag file through cmd line as follows:
```
ros2 launch realsense2_camera rs_launch_from_rosbag.py rosbag_filename:="/full/path/to/rosbag/file"
```
or
```
ros2 launch realsense2_camera rs_launch.py rosbag_filename:="/full/path/to/rosbag/file"
```

Check-out [sample-recordings](https://github.com/IntelRealSense/librealsense/blob/master/doc/sample-data.md) for a few recorded samples.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{'name': 'enable_depth', 'default': 'true', 'description': 'enable depth stream'},
{'name': 'enable_gyro', 'default': 'true', 'description': "'enable gyro stream'"},
{'name': 'enable_accel', 'default': 'true', 'description': "'enable accel stream'"},
{'name': 'rosbag_filename', 'default': [ThisLaunchFileDir(), "/D435i_Depth_and_IMU_Stands_still.bag"], 'description': 'A realsense bagfile to run from as a device'},
{'name': 'rosbag_filename', 'default': [ThisLaunchFileDir(), "/rosbag/D435i_Depth_and_IMU_Stands_still.bag"], 'description': 'A realsense bagfile to run from as a device'},
]

def set_configurable_parameters(local_params):
Expand Down
33 changes: 33 additions & 0 deletions realsense2_camera/examples/launch_params_from_file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Get RS ROS2 node params from YAML file
The following example gets the RS ROS2 node params from YAML file.
```
ros2 launch realsense2_camera rs_launch_get_params_from_yaml.py
```

By default, 'rs_launch_get_params_from_yaml.py' launch file uses the "/config/config.yaml" YAML file.

User can provide a different YAML file through cmd line as follows:
```
ros2 launch realsense2_camera rs_launch_get_params_from_yaml.py config_file:="/full/path/to/config/file"
```
or
```
ros2 launch realsense2_camera rs_launch.py config_file:="/full/path/to/config/file"
```

## Syntax for defining params in YAML file
```
param1: value
param2: value
```

Example:
```
enable_color: true
rgb_camera.profile: 1280x720x15
enable_depth: true
align_depth.enable: true
enable_sync: true
publish_tf: true
tf_publish_rate: 1.0
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ rgb_camera.profile: 1280x720x15
enable_depth: true
align_depth.enable: true
enable_sync: true

publish_tf: true
tf_publish_rate: 1.0
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

local_parameters = [{'name': 'camera_name', 'default': 'camera', 'description': 'camera unique name'},
{'name': 'camera_namespace', 'default': 'camera', 'description': 'camera namespace'},
{'name': 'config_file', 'default': [ThisLaunchFileDir(), "/config.yaml"], 'description': 'yaml config file'},
{'name': 'config_file', 'default': [ThisLaunchFileDir(), "/config/config.yaml"], 'description': 'yaml config file'},
]

def set_configurable_parameters(local_params):
Expand Down
17 changes: 17 additions & 0 deletions realsense2_camera/examples/pointcloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# PointCloud Visualization
The following example starts the camera and simultaneously opens RViz GUI to visualize the published pointcloud.
```
ros2 launch realsense2_camera rs_pointcloud_launch.py
```

Alternatively, start the camera terminal 1:
```
ros2 launch realsense2_camera rs_launch.py pointcloud.enable:=true
```
and in terminal 2 open rviz to visualize pointcloud.

# PointCloud with different coordinate systems
This example opens rviz and shows the camera model with different coordinate systems and the pointcloud, so it presents the pointcloud and the camera together.
```
ros2 launch realsense2_camera rs_d455_pointcloud_launch.py
```
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate_launch_description():
namespace='',
executable='rviz2',
name='rviz2',
arguments=['-d', [ThisLaunchFileDir(), '/urdf_pointcloud.rviz']],
arguments=['-d', [ThisLaunchFileDir(), '/rviz/urdf_pointcloud.rviz']],
output='screen',
parameters=[{'use_sim_time': False}]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ def generate_launch_description():
namespace='',
executable='rviz2',
name='rviz2',
arguments=['-d', [ThisLaunchFileDir(), '/pointcloud.rviz']]
arguments=['-d', [ThisLaunchFileDir(), '/rviz/pointcloud.rviz']]
)
])
Loading

0 comments on commit 4e850c0

Please sign in to comment.