Skip to content

Instantly share code, notes, and snippets.

@RishikesavanRamesh
Last active August 14, 2024 16:10
Show Gist options
  • Select an option

  • Save RishikesavanRamesh/a65d46054945fd42ea88e027107210d2 to your computer and use it in GitHub Desktop.

Select an option

Save RishikesavanRamesh/a65d46054945fd42ea88e027107210d2 to your computer and use it in GitHub Desktop.
Connect ros2 docker containers with fastdds

RUNNING THE CONTAINERS

  • Copy the docker-compose.yml and Dockerfile to a new folder.
  • Run docker compose up -d
  • Next in,
    • Terminal 1 :>> Run docker compose exec -it rosc1 tmate
    • Terminal 2 :>> Run docker compose exec -it rosc2 tmate
    • Terminal 3 :>> Run docker compose exec -it rosc3 tmate
    • Now, you have been connected to those containers in respective terminal. In,
      • Terminal 1 :>> Run ros2 run demo_nodes_cpp talker
      • Terminal 2 :>> Run ros2 run demo_nodes_cpp listener
      • Terminal 3 :>> Run ros2 run demo_nodes_cpp listener
  • You can observe that the listeners on the rosc2 and rosc3 containers are listening to the talker on rosc1 container.

HOW IT IS CONFIGURED?

  • By running the docker-compose.yml, we are running 4 containers,
    • robot_ds ( container running fastdds discovery server )
    • rosc1 and rosc2 ( configured as localhost and shared memory with robot_ds for interprocess communication ( shm transport in dds )
    • rosc3 ( configured to connect to dds and transport data in udp or tcp/ip mode ( default if shm transport is not possible) )

OBSERVATIONS

  • Data is transferred using UDPV4 in rosc1 -- rosc2 and in rosc1 -- rosc3 , even though the rosc1 -- rosc2 met the requirements for ipc (using shm transport).
  • The fastdds_qos settings have to be configured to realise the expected behaviour of shm transport
services:
robot_ds:
build: .
ipc: shareable
command: fastdds discovery -i 0 -t 127.0.0.1 -p 11811
healthcheck:
test: ["CMD-SHELL", "pgrep -f fast-discovery-server || exit 1"]
interval: 5s
timeout: 3s
retries: 5
rosc1:
build: .
environment:
- ROS_DISCOVERY_SERVER=127.0.0.1:11811
- RMW_IMPLEMENTATION=rmw_fastrtps_cpp
ipc: service:robot_ds
command: sleep infinity
network_mode: service:robot_ds
depends_on:
robot_ds:
condition: service_healthy
rosc2:
build: .
environment:
- ROS_DISCOVERY_SERVER=127.0.0.1:11811
- RMW_IMPLEMENTATION=rmw_fastrtps_cpp
ipc: service:robot_ds
command: sleep infinity
network_mode: service:robot_ds
depends_on:
robot_ds:
condition: service_healthy
rosc3:
build: .
environment:
- ROS_DISCOVERY_SERVER=robot_ds:11811
- RMW_IMPLEMENTATION=rmw_fastrtps_cpp
command: sleep infinity
FROM ros:humble
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
ros-humble-demo-nodes-cpp \
iproute2 tmate tcpdump&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment