ROSbot 2 PRO: no ROS communictaion through Docker container

Hi,
I am trying to run my Rosbot2 Pro in ROS2. However, after running the
ros2 run teleop_twist_keyboard teleop_twist_keyboard
command after the docker compose up is not actually running the robot.
If I start a bash using
docker exec -it husarion-rosbot-1 bash and then if I run
ros2 run teleop_twist_keyboard teleop_twist_keyboard
it is working.

Could you please help me what is the issue?
If I need to run my python code how can I run from the container?

Thanks

Hello @QuackerCoder,

By default, communication takes place via shared-memory. To read messages from Dockar on your host, it is necessary that the username is identical. So you can.

  1. Run teleop on the host as root.
    sudo su
    source /opt/ros/{ros_distro}/setup.bash
    ros2 run...
    
  2. Pass the USER variable for all docker services
        environment:
          - USER 
    
  3. Change the DDS configuration both on the host and in dockers to not use shared-memeory.
    export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

All options should give the desired effect. Choose the option that is most convenient for you.

Regards

The first option with host as root is working.
However, rviz2 is not working in that case.
Also, the other 2 option didn’t work.
Could you please take a look at our compose.yaml and suggest.

x-common-config:
  &common-config
  restart: unless-stopped
  network_mode: host
  ipc: host
  #user: ${DOCKER_UID:-1000}:${DOCKER_GID:-1000} # *
  environment:
    - RMW_IMPLEMENTATION=rmw_fastrtps_cpp        # ***
    - FASTRTPS_DEFAULT_PROFILES_FILE  # ***
    - CYCLONEDDS_URI                  # ***
    - ROS_DOMAIN_ID=${ROS_DOMAIN_ID:-0}                   # ***
    - ROBOT_NAMESPACE
    - USER

services:

  microros:
    image: husarion/micro-ros-agent:humble-3.1.3-20240726
    container_name: microros
    <<: *common-config
    restart: unless-stopped
    devices:
      - ${SERIAL_PORT:?err}
    environment:
      - RMW_IMPLEMENTATION
    command: ros2 run micro_ros_agent micro_ros_agent serial -D $SERIAL_PORT serial -b 576000
  
  rplidar:
    image: husarion/rplidar:humble-1.0.1-20240104-stable
    container_name: rplidar
    restart: unless-stopped
    devices:
      - ${LIDAR_SERIAL:?err}:/dev/ttyUSB0
    environment:
      - RMW_IMPLEMENTATION
    command: >
        ros2 launch sllidar_ros2 sllidar_launch.py
        serial_baudrate:=${RPLIDAR_BAUDRATE:-256000}
    
  rosbot:
    image: husarion/rosbot:humble-0.6.1-20230712
    restart: unless-stopped
    devices:
      - ${SERIAL_PORT:?err}
      - /dev/bus/usb/
    <<: *common-config
    environment: #only two envs are valid for micro-xrce-agent
      - RMW_IMPLEMENTATION 
    network_mode: host
    command: >
      ros2 launch rosbot_bringup bringup.launch.py &&
      ros2 launch rosbot_bringup combined.launch.py
       mecanum:=${MECANUM:-False}
       namespace:=${ROBOT_NAMESPACE:-rosbot}
       serial_port:=$SERIAL_PORT

Hello @QuackerCoder,
I see that you have quite an old compose configuration, I am sending you a newer compose that should work.

x-common-config:
  &common-config
  network_mode: host
  ipc: host
  restart: unless-stopped
  environment:
    - ROBOT_NAMESPACE
    - USER

services:
  astra:
    image: husarion/astra:humble-nightly
    <<: *common-config
    devices:
      - /dev/bus/usb/
    command: >
      ros2 launch /husarion_utils/astra.launch.py

  rosbot:
    image: husarion/rosbot:humble-0.13.1-20240201
    <<: *common-config
    devices:
      - ${SERIAL_PORT:?err}
    command: >
      ros2 launch rosbot_bringup combined.launch.py
        mecanum:=${MECANUM:-False}
        serial_port:=$SERIAL_PORT
        serial_baudrate:=576000

  rplidar:
    image: husarion/rplidar:humble-1.0.1-20240104
    <<: *common-config
    devices:
      - /dev/ttyRPLIDAR:/dev/ttyUSB0
    command: >
      ros2 launch /husarion_utils/rplidar.launch.py
        serial_baudrate:=${LIDAR_BAUDRATE:-256000}
        serial_port:=/dev/ttyUSB0

Let me know if everything works properly with this compose.

By the way, I will add that for several months we have also had Snap Rosbot, which has a more user-friendly interface.

Even after using the new compose file, the issue persists. ros2 teleop_twist_keyboard works with sudo su and not as $USER=husarion.

New Question: I have installed ros foxy through terminal, and I do not have the correct urdf file (robot_description) for rosbot2.0 pro. But there is one in the folders of ros noetic, can I use this file and copy paste in ros foxy ?

Hello @QuackerCoder,

I am unable to reproduce the behavior given. I just tested this compos and it was possible to control it with teleop from the host without any problems.
The suggestions I have are:

  1. Changing DDS on the host and docker.
  2. Installing rosbot snap. Install rosbot on Linux | Snap Store
  3. Reinstall the system, maybe some changes have been made that cause problems
  4. You can build the rosbot_ros repository on the host, but I’m not sure if it will work properly because ROSbot 2 PRO uses the Foxy version

Such copying will probably not work because ROS 1 is not compatible with ROS 2. You should build the code from the rosbot_ros repository from the humble branch. The differences between the foxy and humble branches are not significant, but as I’m mention, there might be some missing dependencies between foxy and humble. That’s why we use docker which based on ROS Humble.
You can also login to docker container and work from container.

Regards