carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
10.91k stars 3.51k forks source link

CARLA ROS Bridge Docker Container having issues initially connecting to CARLA Server running in a Docker Container #6373

Open UrbanPistek opened 1 year ago

UrbanPistek commented 1 year ago

CARLA version: 0.9.13 Platform/OS: Docker/Linux

I am using docker compose to launch Carla and a Carla ROS Bridge instance, here is my docker compose file:

version: '3.8'

services:

  # Carla server container
  carla:
    image: carlasim/carla:0.9.13
    container_name: carla_server
    runtime: nvidia
    ports:
      - 2000-2002:2000-2002
    command: /bin/bash -c "./CarlaUE4.sh -nosound -carla-server -RenderOffscreen -world-port=2000"

  # Carla ROS bridge container
  bridge:
    build:
      context: ./docker/ros_carla_bridge/
      dockerfile: Dockerfile
    container_name: carla_ros_bridge
    command: ros2 launch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch.py host:=carla_server timeout:=5
    runtime: nvidia
    restart: always
    depends_on: 
      carla:
        condition: service_started

And here is my ROS Bridge docker file:

FROM osrf/ros:foxy-desktop-focal AS base

SHELL ["/bin/bash", "-c"]

RUN apt update && apt install -y python3-pip

RUN sudo apt install python3-colcon-common-extensions

RUN mkdir -p ~/carla-ros-bridge
WORKDIR /root/carla-ros-bridge

RUN git clone --recurse-submodules https://github.com/carla-simulator/ros-bridge.git src/ros-bridge

RUN rosdep update && rosdep install --from-paths src --ignore-src -r

RUN source /opt/ros/foxy/setup.bash && \
    colcon build

COPY ros_entrypoint.sh /

# Ensure script is executable
RUN ["sudo", "chmod", "+x", "/ros_entrypoint.sh"]

ENTRYPOINT ["/ros_entrypoint.sh"]

RUN python3 -m pip install --upgrade pip && python3 -m pip install numpy pygame
RUN python3 -m pip install 'carla==0.9.13'

I found when I run docker-compose up the carla_ros_bridge has trouble connecting to the carla server, the container crashes then restarts and then its able to connect, here is the error:

carla_ros_bridge   | [bridge-1] [ERROR] [1680446255.811228168] [carla_ros_bridge]: Error: time-out of 5000ms while waiting for the simulator, make sure the simulator is ready and connected to carla_server:2000
carla_ros_bridge   | [bridge-1] [INFO] [1680446255.811739344] [carla_ros_bridge]: Shutting down...

Then on the second retry it is able to connect.

I was wondering why it might be failing to connect on the first try, any ideas?

Thanks

Note: I am not sure if this is a Carla issue or a ROS bridge issue, I've also created a issue in ros-bridge for this: https://github.com/carla-simulator/ros-bridge/issues/673

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.