Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docker_modules/install_realsense.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -e

if [ -z "$REALSENSE" ]; then
echo "Skipping RealSense installation as REALSENSE is not set"
exit 0
fi

# Install RealSense, TurtleBot3 packages and rqt steering
# This script is intended to be run inside the Dockerfile during build.
if [ "$REALSENSE" = "YES" ]; then
echo "Installing RealSense ros packages for ROS distro: ${ROS_DISTRO:-humble}"

sudo apt-get update && sudo apt-get install -y \
ros-${ROS_DISTRO}-point-cloud-transport \
ros-${ROS_DISTRO}-librealsense2* \
ros-${ROS_DISTRO}-realsense2-* \
ros-${ROS_DISTRO}-turtlebot3* \
ros-${ROS_DISTRO}-rqt-robot-steering \
ros-${ROS_DISTRO}-launch-pytest \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what's going wrong, but adding this line seems to break the Docker build (it says the package can't be found). Theoretically, it should be able to locate it, so I'm a bit puzzled here. Ref

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you clarify why these files need to be installed? I tried removing them locally, and the workspace seems to work just fine without them.

python3-tqdm \
&& sudo rm -rf /var/lib/apt/lists/*
fi

echo "RealSense installation completed successfully!"
77 changes: 77 additions & 0 deletions docs/docker-modules/realsense.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Realsense

[![GitHub code](https://img.shields.io/badge/code-blue?logo=github&label=github)](https://github.com/j3soon/ros2-essentials/blob/main/docker_modules/install_cartographer.sh)

ROS2 Realsense. (Only installed by default for the template workspace.)

To enable Realsense, set the `REALSENSE` argument to `YES` in the `compose.yaml` file of your desired workspace (e.g., `husky_ws/docker/compose.yaml`). After making these changes, rebuild the Docker image.

> TODO: Remove duplicate content from the template workspace below.
## 🐳 Start Container

> Make sure your system meets the [system requirements](https://j3soon.github.io/ros2-essentials/#system-requirements) and have followed the [setup instructions](https://j3soon.github.io/ros2-essentials/#setup) before using this workspace.
Run the following commands in a Ubuntu desktop environment. If you are using a remote server, make sure you're using a terminal within a remote desktop session (e.g., VNC) instead of SSH (i.e., don't use `ssh -X` or `ssh -Y`).

```sh
cd ~/ros2-essentials/template_ws/docker
docker compose build
xhost +local:docker
docker compose up -d
# The initial build will take a while, please wait patiently.
```

> If your user's UID is `1000`, you may replace the `docker compose build` command with `docker compose pull`.
The commands in the following sections assume that you are inside the Docker container:

```sh
# in a new terminal
docker exec -it ros2-template-ws bash
```

If the initial build somehow failed, run:

```sh
rm -r build install
colcon build --symlink-install
```

Once you have finished testing, you can stop and remove the container with:

```sh
docker compose down
```

## Realsense test with gazebo

- realsense_desp package: Description of a robot with realsense D435 camera.
- realsense_gazebo package: Gazebo simulation of the robot with robot state publisher.
- Launch Gazebo with turtlebot3 in `tmux`
```bash
ros2 launch realsense_gazebo realsense_gazebo.launch.py
```

- Run the control tool in new window of `tmux`
```bash
ros2 run rqt_robot_steering rqt_robot_steering
```

## Realsense test in realworld

- Launch Realsense camera node in `tmux`
```bash
# add pointcloud.enable:=true to enable pointcloud
ros2 launch realsense2_camera rs_launch.py
```

- Open RViz to verify the camera topics in `tmux`
```bash
ros2 run rviz2 rviz2
```

## References

- [Realsense ROS Wrapper](https://github.com/IntelRealSense/realsense-ros)
- [RealSense Gazebo ROS Plugin](https://github.com/pal-robotics/realsense_gazebo_plugin)
7 changes: 7 additions & 0 deletions template_ws/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ COPY --chown=$USERNAME:$USERNAME \
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
/tmp/install_rtabmap.sh && rm /tmp/install_rtabmap.sh

# realsense configuration
ARG REALSENSE=""
COPY --chown=$USERNAME:$USERNAME \
modules/install_realsense.sh /tmp/install_realsense.sh
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
/tmp/install_realsense.sh && rm /tmp/install_realsense.sh

# TODO: Add more commands here
COPY --chown=$USERNAME:$USERNAME \
.bashrc /home/$USERNAME/.bashrc
Expand Down
9 changes: 8 additions & 1 deletion template_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ services:
CARTOGRAPHER: "YES"
# TODO: Set to "YES" if using RTAB-Map or set to "" if not using RTAB-Map
RTABMAP: "YES"
# TODO: Set to "YES" if using RealSense or set to "" if not using RealSense
REALSENSE: "YES"
cache_from:
- j3soon/ros2-template-ws:buildcache-amd64
- j3soon/ros2-template-ws:buildcache-arm64
Expand Down Expand Up @@ -109,7 +111,7 @@ services:
# Mount shared memory for ROS2 communication.
- /dev/shm:/dev/shm
# TODO: Uncomment the line below and comment out the three entries above to enable USB support.
# - /dev:/dev
- /dev:/dev
# Mount Gazebo models directory to reuse models downloaded during first launch.
# Reference: https://answers.ros.org/question/365658
# Note that this volume is shared among all workspaces.
Expand Down Expand Up @@ -179,6 +181,11 @@ services:
# TODO: Add more volume mounts here.
# Mount root workspace to allow easy access to all workspaces.
- ../..:/home/ros2-essentials
# Add device cgroup rules to allow access to specific devices (like realsense).
# Ref: https://github.com/2b-t/realsense-ros2-docker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding reference docs here feels a bit out of place. It might be better to make this a standalone commit or include it in another one.

device_cgroup_rules:
- 'c 81:* rmw'
- 'c 189:* rmw'
volumes:
gazebo-cache:
name: ros2-gazebo-cache
Expand Down
30 changes: 30 additions & 0 deletions template_ws/src/realsense_examples/realsense_desp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.8)
project(realsense_desp)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

install(DIRECTORY launch models urdf
DESTINATION share/${PROJECT_NAME}/
)

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration

from launch_ros.substitutions import FindPackageShare
from launch_ros.actions import Node

def generate_launch_description():

# Declare the robot position argument
robot_px = LaunchConfiguration('robot_px')
robot_px_arg = DeclareLaunchArgument('robot_px', default_value='0.5')

robot_py = LaunchConfiguration('robot_py')
robot_py_arg = DeclareLaunchArgument('robot_py', default_value='0.5')

robot_pz = LaunchConfiguration('robot_pz')
robot_pz_arg = DeclareLaunchArgument('robot_pz', default_value='0.0')

# Define the path to the model
burger_model_path = PathJoinSubstitution([
FindPackageShare("realsense_desp"),
"models/turtlebot3_burger/model.sdf"
])

# Add robot description
# Ref: https://github.com/ROBOTIS-GIT/turtlebot3_simulations/blob/98a27b20952b11047f454d7ec751f8c742862713/turtlebot3_gazebo/launch/robot_state_publisher.launch.py
urdf_path = os.path.join(
get_package_share_directory('realsense_desp'),
'urdf',
'turtlebot3_burger.urdf'
)

with open(urdf_path, 'r') as infp:
robot_desc = infp.read()

robot_description = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{
'use_sim_time': True,
'robot_description': robot_desc
}],
)

# Spawn the robot in Gazebo
# Ref: https://github.com/ros-simulation/gazebo_ros_pkgs/blob/d52f7c471d1d2fd9425bf8621290bc4831be8dea/gazebo_ros/launch/spawn_entity_demo.launch.py
spawn_entity = Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=[
'-entity', 'burger',
'-file', burger_model_path,
'-x', robot_px,
'-y', robot_py,
'-z', robot_pz
],
parameters=[{'use_sim_time': True}]
)

return LaunchDescription([
# Argument
robot_pz_arg, robot_px_arg, robot_py_arg,

# Nodes
robot_description, spawn_entity
])
Loading