From 06ab3d6547b7d2d708b48990f1c889499934dfe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:18:54 +0200 Subject: [PATCH 1/6] update --- dependencies.repos | 13 +++ docker-compose.yaml | 191 ++++++++++++++++++++++++++++++++++++++++++++ docker/Dockerfile | 89 +++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 dependencies.repos create mode 100644 docker-compose.yaml create mode 100644 docker/Dockerfile diff --git a/dependencies.repos b/dependencies.repos new file mode 100644 index 0000000..12e6b41 --- /dev/null +++ b/dependencies.repos @@ -0,0 +1,13 @@ +repositories: + + # CPS Bot Mini Dependencies + + odrive_ros2_control: + type: git + url: https://github.com/bjoernellens1/odrive_ros2_control + version: humble-fw-v0.5.1 + + Lslidar_ROS2_driver: + type: git + url: https://github.com/bjoernellens1/Lslidar_ROS2_driver + version: N10_V1.0 \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..2bb5036 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,191 @@ +version: "3.9" + +services: + # Base image containing dependencies. + base: + image: ghcr.io/bjoernellens1/ros2_rmp/rmp:base + build: + context: . + dockerfile: docker/Dockerfile + args: + ROS_DISTRO: humble + target: base + x-bake: + platforms: + - linux/arm64 + - linux/amd64 + + # Interactive shell + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + # Needed to display graphical applications + privileged: true + environment: + # Allows graphical programs in the container. + - DISPLAY=${DISPLAY} + - QT_X11_NO_MITSHM=1 + - NVIDIA_DRIVER_CAPABILITIES=all + volumes: + # Allows graphical programs in the container. + - /tmp/.X11-unix:/tmp/.X11-unix:rw + - ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority + + # Overlay image containing the project specific source code. + overlay: + extends: base + image: ghcr.io/bjoernellens1/ros2_rmp/rmp:overlay + build: + context: . + dockerfile: docker/Dockerfile + tags: + - ghcr.io/bjoernellens1/ros2_rmp/rmp:overlay + target: overlay + x-bake: + platforms: + - linux/arm64 + - linux/amd64 + volumes: + - .:/repo + + # Additional dependencies for GUI applications + guis: + extends: overlay + image: ghcr.io/bjoernellens1/ros2_rmp/rmp:guis + build: + context: . + dockerfile: docker/Dockerfile + tags: + - ghcr.io/bjoernellens1/ros2_rmp/rmp:guis + target: guis + x-bake: + platforms: + - linux/arm64 + - linux/amd64 + #entrypoint: /bin/bash + command: > + /bin/bash + + # Robot State Publisher + robot_state_publisher: + extends: overlay + command: > + ros2 launch cps_rmp220_support rsp.launch.py --ros-args -r __ns:=/probeNamespace + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + + # Controller + controller: + extends: overlay + command: > + ros2 launch cps_rmp220_support robot_controller.launch.py __ns:=/probeNamespace + devices: + - /dev/ttyUSB0:/dev/ttyUSB0 + - /dev/ttyACM0:/dev/ttyACM0 + - /dev/input/js0:/dev/input/js0 + # Interactive shell + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + # Needed to display graphical applications + privileged: true + # depends_on: + # - robot_state_publisher + + # teleop + teleop: + extends: overlay + command: > + ros2 launch cps_rmp220_support robot_joystick.launch.py + devices: + - /dev/ttyUSB0:/dev/ttyUSB0 + - /dev/ttyACM0:/dev/ttyACM0 + - /dev/input/js0:/dev/input/js0 + # Interactive shell + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + # Needed to display graphical applications + privileged: true + + # lidar + lidar: + extends: overlay + command: > + ros2 launch cps_rmp220_support robot_lidar.launch.py + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + depends_on: + - robot_state_publisher + + # mapping + mapping: + extends: overlay + command: > + ros2 launch cps_rmp220_support robot_mapping.launch.py + # Interactive shell + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + + # navigation + navigation: + extends: overlay + command: > + ros2 launch cps_rmp220_support robot_navigation.launch.py + map_subscribe_transient_local:=true + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + + # bash + bash: + extends: overlay + command: > + /bin/bash + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + + # rviz2 + rviz2: + extends: guis + # command: > + # ros2 launch cps_rmp220_support robot_rviz2.launch.py + command: > + rviz2 + # Interactive shell + stdin_open: true + tty: true + # Networking and IPC for ROS 2 + network_mode: host + ipc: host + # Needed to display graphical applications + privileged: true + environment: + # Allows graphical programs in the container. + - DISPLAY=${DISPLAY} + - QT_X11_NO_MITSHM=1 + - NVIDIA_DRIVER_CAPABILITIES=all + volumes: + # Allows graphical programs in the container. + - /tmp/.X11-unix:/tmp/.X11-unix:rw + - ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..72a5bb2 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,89 @@ +ARG ROS_DISTRO=humble +ARG UNDERLAY_WS=/bot_mini_ws +ARG OVERLAY_WS=/bot_mini_ws + +# This file should work for both amd64 and arm64 builds. + +######################################## +# Base Image for Bot Mini Control # +######################################## +FROM ros:${ROS_DISTRO} as base +ENV ROS_DISTRO=${ROS_DISTRO} +ENV UNDERLAY_WS=${UNDERLAY_WS} + +SHELL ["/bin/bash", "-c"] + +# Create Colcon workspace with external dependencies +RUN mkdir -p /${UNDERLAY_WS}/src +WORKDIR /${UNDERLAY_WS}/src +COPY dependencies.repos . + +#RUN vcs import < dependencies.repos +RUN vcs import < dependencies.repos; + +# Build the base Colcon workspace, installing dependencies first. +WORKDIR /${UNDERLAY_WS} +RUN source /opt/ros/${ROS_DISTRO}/setup.bash \ + && apt-get update -y \ + && rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y \ + && colcon build --symlink-install \ + && rm -rf /var/lib/apt/lists/* + +# Use Cyclone DDS as middleware +RUN apt-get update && apt-get install -y --no-install-recommends \ + ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \ + ros-${ROS_DISTRO}-xacro \ + && rm -rf /var/lib/apt/lists/* + +ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + +########################################### +# Overlay Image for Bot Mini Control # +########################################### +FROM base AS overlay + +ENV OVERLAY_WS=${OVERLAY_WS} + +# Create an overlay Colcon workspace +RUN mkdir -p /${OVERLAY_WS}/src +WORKDIR /${OVERLAY_WS}/src +COPY overlay.repos . +RUN vcs import < overlay.repos + +WORKDIR /${OVERLAY_WS} + +RUN source /${UNDERLAY_WS}/install/setup.bash \ + && colcon build --symlink-install \ + && apt-get update \ + && rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y \ + && rm -rf /var/lib/apt/lists/* + +# Set up the entrypoint +COPY ./docker/entrypoint.sh / +RUN chmod +x /entrypoint.sh + +COPY ./controller_startup.sh / +RUN chmod +x /controller_startup.sh + +COPY ./localization_startup.sh / +RUN chmod +x /localization_startup.sh + +ENTRYPOINT [ "/entrypoint.sh" ] + +########################################### +# GUI Additions for Ros2 # +########################################### +FROM overlay AS guis + +# Install additional GUI tools +RUN source /${UNDERLAY_WS}/install/setup.bash \ + && colcon build --symlink-install \ + && apt-get update \ + && apt-get install -y --no-install-recommends ros-${ROS_DISTRO}-rviz2 \ + && rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y \ + && rm -rf /var/lib/apt/lists/* + +# Set up the entrypoint +ENTRYPOINT [ "/entrypoint.sh" ] + +LABEL org.opencontainers.image.source=https://github.com/bjoernellens1/ros2_rmp \ No newline at end of file From 7c22e027e072999052d7ef3015e0fbe6be056944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:36:47 +0200 Subject: [PATCH 2/6] update --- docker-compose.yaml | 50 +++++++++++++++------------------------------ docker/Dockerfile | 2 +- overlay.repos | 33 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 overlay.repos diff --git a/docker-compose.yaml b/docker-compose.yaml index 2bb5036..ea1ea37 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,10 +3,12 @@ version: "3.9" services: # Base image containing dependencies. base: - image: ghcr.io/bjoernellens1/ros2_rmp/rmp:base + image: ghcr.io/bjoernellens1/ros2-base:humble build: context: . dockerfile: docker/Dockerfile + tags: + - ghcr.io/bjoernellens1/ros2-base:humble args: ROS_DISTRO: humble target: base @@ -14,7 +16,6 @@ services: platforms: - linux/arm64 - linux/amd64 - # Interactive shell stdin_open: true tty: true @@ -36,12 +37,12 @@ services: # Overlay image containing the project specific source code. overlay: extends: base - image: ghcr.io/bjoernellens1/ros2_rmp/rmp:overlay + image: ghcr.io/bjoernellens1/cps_bot_mini_ws/bot:overlay build: context: . dockerfile: docker/Dockerfile tags: - - ghcr.io/bjoernellens1/ros2_rmp/rmp:overlay + - ghcr.io/bjoernellens1/cps_bot_mini_ws/bot:overlay target: overlay x-bake: platforms: @@ -53,18 +54,17 @@ services: # Additional dependencies for GUI applications guis: extends: overlay - image: ghcr.io/bjoernellens1/ros2_rmp/rmp:guis + image: ghcr.io/bjoernellens1/cps_bot_mini_ws/bot:guis build: context: . dockerfile: docker/Dockerfile tags: - - ghcr.io/bjoernellens1/ros2_rmp/rmp:guis + - ghcr.io/bjoernellens1/cps_bot_mini_ws/bot:guis target: guis x-bake: platforms: - linux/arm64 - linux/amd64 - #entrypoint: /bin/bash command: > /bin/bash @@ -72,7 +72,7 @@ services: robot_state_publisher: extends: overlay command: > - ros2 launch cps_rmp220_support rsp.launch.py --ros-args -r __ns:=/probeNamespace + ros2 launch bot_mini_bringup rsp.launch.py stdin_open: true tty: true # Networking and IPC for ROS 2 @@ -83,11 +83,10 @@ services: controller: extends: overlay command: > - ros2 launch cps_rmp220_support robot_controller.launch.py __ns:=/probeNamespace + ros2 launch bot_mini_bringup robot_controller.launch.py devices: - /dev/ttyUSB0:/dev/ttyUSB0 - /dev/ttyACM0:/dev/ttyACM0 - - /dev/input/js0:/dev/input/js0 # Interactive shell stdin_open: true tty: true @@ -96,17 +95,13 @@ services: ipc: host # Needed to display graphical applications privileged: true - # depends_on: - # - robot_state_publisher # teleop teleop: extends: overlay command: > - ros2 launch cps_rmp220_support robot_joystick.launch.py + ros2 launch bot_mini_bringup robot_joy_teleop.launch.py devices: - - /dev/ttyUSB0:/dev/ttyUSB0 - - /dev/ttyACM0:/dev/ttyACM0 - /dev/input/js0:/dev/input/js0 # Interactive shell stdin_open: true @@ -121,20 +116,22 @@ services: lidar: extends: overlay command: > - ros2 launch cps_rmp220_support robot_lidar.launch.py + ros2 launch cbot_mini_bringup robot_lidar.launch.py + devices: + - /dev/ttyUSB0:/dev/ttyUSB0 + - /dev/ttyUSB1:/dev/ttyUSB1 + - /dev/ttyACM0:/dev/ttyACM0 stdin_open: true tty: true # Networking and IPC for ROS 2 network_mode: host ipc: host - depends_on: - - robot_state_publisher # mapping mapping: extends: overlay command: > - ros2 launch cps_rmp220_support robot_mapping.launch.py + ros2 launch bot_mini_bringup robot_mapper.launch.py # Interactive shell stdin_open: true tty: true @@ -146,30 +143,17 @@ services: navigation: extends: overlay command: > - ros2 launch cps_rmp220_support robot_navigation.launch.py + ros2 launch cbot_mini_bringup robot_navigation.launch.py map_subscribe_transient_local:=true stdin_open: true tty: true # Networking and IPC for ROS 2 network_mode: host ipc: host - - # bash - bash: - extends: overlay - command: > - /bin/bash - stdin_open: true - tty: true - # Networking and IPC for ROS 2 - network_mode: host - ipc: host # rviz2 rviz2: extends: guis - # command: > - # ros2 launch cps_rmp220_support robot_rviz2.launch.py command: > rviz2 # Interactive shell diff --git a/docker/Dockerfile b/docker/Dockerfile index 72a5bb2..2ea7e23 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -86,4 +86,4 @@ RUN source /${UNDERLAY_WS}/install/setup.bash \ # Set up the entrypoint ENTRYPOINT [ "/entrypoint.sh" ] -LABEL org.opencontainers.image.source=https://github.com/bjoernellens1/ros2_rmp \ No newline at end of file +LABEL org.opencontainers.image.source=https://github.com/bjoernellens1/cps_bot_mini_ws \ No newline at end of file diff --git a/overlay.repos b/overlay.repos new file mode 100644 index 0000000..d61bcda --- /dev/null +++ b/overlay.repos @@ -0,0 +1,33 @@ +repositories: + + cps_rmp220_support: + type: git + url: https://github.com/bjoernellens1/cps_rmp220_support.git + version: main + + rmp220_teleop: + type: git + url: https://github.com/bjoernellens1/rmp220_teleop.git + version: main + + cam_openCV: + type: git + url: https://github.com/bjoernellens1/ros2_cam_openCV.git + version: main + + bot_mini_teleop: + type: git + url: https://github.com/bjoernellens1/rmp220_teleop + version: bot_mini + + bot_mini_description: + type: git + url: https://github.com/bjoernellens1/bot_mini_description + + cam_openCV: + type: git + url: https://github.com/bjoernellens1/ros2_cam_openCV + + bot_mini_bringup: + type: git + url: https://github.com/bjoernellens1/bot_mini_bringup \ No newline at end of file From db47b6a78ca01e2f6efa94d4e7e004a50ad093ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:44:16 +0200 Subject: [PATCH 3/6] update --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c4ef14a..5822738 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,22 @@ # cps_bot_mini_ws + +Now working via Docker! +Follow the instructions: To use this you need the latest Docker installed and for the multiplatform build the binfmt dependencies for your system. Otherwise just use the pre-built Docker containers. I will try to make the images available public. + +Run: +For instance on your PC: + docker compose run guis +This will launch the "guis" container where you will find a full ros2 humble installation and all the dependencies this robot needs. + +On the robot: + docker compose up -d controller teleop + + +### Attention: do not launch docker compose without arguments else you will start all services at once and you won't need them. + + +Old-fashioned way: + temporary ws for developing ros2 control on robot mini with odrive needed repos are: From bbb134379f138c819ab8f0c8ef3660748577ce43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:51:19 +0200 Subject: [PATCH 4/6] update --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5822738..50466b5 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,19 @@ Follow the instructions: To use this you need the latest Docker installed and fo Run: For instance on your PC: +``` docker compose run guis +``` + This will launch the "guis" container where you will find a full ros2 humble installation and all the dependencies this robot needs. On the robot: +``` docker compose up -d controller teleop +``` + +So as you can see, you will be working from the same git repository as well on the robot and your dev PC. +For the fact all can run inside Docker makes the project super portable so everyone should be able to tinker around with it. Nice bonus perks: You won't interfere with your computer's local environment. With Docker you are even able to run multiple versions of ROS simultanously, even on unsupported Linux operating systems like Debian or NixOS. Also on MacOS. Windows might be possible but not tested. ### Attention: do not launch docker compose without arguments else you will start all services at once and you won't need them. @@ -30,7 +38,9 @@ For initialization, just call "python3 initialize.py" TODO: extend bot_mini_bringup, python scripts for simplyfiyng startup process. ## Useful commands: +``` rosdep install --from-paths src --ignore-src -r -y +``` ### Localization using predefined map and navigation @@ -52,9 +62,13 @@ These are the options that allows to configure the process real-time settings: Example using ros2 launch: -ros2 launch pendulum_bringup pendulum_bringup.launch.py priority:=80 cpu-affinity:=4 lock-memory-size:=100 config-child-threads:=True +``` +ros2 launch pendulum_bringup pendulum_bringup.launch.py priority:=80 cpu-affinity:=4 lock-memory-size:=100 config-child-threads:=True +``` Example using the executable command line arguments: -ros2 run pendulum_demo pendulum_demo --priority 80 --cpu-affinity:=4 --lock-memory-size 100 --config-child-threads True +``` +ros2 run pendulum_demo pendulum_demo --priority 80 --cpu-affinity:=4 --lock-memory-size 100 --config-child-threads True +``` Source: https://github.com/ros2-realtime-demo/pendulum/blob/rolling/docs/real_time_tutorial.md From 8f850ab8a8d45e878ff7e53354a30ffeeefb40c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:56:42 +0200 Subject: [PATCH 5/6] update --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50466b5..0032df4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # cps_bot_mini_ws -Now working via Docker! +## Now working via Docker! Follow the instructions: To use this you need the latest Docker installed and for the multiplatform build the binfmt dependencies for your system. Otherwise just use the pre-built Docker containers. I will try to make the images available public. +First let's check if you are able to pull the pre-built images: +``` + docker pull ghcr.io/bjoernellens1/bot_mini_ws/bot:overlay + docker pull ghcr.io/bjoernellens1/bot_mini_ws/bot:guis +``` + Run: For instance on your PC: ``` @@ -22,8 +28,15 @@ For the fact all can run inside Docker makes the project super portable so every ### Attention: do not launch docker compose without arguments else you will start all services at once and you won't need them. +For building your own images: +I would advise to fork the repository and start working in your own one. +``` + docker buildx bake overlay --load +``` +This will allow you to modify the images to your needs. Enjoy! -Old-fashioned way: + +## Old-fashioned way: temporary ws for developing ros2 control on robot mini with odrive From 361840971379a317073343d86f42b74758411531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Wed, 2 Aug 2023 16:58:57 +0200 Subject: [PATCH 6/6] update --- docker/Dockerfile | 6 ------ docker/entrypoint.sh | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 docker/entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 2ea7e23..b757f88 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -62,12 +62,6 @@ RUN source /${UNDERLAY_WS}/install/setup.bash \ COPY ./docker/entrypoint.sh / RUN chmod +x /entrypoint.sh -COPY ./controller_startup.sh / -RUN chmod +x /controller_startup.sh - -COPY ./localization_startup.sh / -RUN chmod +x /localization_startup.sh - ENTRYPOINT [ "/entrypoint.sh" ] ########################################### diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..c7d19f8 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Basic entrypoint for ROS / Colcon Docker containers + +# Source ROS 2 +source /opt/ros/${ROS_DISTRO}/setup.bash +echo "Sourced ROS 2 ${ROS_DISTRO}" + +# Source the base workspace, if built +if [ -f ${UNDERLAY_WS}/install/setup.bash ] +then + source ${UNDERLAY_WS}/install/setup.bash + echo "Sourced CPS Bot Mini base workspace" +fi + +# Source the overlay workspace, if built +if [ -f /overlay_ws/install/setup.bash ] +then + source /overlay_ws/install/setup.bash + echo "Sourced CPS BOt Mini Overlay workspace" +fi + +# Execute the command passed into this entrypoint +exec "$@" \ No newline at end of file