micro-ROS / micro-ROS-demos

Sample code using rclc and rclcpp implementations.
Apache License 2.0
84 stars 24 forks source link

Data from micro-ros publisher in docker container can't be received in other ros2-humble docker container #73

Closed ge65luz closed 1 year ago

ge65luz commented 1 year ago

Issue template

Steps to reproduce the issue

I try to publish data from a micro ros docker container and receive it in a ros2 humble docker container. Therefore, i have written my own dockerfiles and docker-compose.yaml. But the listener doesn't receive data and when i run "ros2 topic list" the publisher (ping_pong) is not listed.

This is my Dockerfile:

# Download base image ubuntu 22.04
FROM ubuntu:22.04

# LABEL about the custom image
LABEL maintainer="VV"
LABEL version="1.0"
LABEL description="This is a ROS2_pub_sub Docker Image"

# Define build arguments
ARG TIME_ZONE
ARG DEBIAN_FRONTEND=noninteractive
ARG ROS_DISTRO=humble
#ARG DEBIAN_FRONTEND=noninteractive -> no user input needed when building

# Install dependencies
RUN apt-get update && \
    apt-get install -y locales\
    curl\
    locales\
    python3-pip\
 && rm -rf /var/lib/apt/lists/*

# Generate and set locales
RUN locale-gen en_US en_US.UTF-8 && \
    update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

# Set environment variables
ENV TZ=Europe/Berlin
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV ROS_VERSION=2
ENV ROS_DISTRO=humble
ENV ROS_PYTHON_VERSION=3
ENV RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity} {time}]: {message}"

# Add, install and source ROS2 humble
RUN apt-get update && apt-get install -y software-properties-common curl && \
    add-apt-repository universe

RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

# Install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    nano \
    iputils-ping \
    wget \
    python3-colcon-common-extensions \
    python3-colcon-mixin \
    python3-rosdep \
    python3-vcstool \
    git \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get upgrade -y &&\
    apt-get install -y ros-humble-desktop\
    && rm -rf /var/lib/apt/lists/*

RUN mkdir /microros_ws
WORKDIR /microros_ws
RUN git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup

RUN bash -c "source /opt/ros/humble/setup.bash"

# bootstrap rosdep
RUN rosdep init && \
  rosdep update --rosdistro humble  
RUN apt update && rosdep update
RUN rosdep install -i --from-path src --rosdistro humble -y

RUN bash -c "source /opt/ros/humble/setup.bash && \
            colcon build && \
            source install/local_setup.bash && \
            ros2 run micro_ros_setup create_firmware_ws.sh host && \
            ros2 run micro_ros_setup build_firmware.sh && \
            source install/local_setup.bash && \
            ros2 run micro_ros_setup create_agent_ws.sh && \
            ros2 run micro_ros_setup build_agent.sh && \
            source install/local_setup.bash"

# Environment setup
#RUN echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
RUN echo '#!/usr/bin/env bash' > /ros_entrypoint.sh
RUN echo 'source /opt/ros/humble/setup.bash' >> /ros_entrypoint.sh
RUN echo 'source /microros_ws/install/local_setup.bash' >> /ros_entrypoint.sh

# Finalize entrypoint script
RUN echo 'exec "$@"' >> /ros_entrypoint.sh
RUN chmod +x /ros_entrypoint.sh

ENTRYPOINT ["/ros_entrypoint.sh"]

# Run command
CMD ["bash"]

The name of the docker image created by the dockerfile is called "micro_ros_image.v1:latest". And this is my docker-compose.yaml

version: "3"
services:
  micro_ros_agent:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
    privileged: true
    command: ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 

  micro_ros_dds:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
      - RMW_IMPLEMENTATION=rmw_microxrcedds
    privileged: true
    command: ros2 run micro_ros_demos_rclc ping_pong 

  micro_ros_listen:
    image: micro_ros_image.v1:latest
    volumes:
      - /dev/shm:/dev/shm
    network_mode: "host"
    environment:
      - ROS_DOMAIN_ID=33
    privileged: true
    command: ros2 topic echo /microROS/ping

Expected behavior

The first docker container launches the agent, the second one publishes, and the third one listens/echos.

Actual behavior

Additional information

I also tried to use rmw_cyclonedds_cpp as dds, i gave every container its own image (different names) and I used a real subscriber(listener), but it didn't help. I only receive data if i run everything in one container. Because i want to execute the publisher, directly when i launch docker compose, because i want to create a chain of pub/sub.

Any ideas what i can try. The agent receives the data from the publisher but doesn't transmit the data further.

Acuadros95 commented 1 year ago

On a micro-ROS client, the ROS_DOMAIN_ID shall be configured on the source code.

Check this tutorial: link.

ge65luz commented 1 year ago

Thank you, the link helped. It worked for me after I used cyclone_dds instead of rmw_fastrtps_cpp and ran ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 -v5, instead of only ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888.