From d0d201d5465c605cac0bbd6536b6c17e4b5961e8 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Thu, 28 Nov 2024 10:45:46 +0100 Subject: [PATCH 1/5] Add hardware and sim Docker --- README.md | 4 +-- docker/.env | 2 +- docker/Dockerfile | 29 --------------- docker/Dockerfile.hardware | 34 ++++++++++++++++++ docker/Dockerfile.simulation | 35 +++++++++++++++++++ .../{compose.yaml => compose.hardware.yaml} | 10 ++---- docker/compose.simulation.yaml | 31 ++++++++++++++++ rosbot/package.xml | 2 +- 8 files changed, 107 insertions(+), 40 deletions(-) delete mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.hardware create mode 100644 docker/Dockerfile.simulation rename docker/{compose.yaml => compose.hardware.yaml} (54%) create mode 100644 docker/compose.simulation.yaml diff --git a/README.md b/README.md index 1114fce3..676fd890 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ git clone https://github.com/husarion/rosbot_ros src/rosbot_ros Building: ```bash -export HUSARION_ROS_BUILD=hardware +export HUSARION_ROS_BUILD_TYPE=hardware source /opt/ros/$ROS_DISTRO/setup.bash @@ -93,7 +93,7 @@ ros2 launch rosbot_bringup combined.launch.py Building: ```bash -export HUSARION_ROS_BUILD=simulation +export HUSARION_ROS_BUILD_TYPE=simulation source /opt/ros/$ROS_DISTRO/setup.bash diff --git a/docker/.env b/docker/.env index 9a9566ef..3692ed2f 100644 --- a/docker/.env +++ b/docker/.env @@ -1,2 +1,2 @@ SERIAL_PORT=/dev/ttyUSB0 -ROS_NAMESPACE=robot1 +ROS_NAMESPACE=rosbot diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 3dfb0f67..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -ARG ROS_DISTRO=humble - -FROM husarnet/ros:${ROS_DISTRO}-ros-base - -SHELL ["/bin/bash", "-c"] - -WORKDIR /ros2_ws - -COPY . src/ - -RUN apt-get update && apt-get install -y \ - python3-pip \ - stm32flash \ - ros-${ROS_DISTRO}-teleop-twist-keyboard - -RUN vcs import src < src/rosbot/rosbot_hardware.repos && \ - rm -r src/rosbot_gazebo - -# Create a script to install runtime dependencies for final image -RUN apt update && \ - rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} --reinstall --simulate -y --dependency-types exec >> /rosdep_install.sh && \ - chmod +x /rosdep_install.sh - -RUN apt update && \ - rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y && \ - source /opt/ros/$ROS_DISTRO/setup.bash && \ - colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \ - echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ - rm -rf build log src diff --git a/docker/Dockerfile.hardware b/docker/Dockerfile.hardware new file mode 100644 index 00000000..0d8ac161 --- /dev/null +++ b/docker/Dockerfile.hardware @@ -0,0 +1,34 @@ +ARG ROS_DISTRO=humble + +FROM husarnet/ros:${ROS_DISTRO}-ros-core + +WORKDIR /ros2_ws + +ENV HUSARION_ROS_BUILD_TYPE=hardware + +COPY .. src/rosbot_ros + +RUN apt-get update && apt-get install -y \ + python3-pip \ + ros-dev-tools \ + stm32flash \ + ros-${ROS_DISTRO}-teleop-twist-keyboard && \ + # Setup workspace + vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \ + rm -r src/rosbot_gazebo && \ + # Install dependencies + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install --from-paths src -y -i && \ + # Build + source /opt/ros/$ROS_DISTRO/setup.bash && \ + colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release && \ + # Get version + echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ + # Size optimization + export SUDO_FORCE_REMOVE=yes && \ + apt-get remove -y \ + ros-dev-tools && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* diff --git a/docker/Dockerfile.simulation b/docker/Dockerfile.simulation new file mode 100644 index 00000000..dc90ab5b --- /dev/null +++ b/docker/Dockerfile.simulation @@ -0,0 +1,35 @@ +ARG ROS_DISTRO=humble + +FROM husarnet/ros:${ROS_DISTRO}-ros-core + +WORKDIR /ros2_ws + +ENV HUSARION_ROS_BUILD_TYPE=simulation + +COPY .. src/rosbot_ros + +RUN apt-get update && apt-get install -y \ + python3-pip \ + ros-dev-tools \ + stm32flash \ + ros-${ROS_DISTRO}-teleop-twist-keyboard && \ + # Setup workspace + vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \ + vcs import src < src/rosbot_ros/rosbot/rosbot_simulation.repos && \ + cp -r src/ros2_controllers/imu_sensor_broadcaster src && rm -rf src/ros2_controllers && \ + # Install dependencies + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install --from-paths src -y -i && \ + # Build + source /opt/ros/$ROS_DISTRO/setup.bash && \ + colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release && \ + # Get version + echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ + # Size optimization + export SUDO_FORCE_REMOVE=yes && \ + apt-get remove -y \ + ros-dev-tools && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/compose.yaml b/docker/compose.hardware.yaml similarity index 54% rename from docker/compose.yaml rename to docker/compose.hardware.yaml index fb9aaf96..e28f7e0a 100644 --- a/docker/compose.yaml +++ b/docker/compose.hardware.yaml @@ -2,18 +2,14 @@ services: rosbot: build: context: .. - dockerfile: docker/Dockerfile + dockerfile: docker/Dockerfile.hardware network_mode: host ipc: host devices: - - ${SERIAL_PORT:?err} + - /dev/ttyUSB0 - /dev/bus/usb/ # FTDI - # environment: - # - ROS_NAMESPACE - # command: tail -f /dev/null command: > ros2 launch rosbot_bringup combined.launch.py mecanum:=${MECANUM:-False} - serial_port:=$SERIAL_PORT + serial_port:=/dev/ttyUSB0 serial_baudrate:=576000 - # namespace:=${ROS_NAMESPACE:-rosbot} diff --git a/docker/compose.simulation.yaml b/docker/compose.simulation.yaml new file mode 100644 index 00000000..bddae597 --- /dev/null +++ b/docker/compose.simulation.yaml @@ -0,0 +1,31 @@ +# Quick Start +# +# 1. run `xhost +local:docker && docker compose -f compose.gazebo.yaml up` on the laptop +# 2. open a shell inside a docker container `docker compose -f compose.gazebo.yaml exec -it rosbot bash` +# 2. run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container + +x-gpu-config: + &gpu-config + runtime: nvidia + environment: + - DISPLAY=${DISPLAY:?err} + - NVIDIA_VISIBLE_DEVICES=all + - NVIDIA_DRIVER_CAPABILITIES=all + +x-cpu-config: + &cpu-config + environment: + - DISPLAY=${DISPLAY:?err} + +services: + rosbot: + build: + context: .. + dockerfile: docker/Dockerfile.simulation + network_mode: host + ipc: host + <<: [ *gpu-config] + command: > + ros2 launch rosbot_gazebo simulation.launch.py + namespace:=${ROS_NAMESPACE:-""} + mecanum:=${MECANUM:-False} diff --git a/rosbot/package.xml b/rosbot/package.xml index 6533fef6..01d6d837 100644 --- a/rosbot/package.xml +++ b/rosbot/package.xml @@ -20,7 +20,7 @@ rosbot_description rosbot_utils - rosbot_gazebo + rosbot_gazebo ament_cmake From 4be5e6f42695d8360ddaf12f3b5488635d001b2c Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Thu, 28 Nov 2024 13:27:10 +0100 Subject: [PATCH 2/5] Fix hardware docker --- docker/.env | 1 - docker/Dockerfile.hardware | 2 +- docker/compose.hardware.yaml | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docker/.env b/docker/.env index 3692ed2f..bec99c89 100644 --- a/docker/.env +++ b/docker/.env @@ -1,2 +1 @@ -SERIAL_PORT=/dev/ttyUSB0 ROS_NAMESPACE=rosbot diff --git a/docker/Dockerfile.hardware b/docker/Dockerfile.hardware index 0d8ac161..19d85ec2 100644 --- a/docker/Dockerfile.hardware +++ b/docker/Dockerfile.hardware @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y \ ros-${ROS_DISTRO}-teleop-twist-keyboard && \ # Setup workspace vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \ - rm -r src/rosbot_gazebo && \ + rm -r src/rosbot_ros/rosbot_gazebo && \ # Install dependencies rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ diff --git a/docker/compose.hardware.yaml b/docker/compose.hardware.yaml index e28f7e0a..7083e47f 100644 --- a/docker/compose.hardware.yaml +++ b/docker/compose.hardware.yaml @@ -5,11 +5,15 @@ services: dockerfile: docker/Dockerfile.hardware network_mode: host ipc: host + restart: unless-stopped devices: - - /dev/ttyUSB0 + - ${SERIAL_PORT:-/dev/ttyUSB0} - /dev/bus/usb/ # FTDI + environment: + - FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml + - USER=${USER:-root} command: > ros2 launch rosbot_bringup combined.launch.py mecanum:=${MECANUM:-False} - serial_port:=/dev/ttyUSB0 + serial_port:=${SERIAL_PORT:-/dev/ttyUSB0} serial_baudrate:=576000 From 50572951020c8a243dc280dbbc11ba7b8aa3f8b8 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Thu, 28 Nov 2024 16:03:02 +0100 Subject: [PATCH 3/5] Fixes --- docker/.env | 2 +- docker/compose.hardware.yaml | 4 +--- docker/compose.simulation.yaml | 2 +- docker/justfile | 14 +++++++------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docker/.env b/docker/.env index bec99c89..05b532ca 100644 --- a/docker/.env +++ b/docker/.env @@ -1 +1 @@ -ROS_NAMESPACE=rosbot +ROBOT_NAMESPACE=rosbot diff --git a/docker/compose.hardware.yaml b/docker/compose.hardware.yaml index 7083e47f..259561e6 100644 --- a/docker/compose.hardware.yaml +++ b/docker/compose.hardware.yaml @@ -9,11 +9,9 @@ services: devices: - ${SERIAL_PORT:-/dev/ttyUSB0} - /dev/bus/usb/ # FTDI - environment: - - FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml - - USER=${USER:-root} command: > ros2 launch rosbot_bringup combined.launch.py mecanum:=${MECANUM:-False} + namespace:=${ROBOT_NAMESPACE:-rosbot} serial_port:=${SERIAL_PORT:-/dev/ttyUSB0} serial_baudrate:=576000 diff --git a/docker/compose.simulation.yaml b/docker/compose.simulation.yaml index bddae597..a927a1cd 100644 --- a/docker/compose.simulation.yaml +++ b/docker/compose.simulation.yaml @@ -27,5 +27,5 @@ services: <<: [ *gpu-config] command: > ros2 launch rosbot_gazebo simulation.launch.py - namespace:=${ROS_NAMESPACE:-""} mecanum:=${MECANUM:-False} + namespace:=${ROBOT_NAMESPACE:-rosbot} diff --git a/docker/justfile b/docker/justfile index 50fbe34d..0e6f5ef4 100644 --- a/docker/justfile +++ b/docker/justfile @@ -13,7 +13,7 @@ alias teleop := run-teleop-docker # run teleop_twist_keybaord (inside rviz2 container) run-teleop-docker: _run-as-user #!/bin/bash - docker compose exec rosbot /bin/bash -c "/ros_entrypoint.sh ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/${ROS_NAMESPACE}" + docker compose exec rosbot /bin/bash -c "/ros_entrypoint.sh ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/${ROBOT_NAMESPACE}" flash-firmware: _install-yq _run-as-user #!/bin/bash @@ -29,9 +29,9 @@ flash-firmware: _install-yq _run-as-user gpio_chip=/dev/gpiochip4 serial_port=/dev/ttyS4 else - echo "Probably user laptop" + echo "Probably user computer" gpio_chip=/dev/bus/usb - serial_port=$SERIAL_PORT + serial_port=/dev/ttyUSB0 enable_usb="--usb" fi @@ -42,13 +42,13 @@ flash-firmware: _install-yq _run-as-user docker-rosbot \ ros2 run rosbot_utils flash_firmware ${enable_usb} -run: +run_hardware: #/bin/bash - docker compose up + docker compose -f compose.hardware.yaml up -build: +build_hardware: #/bin/bash - docker compose build + docker compose -f compose.hardware.yaml build _run-as-root: #!/bin/bash From c0c92816f67b800fd7b49f579c00d8eace2eb610 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Mon, 2 Dec 2024 10:20:13 +0100 Subject: [PATCH 4/5] Use packages-up-to --- README.md | 4 ++-- docker/compose.hardware.yaml | 1 - rosbot/package.xml | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 676fd890..b6a697b9 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ rm -r src/rosbot_ros/rosbot_gazebo sudo rosdep init rosdep update --rosdistro $ROS_DISTRO rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y -colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release +colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release ``` Flash firmware: @@ -106,7 +106,7 @@ cp -r src/ros2_controllers/imu_sensor_broadcaster src && rm -rf src/ros2_control sudo rosdep init rosdep update --rosdistro $ROS_DISTRO rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y -colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release +colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release ``` Running: diff --git a/docker/compose.hardware.yaml b/docker/compose.hardware.yaml index 259561e6..564e1ccc 100644 --- a/docker/compose.hardware.yaml +++ b/docker/compose.hardware.yaml @@ -14,4 +14,3 @@ services: mecanum:=${MECANUM:-False} namespace:=${ROBOT_NAMESPACE:-rosbot} serial_port:=${SERIAL_PORT:-/dev/ttyUSB0} - serial_baudrate:=576000 diff --git a/rosbot/package.xml b/rosbot/package.xml index 01d6d837..7bfc85c3 100644 --- a/rosbot/package.xml +++ b/rosbot/package.xml @@ -18,9 +18,8 @@ rosbot_bringup rosbot_controller rosbot_description - rosbot_utils - rosbot_gazebo + rosbot_utils ament_cmake From cfc594292d3c627745f13b4fd763500971b94c46 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Mon, 2 Dec 2024 10:23:29 +0100 Subject: [PATCH 5/5] Add description to compose --- docker/compose.hardware.yaml | 6 ++++++ docker/compose.simulation.yaml | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docker/compose.hardware.yaml b/docker/compose.hardware.yaml index 564e1ccc..3ebcf58e 100644 --- a/docker/compose.hardware.yaml +++ b/docker/compose.hardware.yaml @@ -1,3 +1,9 @@ +# Quick Start +# +# 1. Run `docker compose -f compose.hardware.yaml up` on the ROSbot +# 2. Open a shell inside a docker container `docker compose -f compose.hardware.yaml exec -it rosbot bash` +# 3. Run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container + services: rosbot: build: diff --git a/docker/compose.simulation.yaml b/docker/compose.simulation.yaml index a927a1cd..9194cda1 100644 --- a/docker/compose.simulation.yaml +++ b/docker/compose.simulation.yaml @@ -1,8 +1,9 @@ # Quick Start # -# 1. run `xhost +local:docker && docker compose -f compose.gazebo.yaml up` on the laptop -# 2. open a shell inside a docker container `docker compose -f compose.gazebo.yaml exec -it rosbot bash` -# 2. run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container +# 1. Run `xhost +local:docker && docker compose -f compose.simulation.yaml up` on the laptop +# (optionally you can chang `gpu-config` -> `cpu config`). +# 2. Open a shell inside a docker container `docker compose -f compose.simulation.yaml exec -it rosbot bash` +# 3. Run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container x-gpu-config: &gpu-config