From e08b856d99ea1d26e4a5484c7c5f050c179a14b4 Mon Sep 17 00:00:00 2001 From: Peng Xu Date: Mon, 17 Jan 2022 22:07:34 -0800 Subject: [PATCH 1/4] Update code and patch to work with Carla 0.9.11. --- Dockerfile | 37 ++-- carla-autoware-agent/agent/bridge.launch | 14 +- .../agent/config/objects.json | 162 ++++++++++++++++++ .../agent/config/sensors.json | 122 ------------- .../launch/carla_autoware_agent.launch | 7 +- run.sh | 9 +- update_code.patch | 50 ++++++ update_sim.patch | 2 +- 8 files changed, 255 insertions(+), 148 deletions(-) create mode 100644 carla-autoware-agent/agent/config/objects.json delete mode 100644 carla-autoware-agent/agent/config/sensors.json create mode 100644 update_code.patch diff --git a/Dockerfile b/Dockerfile index eb2547d..6d77e0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG AUTOWARE_VERSION=1.14.0-melodic-cuda +ARG AUTOWARE_VERSION=latest-melodic-cuda FROM autoware/autoware:$AUTOWARE_VERSION @@ -7,15 +7,21 @@ WORKDIR /home/autoware # Update simulation repo to latest master. COPY --chown=autoware update_sim.patch ./Autoware RUN patch ./Autoware/autoware.ai.repos ./Autoware/update_sim.patch + +# Change code in simulation package. +COPY --chown=autoware update_code.patch ./Autoware/src/autoware/simulation RUN cd ./Autoware \ && vcs import src < autoware.ai.repos \ - && git --git-dir=./src/autoware/simulation/.git --work-tree=./src/autoware/simulation pull \ + && cd src/autoware/simulation && git apply update_code.patch + +# Compile with colcon build. +RUN cd ./Autoware \ && source /opt/ros/melodic/setup.bash \ && AUTOWARE_COMPILE_WITH_CUDA=1 colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release # CARLA PythonAPI RUN mkdir ./PythonAPI -ADD --chown=autoware https://carla-releases.s3.eu-west-3.amazonaws.com/Backup/carla-0.9.10-py2.7-linux-x86_64.egg ./PythonAPI +ADD --chown=autoware https://carla-releases.s3.eu-west-3.amazonaws.com/Backup/carla-0.9.11-py2.7-linux-x86_64.egg ./PythonAPI RUN echo "export PYTHON2_EGG=$(ls /home/autoware/PythonAPI | grep py2.)" >> .bashrc \ && echo "export PYTHONPATH=\$PYTHONPATH:~/PythonAPI/\$PYTHON2_EGG" >> .bashrc @@ -23,19 +29,19 @@ RUN echo "export PYTHON2_EGG=$(ls /home/autoware/PythonAPI | grep py2.)" >> .bas # There is some kind of mismatch between the ROS debian packages installed in the Autoware image and # the latest ros-melodic-ackermann-msgs and ros-melodic-derived-objects-msgs packages. As a # workaround we use a snapshot of the ROS apt repository to install an older version of the required -# packages. -RUN sudo rm -f /etc/apt/sources.list.d/ros1-latest.list -RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA -RUN sudo sh -c 'echo "deb http://snapshots.ros.org/melodic/2020-08-07/ubuntu $(lsb_release -sc) main" >> /etc/apt/sources.list.d/ros-snapshots.list' -RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends \ +# packages. +RUN rm -f /etc/apt/sources.list.d/ros1-latest.list +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA +RUN sh -c 'echo "deb http://snapshots.ros.org/melodic/2020-08-07/ubuntu $(lsb_release -sc) main" >> /etc/apt/sources.list.d/ros-snapshots.list' +RUN apt-get update && apt-get install -y --no-install-recommends \ python-pip \ python-wheel \ ros-melodic-ackermann-msgs \ ros-melodic-derived-object-msgs \ - && sudo rm -rf /var/lib/apt/lists/* -RUN pip install simple-pid pygame networkx==2.2 + && rm -rf /var/lib/apt/lists/* +RUN pip install transforms3d simple-pid pygame networkx==2.2 -RUN git clone -b '0.9.10.1' --recurse-submodules https://github.com/carla-simulator/ros-bridge.git +RUN git clone -b '0.9.11' --recurse-submodules https://github.com/carla-simulator/ros-bridge.git # CARLA Autoware agent COPY --chown=autoware . ./carla-autoware @@ -52,5 +58,12 @@ RUN echo "export CARLA_AUTOWARE_CONTENTS=~/autoware-contents" >> .bashrc \ && echo "source ~/carla_ws/devel/setup.bash" >> .bashrc \ && echo "source ~/Autoware/install/setup.bash" >> .bashrc -CMD ["/bin/bash"] +# (Optional) Install vscode +RUN apt-get update +RUN apt-get install -y software-properties-common apt-transport-https wget +RUN wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | apt-key add - +RUN add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" +RUN apt-get -y install code +USER root +CMD ["/bin/bash"] diff --git a/carla-autoware-agent/agent/bridge.launch b/carla-autoware-agent/agent/bridge.launch index e777f65..f0ce999 100644 --- a/carla-autoware-agent/agent/bridge.launch +++ b/carla-autoware-agent/agent/bridge.launch @@ -15,16 +15,16 @@ - + - + - + - + - + - - + + - + @@ -54,7 +54,7 @@ @@ -68,11 +68,10 @@ - diff --git a/run.sh b/run.sh index e7fc143..164653b 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Default settings +USER_ID="$(id -u)" +XAUTH=$HOME/.Xauthority + RUNTIME="" DOCKER_VERSION=$(docker version --format '{{.Client.Version}}' | cut --delimiter=. --fields=1,2) if [[ $DOCKER_VERSION < "19.03" ]] && ! type nvidia-docker; then @@ -10,10 +14,11 @@ fi docker run \ -it --rm \ - --volume=$(pwd)/autoware-contents:/home/autoware/autoware-contents:ro \ + --volume=$(pwd)/autoware-contents:/home/autoware/autoware-contents:rw \ + --env="XAUTHORITY=${XAUTH}" \ --env="DISPLAY=${DISPLAY}" \ + --env="USER_ID=$USER_ID" \ --privileged \ --net=host \ $RUNTIME \ carla-autoware:latest - diff --git a/update_code.patch b/update_code.patch new file mode 100644 index 0000000..906cac1 --- /dev/null +++ b/update_code.patch @@ -0,0 +1,50 @@ +diff --git a/carla_simulator_bridge/carla_autoware_bridge/launch/carla_autoware_bridge.launch b/carla_simulator_bridge/carla_autoware_bridge/launch/carla_autoware_bridge.launch +index a4be5dd..549ab17 100644 +--- a/carla_simulator_bridge/carla_autoware_bridge/launch/carla_autoware_bridge.launch ++++ b/carla_simulator_bridge/carla_autoware_bridge/launch/carla_autoware_bridge.launch +@@ -7,6 +7,7 @@ + + + ++ + + + +@@ -16,13 +17,10 @@ + + + +- +- +- +- +- +- +- ++ ++ ++ ++ + + + +@@ -53,4 +51,3 @@ + + + +- +diff --git a/vehicle_gazebo_simulation_launcher/launch/rviz_test.launch b/vehicle_gazebo_simulation_launcher/launch/rviz_test.launch +index 97225f8..8574844 100644 +--- a/vehicle_gazebo_simulation_launcher/launch/rviz_test.launch ++++ b/vehicle_gazebo_simulation_launcher/launch/rviz_test.launch +@@ -8,7 +8,7 @@ + + + +- ++ + + +- +\ No newline at end of file ++ diff --git a/update_sim.patch b/update_sim.patch index 762fec3..cfcab54 100644 --- a/update_sim.patch +++ b/update_sim.patch @@ -1,4 +1,4 @@ 25c25 < version: 1.14.0 --- -> version: master +> version: master From a98190cd5d6fff3279a15b75a3f1e7434d8f3e88 Mon Sep 17 00:00:00 2001 From: Peng Xu Date: Tue, 18 Jan 2022 13:41:57 -0800 Subject: [PATCH 2/4] Update Dockefile and open permision to modify inside the container. --- Dockerfile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d77e0b..eb8e8ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,21 @@ ARG AUTOWARE_VERSION=latest-melodic-cuda FROM autoware/autoware:$AUTOWARE_VERSION +USER autoware +ENV USERNAME autoware + WORKDIR /home/autoware # Update simulation repo to latest master. -COPY --chown=autoware update_sim.patch ./Autoware -RUN patch ./Autoware/autoware.ai.repos ./Autoware/update_sim.patch +COPY --chown=autoware update_sim.patch /home/$USERNAME/Autoware +RUN patch ./Autoware/autoware.ai.repos /home/$USERNAME/Autoware/update_sim.patch # Change code in simulation package. -COPY --chown=autoware update_code.patch ./Autoware/src/autoware/simulation -RUN cd ./Autoware \ +COPY --chown=autoware update_code.patch /home/$USERNAME/Autoware/src/autoware/simulation +RUN cd /home/$USERNAME/Autoware \ && vcs import src < autoware.ai.repos \ - && cd src/autoware/simulation && git apply update_code.patch + && cd /home/$USERNAME/Autoware/src/autoware/simulation \ + && git apply update_code.patch # Compile with colcon build. RUN cd ./Autoware \ @@ -30,6 +34,7 @@ RUN echo "export PYTHON2_EGG=$(ls /home/autoware/PythonAPI | grep py2.)" >> .bas # the latest ros-melodic-ackermann-msgs and ros-melodic-derived-objects-msgs packages. As a # workaround we use a snapshot of the ROS apt repository to install an older version of the required # packages. +USER root RUN rm -f /etc/apt/sources.list.d/ros1-latest.list RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA RUN sh -c 'echo "deb http://snapshots.ros.org/melodic/2020-08-07/ubuntu $(lsb_release -sc) main" >> /etc/apt/sources.list.d/ros-snapshots.list' @@ -41,6 +46,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* RUN pip install transforms3d simple-pid pygame networkx==2.2 +USER autoware + RUN git clone -b '0.9.11' --recurse-submodules https://github.com/carla-simulator/ros-bridge.git # CARLA Autoware agent @@ -58,6 +65,8 @@ RUN echo "export CARLA_AUTOWARE_CONTENTS=~/autoware-contents" >> .bashrc \ && echo "source ~/carla_ws/devel/setup.bash" >> .bashrc \ && echo "source ~/Autoware/install/setup.bash" >> .bashrc +USER root + # (Optional) Install vscode RUN apt-get update RUN apt-get install -y software-properties-common apt-transport-https wget @@ -65,5 +74,4 @@ RUN wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | apt-key add RUN add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" RUN apt-get -y install code -USER root CMD ["/bin/bash"] From 461be0876ac60cb25636beae58673079073ef512 Mon Sep 17 00:00:00 2001 From: Peng Xu Date: Tue, 18 Jan 2022 13:43:58 -0800 Subject: [PATCH 3/4] Update readme. --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 54bcea2..a19eba3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The carla autoware bridge is now hosted and maintained [here](https://github.com This repository contains a demonstrator of an autoware agent ready to be executed with CARLA. -**The carla autoware integration requires CARLA 0.9.10.1. You can download it from [here](https://github.com/carla-simulator/carla/releases/tag/0.9.10.1)** +**The carla autoware integration requires CARLA 0.9.11. You can download it from [here](https://github.com/carla-simulator/carla/releases/tag/0.9.11)** ## CARLA autoware agent The autoware agent is provided as a ROS package. All the configuration can be found inside the `carla-autoware-agent` folder. @@ -42,7 +42,7 @@ This will generate a `carla-autoware:latest` docker image. ./CarlaUE4.sh ``` -2. Run the `carla-autoware` image: +2. Run the `carla-autoware` image: ```sh ./run.sh @@ -56,4 +56,3 @@ roslaunch carla_autoware_agent carla_autoware_agent.launch town:=Town01 ## CARLA Autoware contents The [autoware-contents](https://bitbucket.org/carla-simulator/autoware-contents.git) repository contains additional data required to run Autoware with CARLA, including the point cloud maps, vector maps and configuration files. - From 930a6531951f9edcdc8f6e4cc9f4c43b45e73043 Mon Sep 17 00:00:00 2001 From: Peng Xu Date: Wed, 16 Feb 2022 16:16:27 -0800 Subject: [PATCH 4/4] Add a patch to fix tf tree error between ego and sensors. --- Dockerfile | 19 ++++-- update_ros_bridge.patch | 63 ++++++++++++++++++++ update_code.patch => update_sim_code.patch | 0 update_sim.patch => update_sim_version.patch | 0 4 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 update_ros_bridge.patch rename update_code.patch => update_sim_code.patch (100%) rename update_sim.patch => update_sim_version.patch (100%) diff --git a/Dockerfile b/Dockerfile index eb8e8ec..9d48189 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,16 +7,16 @@ ENV USERNAME autoware WORKDIR /home/autoware -# Update simulation repo to latest master. -COPY --chown=autoware update_sim.patch /home/$USERNAME/Autoware -RUN patch ./Autoware/autoware.ai.repos /home/$USERNAME/Autoware/update_sim.patch +# Update autoware/simulation package version to latest. +COPY --chown=autoware update_sim_version.patch /home/$USERNAME/Autoware +RUN patch ./Autoware/autoware.ai.repos /home/$USERNAME/Autoware/update_sim_version.patch -# Change code in simulation package. -COPY --chown=autoware update_code.patch /home/$USERNAME/Autoware/src/autoware/simulation +# Change code in autoware/simulation package. +COPY --chown=autoware update_sim_code.patch /home/$USERNAME/Autoware/src/autoware/simulation RUN cd /home/$USERNAME/Autoware \ && vcs import src < autoware.ai.repos \ && cd /home/$USERNAME/Autoware/src/autoware/simulation \ - && git apply update_code.patch + && git apply update_sim_code.patch # Compile with colcon build. RUN cd ./Autoware \ @@ -50,6 +50,13 @@ USER autoware RUN git clone -b '0.9.11' --recurse-submodules https://github.com/carla-simulator/ros-bridge.git +# Update code in carla-ros-bridge package and fix the tf tree issue. +# The fix has been introduced in latest version (since 0.9.12): +# https://github.com/carla-simulator/ros-bridge/pull/570/commits/9f903cf43c4ef3dd0b909721e044c62a8796f841 +COPY --chown=autoware update_ros_bridge.patch /home/$USERNAME/ros-bridge +RUN cd /home/$USERNAME/ros-bridge \ + && git apply update_ros_bridge.patch + # CARLA Autoware agent COPY --chown=autoware . ./carla-autoware diff --git a/update_ros_bridge.patch b/update_ros_bridge.patch new file mode 100644 index 0000000..43ff4e6 --- /dev/null +++ b/update_ros_bridge.patch @@ -0,0 +1,63 @@ +diff --git a/carla_ros_bridge/src/carla_ros_bridge/actor_factory.py b/carla_ros_bridge/src/carla_ros_bridge/actor_factory.py +index e3b0667..91bd78b 100755 +--- a/carla_ros_bridge/src/carla_ros_bridge/actor_factory.py ++++ b/carla_ros_bridge/src/carla_ros_bridge/actor_factory.py +@@ -112,7 +112,7 @@ class ActorFactory(object): + for actor_id in new_actors: + carla_actor = self.world.get_actor(actor_id) + if self.node.parameters["register_all_sensors"] or not isinstance(carla_actor, carla.Sensor): +- self._create_object_from_actor(carla_actor) ++ self._create_object_from_actor(carla_actor, None) + + for actor_id in deleted_actors: + self._destroy_object(actor_id, delete_actor=False) +@@ -123,7 +123,8 @@ class ActorFactory(object): + task = self._task_queue.get() + if task[0] == ActorFactory.TaskType.SPAWN_ACTOR and not self.node.shutdown.is_set(): + carla_actor = self.world.get_actor(task[1][0]) +- self._create_object_from_actor(carla_actor) ++ relative_transform = task[1][1].transform ++ self._create_object_from_actor(carla_actor, relative_transform) + elif task[0] == ActorFactory.TaskType.SPAWN_PSEUDO_ACTOR and not self.node.shutdown.is_set(): + pseudo_object = task[1] + self._create_object(pseudo_object[0], pseudo_object[1].type, pseudo_object[1].id, +@@ -169,7 +170,7 @@ class ActorFactory(object): + self._task_queue.put((ActorFactory.TaskType.SPAWN_PSEUDO_ACTOR, (id_, req))) + else: + id_ = self._spawn_carla_actor(req) +- self._task_queue.put((ActorFactory.TaskType.SPAWN_ACTOR, (id_, None))) ++ self._task_queue.put((ActorFactory.TaskType.SPAWN_ACTOR, (id_, req))) + self._known_actor_ids.append(id_) + return id_ + +@@ -222,26 +223,20 @@ class ActorFactory(object): + carla_actor = self.world.spawn_actor(blueprint, transform, attach_to) + return carla_actor.id + +- def _create_object_from_actor(self, carla_actor): ++ def _create_object_from_actor(self, carla_actor, relative_transform): + """ + create a object for a given carla actor + Creates also the object for its parent, if not yet existing + """ + parent = None + # the transform relative to the map +- relative_transform = trans.carla_transform_to_ros_pose(carla_actor.get_transform()) ++ if relative_transform == None: ++ relative_transform = trans.carla_transform_to_ros_pose(carla_actor.get_transform()) + if carla_actor.parent: + if carla_actor.parent.id in self.actors: + parent = self.actors[carla_actor.parent.id] + else: +- parent = self._create_object_from_actor(carla_actor.parent) +- # calculate relative transform to the parent +- actor_transform_matrix = trans.ros_pose_to_transform_matrix(relative_transform) +- parent_transform_matrix = trans.ros_pose_to_transform_matrix( +- trans.carla_transform_to_ros_pose(carla_actor.parent.get_transform())) +- relative_transform_matrix = np.matrix( +- parent_transform_matrix).getI() * np.matrix(actor_transform_matrix) +- relative_transform = trans.transform_matrix_to_ros_pose(relative_transform_matrix) ++ parent = self._create_object_from_actor(carla_actor.parent, None) + + parent_id = 0 + if parent is not None: diff --git a/update_code.patch b/update_sim_code.patch similarity index 100% rename from update_code.patch rename to update_sim_code.patch diff --git a/update_sim.patch b/update_sim_version.patch similarity index 100% rename from update_sim.patch rename to update_sim_version.patch