From e614e1b8e1e59981912c16cb121a6716f306fd0c Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 1 Dec 2023 20:34:52 +0100 Subject: [PATCH 01/11] combined.launch.py is working fine --- Dockerfile.hardware | 22 ++++++++++++++++----- demo/compose.combined.yaml | 18 ++++++++++++++++++ demo/namespace/compose.yaml | 38 +++++++++++++++++++++++++++++++++++++ demo/namespace/filter.yaml | 5 +++++ microros_localhost_only.xml | 26 +++++++++++++++++++++++++ ros_entrypoint.sh | 22 +++++++++++++++++++++ sync_with_rosbot.sh | 8 ++++---- vulcanexus_entrypoint.sh | 22 +++++++++++++++++++++ 8 files changed, 152 insertions(+), 9 deletions(-) create mode 100644 demo/compose.combined.yaml create mode 100644 demo/namespace/compose.yaml create mode 100644 demo/namespace/filter.yaml create mode 100644 microros_localhost_only.xml create mode 100755 ros_entrypoint.sh create mode 100755 vulcanexus_entrypoint.sh diff --git a/Dockerfile.hardware b/Dockerfile.hardware index d33fe6c..7e8217a 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -1,6 +1,6 @@ ARG ROS_DISTRO=humble ARG PREFIX= -ARG ROSBOT_FW_RELEASE=0.7.0 +ARG ROSBOT_FW_RELEASE=0.8.0 ## ============================ STM32FLASH ================================= # stm32flash needs an older version of glibc (2.28), which is why ubuntu 18.04 was used FROM ubuntu:18.04 AS stm32flash_builder_and_downloader @@ -26,7 +26,7 @@ RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE RUN curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.bin -o /firmware.bin && \ curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.hex -o /firmware.hex -RUN git clone https://github.com/husarion/rosbot_ros.git /ros2_ws/src +RUN git clone https://github.com/husarion/rosbot_ros.git /ros2_ws/src -b ros2-combined-microros ## =========================== Firmware CPU ID ================================ @@ -50,6 +50,10 @@ RUN pip3 install -U platformio && \ pio run && \ chmod -x .pio/build/olimex_e407/firmware.bin +## =========================== Micro ROS agent =============================== + +FROM husarion/micro-ros-agent:humble-3.1.3-20231122 AS microros_agent_getter + ## =========================== ROS image =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core @@ -115,20 +119,28 @@ RUN apt-get update && apt-get install -y \ RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt -RUN if [ -f "/ros_entrypoint.sh" ]; then \ +COPY ros_entrypoint.sh / +COPY vulcanexus_entrypoint.sh / + +RUN if [[ ${PREFIX} == 'vulcanexus-' ]]; then \ sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ ros2 run healthcheck_pkg healthcheck_node &' \ - /ros_entrypoint.sh; \ + /vulcanexus_entrypoint.sh; \ else \ sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ ros2 run healthcheck_pkg healthcheck_node &' \ - /vulcanexus_entrypoint.sh; \ + /ros_entrypoint.sh; \ fi COPY ./healthcheck.sh / HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ CMD ["/healthcheck.sh"] +# copy micro-ros agent + +COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent +COPY microros_localhost_only.xml / + # copy scripts COPY flash-firmware.py / COPY flash-firmware.py /usr/bin/ diff --git a/demo/compose.combined.yaml b/demo/compose.combined.yaml new file mode 100644 index 0000000..2d0e488 --- /dev/null +++ b/demo/compose.combined.yaml @@ -0,0 +1,18 @@ +services: + + rosbot: + build: + context: ../ + dockerfile: Dockerfile.hardware + devices: + - ${SERIAL_PORT:?err} + environment: + - ROS_DOMAIN_ID=123 + - ROS_LOCALHOST_ONLY=1 + command: > + ros2 launch rosbot_bringup combined.launch.py + mecanum:=${MECANUM:-False} + serial_port:=$SERIAL_PORT + serial_baudrate:=576000 + + diff --git a/demo/namespace/compose.yaml b/demo/namespace/compose.yaml new file mode 100644 index 0000000..85f2039 --- /dev/null +++ b/demo/namespace/compose.yaml @@ -0,0 +1,38 @@ +services: + + rosbot: + build: + context: ../../ + dockerfile: Dockerfile.hardware + network_mode: host + ipc: host + devices: + - ${SERIAL_PORT:?err} + environment: + - FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml + command: > + ros2 launch rosbot_bringup combined.launch.py + mecanum:=${MECANUM:-False} + serial_port:=$SERIAL_PORT + serial_baudrate:=576000 + namespace:=robot1 + + ros2router: + image: husarnet/ros2router:release-1.4.0 + network_mode: host + ipc: host + volumes: + - ./filter.yaml:/filter.yaml + environment: + - USE_HUSARNET=FALSE + - ROS_LOCALHOST_ONLY=1 + - ROS_DISTRO + +# 1. run `docker-compose up` on the robot +# 2. On the second host in LAN you will see only single ros2 topic: +# $ ros2 topic list +# /parameter_events +# /robot1/cmd_vel +# /rosout +# 3. You can use teleop_twist_keyboard to control the robot in robot1 namespace: +# `ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/robot1` \ No newline at end of file diff --git a/demo/namespace/filter.yaml b/demo/namespace/filter.yaml new file mode 100644 index 0000000..a6da4ee --- /dev/null +++ b/demo/namespace/filter.yaml @@ -0,0 +1,5 @@ +allowlist: + - name: "rt/robot1/cmd_vel" + type: "geometry_msgs::msg::dds_::Twist_" +blocklist: [] +builtin-topics: [] \ No newline at end of file diff --git a/microros_localhost_only.xml b/microros_localhost_only.xml new file mode 100644 index 0000000..d433142 --- /dev/null +++ b/microros_localhost_only.xml @@ -0,0 +1,26 @@ + + + + + + + CustomUdpTransport + UDPv4 + +
127.0.0.1
+
+
+
+ + + + + CustomUdpTransport + + + false + + +
+
\ No newline at end of file diff --git a/ros_entrypoint.sh b/ros_entrypoint.sh new file mode 100755 index 0000000..f0da6dc --- /dev/null +++ b/ros_entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +output=$(husarnet-dds singleshot) || true +if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then + echo "$output" +fi + +# Check if XRCE_DOMAIN_ID_OVERRIDE is unset or empty +if [ -z "$XRCE_DOMAIN_ID_OVERRIDE" ]; then + # If ROS_DOMAIN_ID is set and not empty, set XRCE_DOMAIN_ID_OVERRIDE to its value + if [ -n "$ROS_DOMAIN_ID" ]; then + export XRCE_DOMAIN_ID_OVERRIDE="$ROS_DOMAIN_ID" + fi +fi + +# setup ros environment +source "/opt/ros/$ROS_DISTRO/setup.bash" +source "/ros2_ws/install/setup.bash" +source "/ros2_ws_microros_agent/install/setup.bash" + +exec "$@" diff --git a/sync_with_rosbot.sh b/sync_with_rosbot.sh index 2dbd9c5..f4a2738 100755 --- a/sync_with_rosbot.sh +++ b/sync_with_rosbot.sh @@ -3,8 +3,8 @@ # If your ROSbot's IP addr is 10.5.10.64 execute: # ./sync_with_rosbot.sh 10.5.10.64 -sshpass -p "husarion" rsync -vRr ./ husarion@$1:/home/husarion/${PWD##*/} +sshpass -p "husarion" rsync -vRr --delete ./ husarion@$1:/home/husarion/${PWD##*/} -while inotifywait -r -e modify,create,delete,move ./ ; do - sshpass -p "husarion" rsync -vRr ./ husarion@$1:/home/husarion/${PWD##*/} -done +while inotifywait -r -e modify,create,delete,move ./ ; do + sshpass -p "husarion" rsync -vRr --delete ./ husarion@$1:/home/husarion/${PWD##*/} +done \ No newline at end of file diff --git a/vulcanexus_entrypoint.sh b/vulcanexus_entrypoint.sh new file mode 100755 index 0000000..e362a3b --- /dev/null +++ b/vulcanexus_entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +output=$(husarnet-dds singleshot) || true +if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then + echo "$output" +fi + +# Check if XRCE_DOMAIN_ID_OVERRIDE is unset or empty +if [ -z "$XRCE_DOMAIN_ID_OVERRIDE" ]; then + # If ROS_DOMAIN_ID is set and not empty, set XRCE_DOMAIN_ID_OVERRIDE to its value + if [ -n "$ROS_DOMAIN_ID" ]; then + export XRCE_DOMAIN_ID_OVERRIDE="$ROS_DOMAIN_ID" + fi +fi + +# setup ros environment +source "/opt/vulcanexus/$ROS_DISTRO/setup.bash" +source "/ros2_ws/install/setup.bash" +source "/ros2_ws_microros_agent/install/setup.bash" + +exec "$@" From 217e6ad8ce4202de7cc36c9f13ff7b651df8b92b Mon Sep 17 00:00:00 2001 From: dominikn Date: Sun, 3 Dec 2023 20:22:54 +0100 Subject: [PATCH 02/11] working on new dockerfile --- Dockerfile | 157 ++++++++++++++++++++++++++++++++++++ demo/compose.combined.yaml | 6 +- demo/namespace/compose.yaml | 4 +- 3 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6fa7a20 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,157 @@ +ARG ROS_DISTRO=humble +ARG PREFIX= +ARG ROSBOT_FW_RELEASE=0.8.0 +## ============================ STM32FLASH ================================= +# stm32flash needs an older version of glibc (2.28), which is why ubuntu 18.04 was used +FROM ubuntu:18.04 AS stm32flash_builder + +ARG ROS_DISTRO +ARG ROSBOT_FW_RELEASE + +SHELL ["/bin/bash", "-c"] + +# official releases are only for intel archs, so we need to build stm32flash from sources +RUN apt-get update && apt-get install -y \ + curl \ + git \ + build-essential \ + cmake && \ + git clone https://github.com/stm32duino/stm32flash.git && \ + cd stm32flash/ && \ + make all + +RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE + +# Copy firmware binaries +RUN curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.bin -o /firmware.bin && \ + curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.hex -o /firmware.hex + +## =========================== Firmware CPU ID ================================ + +FROM ubuntu:20.04 AS cpu_id_builder + +ARG ROSBOT_FW_RELEASE + +SHELL ["/bin/bash", "-c"] + +# official releases are only for intel archs, so we need to build stm32flash from sources +RUN apt-get update && apt-get install -y \ + curl \ + python3 \ + python3-pip + +# build a binary for reading the CPU ID +COPY read_cpu_id/ /read_cpu_id + +RUN pip3 install -U platformio && \ + cd /read_cpu_id && \ + pio run && \ + chmod -x .pio/build/olimex_e407/firmware.bin + +## =========================== Micro ROS agent =============================== + +FROM husarion/micro-ros-agent:humble-3.1.3-20231122 AS microros_agent_getter + +## =========================== ROS builder =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder + +ARG ROS_DISTRO +ARG PREFIX + +SHELL ["/bin/bash", "-c"] + +WORKDIR /ros2_ws +RUN mkdir src + +COPY ./healthcheck.cpp / + +RUN apt-get update && apt-get install -y \ + git \ + python3-pip \ + python3-sh \ + python3-periphery && \ + pip3 install pyserial && \ + MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ + git clone https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ + vcs import src < src/rosbot/rosbot_hardware.repos && \ + # it is necessary to remove simulation - otherwise rosdep tries to install dependencies + rm -r src/rosbot_gazebo && \ + # without this line (using vulcanexus base image) rosdep init throws error: "ERROR: default sources list file already exists:" + rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ + # Create health check package + cd src/ && \ + source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ + ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ + sed -i '/find_package(nav_msgs REQUIRED)/a \ + add_executable(healthcheck_node src/healthcheck.cpp)\n \ + ament_target_dependencies(healthcheck_node rclcpp nav_msgs)\n \ + install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \ + /ros2_ws/src/healthcheck_pkg/CMakeLists.txt && \ + mv /healthcheck.cpp /ros2_ws/src/healthcheck_pkg/src/ && \ + cd .. && \ + # Build + colcon build + +# RUN rosdep install --from-paths src --rosdistro $ROS_DISTRO -y --simulate >> rosdep.log +RUN rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y --simulate >> rosdep.log + +## =========================== Final Stage =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core + +ARG ROS_DISTRO +ARG PREFIX + +SHELL ["/bin/bash", "-c"] + +WORKDIR /ros2_ws + +COPY --from=ros_builder /ros2_ws /ros2_ws + +RUN apt-get update && apt-get install -y \ + python3-rosdep \ + ros-$ROS_DISTRO-teleop-twist-keyboard && \ + rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# copy firmware built in previous stage and downloaded repository +COPY --from=stm32flash_builder /firmware.bin /root/firmware.bin +COPY --from=stm32flash_builder /firmware.hex /root/firmware.hex +COPY --from=stm32flash_builder /stm32flash/stm32flash /usr/bin/stm32flash + +COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin + +RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt + +COPY ros_entrypoint.sh / +COPY vulcanexus_entrypoint.sh / + +RUN if [[ ${PREFIX} == 'vulcanexus-' ]]; then \ + sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ + ros2 run healthcheck_pkg healthcheck_node &' \ + /vulcanexus_entrypoint.sh; \ + else \ + sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ + ros2 run healthcheck_pkg healthcheck_node &' \ + /ros_entrypoint.sh; \ + fi + +COPY ./healthcheck.sh / +HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ + CMD ["/healthcheck.sh"] + +# copy micro-ros agent + +COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent +COPY microros_localhost_only.xml / + +# copy scripts +COPY flash-firmware.py / +COPY flash-firmware.py /usr/bin/ +COPY print-serial-number.py /usr/bin/ diff --git a/demo/compose.combined.yaml b/demo/compose.combined.yaml index 2d0e488..71a037a 100644 --- a/demo/compose.combined.yaml +++ b/demo/compose.combined.yaml @@ -1,9 +1,9 @@ services: rosbot: - build: - context: ../ - dockerfile: Dockerfile.hardware + # build: + # context: ../ + # dockerfile: Dockerfile.hardware devices: - ${SERIAL_PORT:?err} environment: diff --git a/demo/namespace/compose.yaml b/demo/namespace/compose.yaml index 85f2039..0ddc09f 100644 --- a/demo/namespace/compose.yaml +++ b/demo/namespace/compose.yaml @@ -1,9 +1,11 @@ services: rosbot: + # image: rosbot-local build: context: ../../ - dockerfile: Dockerfile.hardware + dockerfile: Dockerfile + # dockerfile: Dockerfile.hardware network_mode: host ipc: host devices: From 4cc21cc850f4ce347525f0cd51e3eddd03b151c5 Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 14:16:08 +0100 Subject: [PATCH 03/11] building micro_ros_agent inside robot_ros package --- Dockerfile | 46 +++++++++++++++++++--------------------- ros_entrypoint.sh | 3 ++- vulcanexus_entrypoint.sh | 3 ++- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6fa7a20..8aead8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,9 +48,6 @@ RUN pip3 install -U platformio && \ pio run && \ chmod -x .pio/build/olimex_e407/firmware.bin -## =========================== Micro ROS agent =============================== - -FROM husarion/micro-ros-agent:humble-3.1.3-20231122 AS microros_agent_getter ## =========================== ROS builder =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder @@ -80,9 +77,10 @@ RUN apt-get update && apt-get install -y \ rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ - # Create health check package - cd src/ && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y + + # Create health check package and build +RUN cd src/ && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ sed -i '/find_package(nav_msgs REQUIRED)/a \ @@ -93,10 +91,22 @@ RUN apt-get update && apt-get install -y \ mv /healthcheck.cpp /ros2_ws/src/healthcheck_pkg/src/ && \ cd .. && \ # Build - colcon build - -# RUN rosdep install --from-paths src --rosdistro $ROS_DISTRO -y --simulate >> rosdep.log -RUN rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y --simulate >> rosdep.log + colcon build --packages-skip \ + ackermann_steering_controller \ + bicycle_steering_controller \ + tricycle_steering_controller \ + ros2_controllers \ + effort_controllers \ + admittance_controller \ + force_torque_sensor_broadcaster \ + forward_command_controller \ + gripper_controllers \ + joint_trajectory_controller \ + position_controllers \ + rqt_joint_trajectory_controller \ + tricycle_controller \ + velocity_controllers \ + ros2_controllers_test_nodes ## =========================== Final Stage =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core @@ -131,24 +141,12 @@ RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.* COPY ros_entrypoint.sh / COPY vulcanexus_entrypoint.sh / +COPY healthcheck.sh / -RUN if [[ ${PREFIX} == 'vulcanexus-' ]]; then \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /vulcanexus_entrypoint.sh; \ - else \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /ros_entrypoint.sh; \ - fi - -COPY ./healthcheck.sh / HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ CMD ["/healthcheck.sh"] -# copy micro-ros agent - -COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent +# COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent COPY microros_localhost_only.xml / # copy scripts diff --git a/ros_entrypoint.sh b/ros_entrypoint.sh index f0da6dc..21341ce 100755 --- a/ros_entrypoint.sh +++ b/ros_entrypoint.sh @@ -17,6 +17,7 @@ fi # setup ros environment source "/opt/ros/$ROS_DISTRO/setup.bash" source "/ros2_ws/install/setup.bash" -source "/ros2_ws_microros_agent/install/setup.bash" + +ros2 run healthcheck_pkg healthcheck_node & exec "$@" diff --git a/vulcanexus_entrypoint.sh b/vulcanexus_entrypoint.sh index e362a3b..950ae45 100755 --- a/vulcanexus_entrypoint.sh +++ b/vulcanexus_entrypoint.sh @@ -17,6 +17,7 @@ fi # setup ros environment source "/opt/vulcanexus/$ROS_DISTRO/setup.bash" source "/ros2_ws/install/setup.bash" -source "/ros2_ws_microros_agent/install/setup.bash" + +ros2 run healthcheck_pkg healthcheck_node & exec "$@" From e36b578ebc37b322572807f330ff94449ca1f860 Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 15:57:18 +0100 Subject: [PATCH 04/11] cleaner dockerfile for building hardware --- Dockerfile | 155 -------------------------------------------- Dockerfile.hardware | 103 +++++++++++++++-------------- 2 files changed, 55 insertions(+), 203 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8aead8b..0000000 --- a/Dockerfile +++ /dev/null @@ -1,155 +0,0 @@ -ARG ROS_DISTRO=humble -ARG PREFIX= -ARG ROSBOT_FW_RELEASE=0.8.0 -## ============================ STM32FLASH ================================= -# stm32flash needs an older version of glibc (2.28), which is why ubuntu 18.04 was used -FROM ubuntu:18.04 AS stm32flash_builder - -ARG ROS_DISTRO -ARG ROSBOT_FW_RELEASE - -SHELL ["/bin/bash", "-c"] - -# official releases are only for intel archs, so we need to build stm32flash from sources -RUN apt-get update && apt-get install -y \ - curl \ - git \ - build-essential \ - cmake && \ - git clone https://github.com/stm32duino/stm32flash.git && \ - cd stm32flash/ && \ - make all - -RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE - -# Copy firmware binaries -RUN curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.bin -o /firmware.bin && \ - curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.hex -o /firmware.hex - -## =========================== Firmware CPU ID ================================ - -FROM ubuntu:20.04 AS cpu_id_builder - -ARG ROSBOT_FW_RELEASE - -SHELL ["/bin/bash", "-c"] - -# official releases are only for intel archs, so we need to build stm32flash from sources -RUN apt-get update && apt-get install -y \ - curl \ - python3 \ - python3-pip - -# build a binary for reading the CPU ID -COPY read_cpu_id/ /read_cpu_id - -RUN pip3 install -U platformio && \ - cd /read_cpu_id && \ - pio run && \ - chmod -x .pio/build/olimex_e407/firmware.bin - - -## =========================== ROS builder =============================== -FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder - -ARG ROS_DISTRO -ARG PREFIX - -SHELL ["/bin/bash", "-c"] - -WORKDIR /ros2_ws -RUN mkdir src - -COPY ./healthcheck.cpp / - -RUN apt-get update && apt-get install -y \ - git \ - python3-pip \ - python3-sh \ - python3-periphery && \ - pip3 install pyserial && \ - MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ - git clone https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ - vcs import src < src/rosbot/rosbot_hardware.repos && \ - # it is necessary to remove simulation - otherwise rosdep tries to install dependencies - rm -r src/rosbot_gazebo && \ - # without this line (using vulcanexus base image) rosdep init throws error: "ERROR: default sources list file already exists:" - rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ - rosdep init && \ - rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y - - # Create health check package and build -RUN cd src/ && \ - source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ - ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ - sed -i '/find_package(nav_msgs REQUIRED)/a \ - add_executable(healthcheck_node src/healthcheck.cpp)\n \ - ament_target_dependencies(healthcheck_node rclcpp nav_msgs)\n \ - install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \ - /ros2_ws/src/healthcheck_pkg/CMakeLists.txt && \ - mv /healthcheck.cpp /ros2_ws/src/healthcheck_pkg/src/ && \ - cd .. && \ - # Build - colcon build --packages-skip \ - ackermann_steering_controller \ - bicycle_steering_controller \ - tricycle_steering_controller \ - ros2_controllers \ - effort_controllers \ - admittance_controller \ - force_torque_sensor_broadcaster \ - forward_command_controller \ - gripper_controllers \ - joint_trajectory_controller \ - position_controllers \ - rqt_joint_trajectory_controller \ - tricycle_controller \ - velocity_controllers \ - ros2_controllers_test_nodes - -## =========================== Final Stage =============================== -FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core - -ARG ROS_DISTRO -ARG PREFIX - -SHELL ["/bin/bash", "-c"] - -WORKDIR /ros2_ws - -COPY --from=ros_builder /ros2_ws /ros2_ws - -RUN apt-get update && apt-get install -y \ - python3-rosdep \ - ros-$ROS_DISTRO-teleop-twist-keyboard && \ - rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ - rosdep init && \ - rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# copy firmware built in previous stage and downloaded repository -COPY --from=stm32flash_builder /firmware.bin /root/firmware.bin -COPY --from=stm32flash_builder /firmware.hex /root/firmware.hex -COPY --from=stm32flash_builder /stm32flash/stm32flash /usr/bin/stm32flash - -COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin - -RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt - -COPY ros_entrypoint.sh / -COPY vulcanexus_entrypoint.sh / -COPY healthcheck.sh / - -HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ - CMD ["/healthcheck.sh"] - -# COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent -COPY microros_localhost_only.xml / - -# copy scripts -COPY flash-firmware.py / -COPY flash-firmware.py /usr/bin/ -COPY print-serial-number.py /usr/bin/ diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 7e8217a..4697c9f 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -3,7 +3,7 @@ ARG PREFIX= ARG ROSBOT_FW_RELEASE=0.8.0 ## ============================ STM32FLASH ================================= # stm32flash needs an older version of glibc (2.28), which is why ubuntu 18.04 was used -FROM ubuntu:18.04 AS stm32flash_builder_and_downloader +FROM ubuntu:18.04 AS stm32flash_builder ARG ROS_DISTRO ARG ROSBOT_FW_RELEASE @@ -26,8 +26,6 @@ RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE RUN curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.bin -o /firmware.bin && \ curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.hex -o /firmware.hex -RUN git clone https://github.com/husarion/rosbot_ros.git /ros2_ws/src -b ros2-combined-microros - ## =========================== Firmware CPU ID ================================ FROM ubuntu:20.04 AS cpu_id_builder @@ -50,41 +48,27 @@ RUN pip3 install -U platformio && \ pio run && \ chmod -x .pio/build/olimex_e407/firmware.bin -## =========================== Micro ROS agent =============================== - -FROM husarion/micro-ros-agent:humble-3.1.3-20231122 AS microros_agent_getter -## =========================== ROS image =============================== -FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core +## =========================== ROS builder =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder ARG ROS_DISTRO ARG PREFIX SHELL ["/bin/bash", "-c"] -RUN mkdir -p /ros2_ws/src && cd /ros2_ws/src WORKDIR /ros2_ws +RUN mkdir src -# copy firmware built in previous stage and downloaded repository -COPY --from=stm32flash_builder_and_downloader /firmware.bin /root/firmware.bin -COPY --from=stm32flash_builder_and_downloader /firmware.hex /root/firmware.hex -COPY --from=stm32flash_builder_and_downloader /stm32flash/stm32flash /usr/bin/stm32flash -COPY --from=stm32flash_builder_and_downloader /ros2_ws /ros2_ws -COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin COPY ./healthcheck.cpp / RUN apt-get update && apt-get install -y \ git \ python3-pip \ - python3-colcon-common-extensions \ - python3-rosdep \ - python3-vcstool \ python3-sh \ - python3-periphery \ - build-essential \ - ros-$ROS_DISTRO-teleop-twist-keyboard && \ + python3-periphery && \ pip3 install pyserial && \ - MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ + git clone https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ # it is necessary to remove simulation - otherwise rosdep tries to install dependencies rm -r src/rosbot_gazebo && \ @@ -92,9 +76,11 @@ RUN apt-get update && apt-get install -y \ rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ - # Create health check package - cd src/ && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y + + # Create health check package and build +RUN cd src/ && \ + MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ sed -i '/find_package(nav_msgs REQUIRED)/a \ @@ -105,40 +91,61 @@ RUN apt-get update && apt-get install -y \ mv /healthcheck.cpp /ros2_ws/src/healthcheck_pkg/src/ && \ cd .. && \ # Build - colcon build && \ - # clear ubuntu packages + colcon build --packages-skip \ + ackermann_steering_controller \ + bicycle_steering_controller \ + tricycle_steering_controller \ + ros2_controllers \ + effort_controllers \ + admittance_controller \ + force_torque_sensor_broadcaster \ + forward_command_controller \ + gripper_controllers \ + joint_trajectory_controller \ + position_controllers \ + rqt_joint_trajectory_controller \ + tricycle_controller \ + velocity_controllers \ + ros2_controllers_test_nodes + +## =========================== Final Stage =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core + +ARG ROS_DISTRO +ARG PREFIX + +SHELL ["/bin/bash", "-c"] + +WORKDIR /ros2_ws + +COPY --from=ros_builder /ros2_ws /ros2_ws + +RUN apt-get update && apt-get install -y \ + python3-rosdep \ + ros-$ROS_DISTRO-teleop-twist-keyboard && \ + rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ apt-get clean && \ - apt-get remove -y \ - git \ - python3-colcon-common-extensions \ - python3-rosdep \ - python3-vcstool \ - python3-pip \ - build-essential && \ rm -rf /var/lib/apt/lists/* +# copy firmware built in previous stage and downloaded repository +COPY --from=stm32flash_builder /firmware.bin /root/firmware.bin +COPY --from=stm32flash_builder /firmware.hex /root/firmware.hex +COPY --from=stm32flash_builder /stm32flash/stm32flash /usr/bin/stm32flash + +COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin + RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt COPY ros_entrypoint.sh / COPY vulcanexus_entrypoint.sh / +COPY healthcheck.sh / -RUN if [[ ${PREFIX} == 'vulcanexus-' ]]; then \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /vulcanexus_entrypoint.sh; \ - else \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /ros_entrypoint.sh; \ - fi - -COPY ./healthcheck.sh / HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ CMD ["/healthcheck.sh"] -# copy micro-ros agent - -COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent COPY microros_localhost_only.xml / # copy scripts From 27f9225a7de659bfba8eb7d47547be10c37dfbec Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 17:09:08 +0100 Subject: [PATCH 05/11] small fix --- Dockerfile.hardware | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 4697c9f..385cdbd 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -93,20 +93,22 @@ RUN cd src/ && \ # Build colcon build --packages-skip \ ackermann_steering_controller \ + admittance_controller \ bicycle_steering_controller \ tricycle_steering_controller \ - ros2_controllers \ effort_controllers \ - admittance_controller \ force_torque_sensor_broadcaster \ forward_command_controller \ gripper_controllers \ joint_trajectory_controller \ position_controllers \ + range_sensor_broadcaster \ + ros2_controllers \ + ros2_controllers_test_nodes \ rqt_joint_trajectory_controller \ tricycle_controller \ - velocity_controllers \ - ros2_controllers_test_nodes + tricycle_steering_controller \ + velocity_controllers ## =========================== Final Stage =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core From f974875290026fd68f3c120fd4c7f388e22a11dc Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 18:40:23 +0100 Subject: [PATCH 06/11] make the final image smaller --- Dockerfile.hardware | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 385cdbd..95a4456 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -108,7 +108,8 @@ RUN cd src/ && \ rqt_joint_trajectory_controller \ tricycle_controller \ tricycle_steering_controller \ - velocity_controllers + velocity_controllers && \ + rm -rf build log src ## =========================== Final Stage =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core From 1350de2506770a0198b63c4369ff7bd35f8d7623 Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 19:20:41 +0100 Subject: [PATCH 07/11] small fixes --- Dockerfile.hardware | 2 +- demo/namespace/compose.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 95a4456..a4fbf1b 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -76,7 +76,7 @@ RUN apt-get update && apt-get install -y \ rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y + rosdep install --from-paths src --ignore-src -y # Create health check package and build RUN cd src/ && \ diff --git a/demo/namespace/compose.yaml b/demo/namespace/compose.yaml index 0ddc09f..85f2039 100644 --- a/demo/namespace/compose.yaml +++ b/demo/namespace/compose.yaml @@ -1,11 +1,9 @@ services: rosbot: - # image: rosbot-local build: context: ../../ - dockerfile: Dockerfile - # dockerfile: Dockerfile.hardware + dockerfile: Dockerfile.hardware network_mode: host ipc: host devices: From 68ff14770f37c359b543c534a7006894a453e63e Mon Sep 17 00:00:00 2001 From: dominikn Date: Mon, 4 Dec 2023 21:16:58 +0100 Subject: [PATCH 08/11] fix dockerfile --- Dockerfile.hardware | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index a4fbf1b..909b006 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -109,7 +109,7 @@ RUN cd src/ && \ tricycle_controller \ tricycle_steering_controller \ velocity_controllers && \ - rm -rf build log src + rm -rf build log ## =========================== Final Stage =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core @@ -131,6 +131,7 @@ RUN apt-get update && apt-get install -y \ rosdep update --rosdistro $ROS_DISTRO && \ rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ apt-get clean && \ + rm -rf src && \ rm -rf /var/lib/apt/lists/* # copy firmware built in previous stage and downloaded repository From c09dfe83e2c3dcd118ce952890c9db42d9285647 Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 5 Dec 2023 00:45:31 +0100 Subject: [PATCH 09/11] fix compose files --- demo/.env | 12 --------- demo/compose.combined.yaml | 18 ------------- ...se.simulation.yaml => compose.gazebo.yaml} | 13 +++++----- demo/compose.yaml | 25 +++++++----------- demo/namespace/compose.yaml | 26 +++++++++---------- demo/net.env | 17 ------------ 6 files changed, 29 insertions(+), 82 deletions(-) delete mode 100644 demo/.env delete mode 100644 demo/compose.combined.yaml rename demo/{compose.simulation.yaml => compose.gazebo.yaml} (59%) delete mode 100644 demo/net.env diff --git a/demo/.env b/demo/.env deleted file mode 100644 index 4e12be9..0000000 --- a/demo/.env +++ /dev/null @@ -1,12 +0,0 @@ -# ======================================= -# Hardware config -# ======================================= -LIDAR_SERIAL=/dev/ttyUSB0 - -# for RPLIDAR A2M8 (red circle around the sensor): -LIDAR_BAUDRATE=115200 -# for RPLIDAR A2M12 and A3 (violet circle around the sensor): -# LIDAR_BAUDRATE=256000 - -# uncomment for ROSbots with mecanum wheels -# MECANUM=True diff --git a/demo/compose.combined.yaml b/demo/compose.combined.yaml deleted file mode 100644 index 71a037a..0000000 --- a/demo/compose.combined.yaml +++ /dev/null @@ -1,18 +0,0 @@ -services: - - rosbot: - # build: - # context: ../ - # dockerfile: Dockerfile.hardware - devices: - - ${SERIAL_PORT:?err} - environment: - - ROS_DOMAIN_ID=123 - - ROS_LOCALHOST_ONLY=1 - command: > - ros2 launch rosbot_bringup combined.launch.py - mecanum:=${MECANUM:-False} - serial_port:=$SERIAL_PORT - serial_baudrate:=576000 - - diff --git a/demo/compose.simulation.yaml b/demo/compose.gazebo.yaml similarity index 59% rename from demo/compose.simulation.yaml rename to demo/compose.gazebo.yaml index 616a95c..e15dec4 100644 --- a/demo/compose.simulation.yaml +++ b/demo/compose.gazebo.yaml @@ -1,8 +1,8 @@ -x-net-config: - &net-config - network_mode: host - ipc: host - env_file: net.env +# 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 @@ -21,8 +21,7 @@ x-cpu-config: services: rosbot: image: husarion/rosbot-gazebo:humble - <<: [ *net-config, *gpu-config] + <<: [ *gpu-config] volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw - - /dev:/dev command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False} diff --git a/demo/compose.yaml b/demo/compose.yaml index 0226cba..860f4ee 100644 --- a/demo/compose.yaml +++ b/demo/compose.yaml @@ -1,25 +1,20 @@ -x-net-config: - &net-config - network_mode: host - ipc: host - env_file: net.env +# Quick Start +# +# 1. run `docker compose up` on the robot +# 2. run `ROS_DOMAIN_ID=10 ros2 run teleop_twist_keyboard teleop_twist_keyboard` in the robot termianl services: rosbot: - image: husarion/rosbot:humble - <<: *net-config + image: husarion/rosbot:humble-0.10.3-20231128 environment: - - ROS_DOMAIN_ID + - ROS_DOMAIN_ID=10 command: ros2 launch rosbot_bringup bringup.launch.py mecanum:=${MECANUM:-False} - - micro-xrce-agent: - image: husarion/micro-xrce-agent:v2.4.1 - <<: *net-config + micro-ros-agent: + image: husarion/micro-ros-agent:humble-3.1.3-20231122 devices: - ${SERIAL_PORT:?err} environment: - - XRCE_DOMAIN_ID_OVERRIDE=${ROS_DOMAIN_ID} # *** - - SERIAL_PORT - command: MicroXRCEAgent serial -D $SERIAL_PORT serial -b 576000 # -v6 + - ROS_DOMAIN_ID=10 + command: ros2 run micro_ros_agent micro_ros_agent serial -D $SERIAL_PORT serial -b 576000 # -v6 diff --git a/demo/namespace/compose.yaml b/demo/namespace/compose.yaml index 85f2039..78424ca 100644 --- a/demo/namespace/compose.yaml +++ b/demo/namespace/compose.yaml @@ -1,9 +1,18 @@ +# Quick Start +# +# 1. run `docker compose up` on the robot +# 2. On the second host in LAN you will see only single ros2 topic: +# $ ros2 topic list +# /parameter_events +# /robot1/cmd_vel +# /rosout +# 3. You can use teleop_twist_keyboard to control the robot in robot1 namespace: +# `ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/robot1` + services: rosbot: - build: - context: ../../ - dockerfile: Dockerfile.hardware + image: husarion/rosbot:humble-ros2-combined-microros network_mode: host ipc: host devices: @@ -18,7 +27,7 @@ services: namespace:=robot1 ros2router: - image: husarnet/ros2router:release-1.4.0 + image: husarnet/ros2router:1.4.0 network_mode: host ipc: host volumes: @@ -27,12 +36,3 @@ services: - USE_HUSARNET=FALSE - ROS_LOCALHOST_ONLY=1 - ROS_DISTRO - -# 1. run `docker-compose up` on the robot -# 2. On the second host in LAN you will see only single ros2 topic: -# $ ros2 topic list -# /parameter_events -# /robot1/cmd_vel -# /rosout -# 3. You can use teleop_twist_keyboard to control the robot in robot1 namespace: -# `ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/robot1` \ No newline at end of file diff --git a/demo/net.env b/demo/net.env deleted file mode 100644 index 029bdbe..0000000 --- a/demo/net.env +++ /dev/null @@ -1,17 +0,0 @@ -# ======================================= -# Network config options (uncomment one) -# ======================================= - -# 1. Fast DDS + LAN -# RMW_IMPLEMENTATION=rmw_fastrtps_cpp - -# 2. Cyclone DDS + LAN -RMW_IMPLEMENTATION=rmw_cyclonedds_cpp - -# 3. Fast DDS + VPN -# RMW_IMPLEMENTATION=rmw_fastrtps_cpp -# FASTRTPS_DEFAULT_PROFILES_FILE=/husarnet-fastdds.xml - -# 4. Cyclone DDS + VPN -# RMW_IMPLEMENTATION=rmw_cyclonedds_cpp -# CYCLONEDDS_URI=file:///husarnet-cyclonedds.xml From 9ac4775390012f4ec4b0e2543f657d2380bc51a5 Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 5 Dec 2023 09:54:09 +0100 Subject: [PATCH 10/11] fixes in gazebo dockerfile --- .github/workflows/ros-docker-image.yaml | 4 +- .../workflows/vulcanexus-docker-image.yaml | 2 +- Dockerfile.simulation => Dockerfile.gazebo | 74 +++++++++++-------- Dockerfile.hardware | 8 +- demo/compose.gazebo.yaml | 7 +- 5 files changed, 56 insertions(+), 39 deletions(-) rename Dockerfile.simulation => Dockerfile.gazebo (55%) diff --git a/.github/workflows/ros-docker-image.yaml b/.github/workflows/ros-docker-image.yaml index 34cce4c..f8fd7e0 100644 --- a/.github/workflows/ros-docker-image.yaml +++ b/.github/workflows/ros-docker-image.yaml @@ -43,7 +43,7 @@ jobs: repo_name: '' platforms: linux/amd64, linux/arm64 ros_distro: humble - - dockerfile: Dockerfile.simulation + - dockerfile: Dockerfile.gazebo repo_name: rosbot-gazebo platforms: linux/amd64 ros_distro: humble @@ -51,7 +51,7 @@ jobs: repo_name: '' platforms: linux/amd64, linux/arm64 ros_distro: iron - # - dockerfile: Dockerfile.simulation + # - dockerfile: Dockerfile.gazebo # repo_name: rosbot-gazebo # platforms: linux/amd64 # ros_distro: iron diff --git a/.github/workflows/vulcanexus-docker-image.yaml b/.github/workflows/vulcanexus-docker-image.yaml index 1ecd2be..4f64b52 100644 --- a/.github/workflows/vulcanexus-docker-image.yaml +++ b/.github/workflows/vulcanexus-docker-image.yaml @@ -43,7 +43,7 @@ jobs: repo_name: '' platforms: linux/amd64, linux/arm64 ros_distro: humble - - dockerfile: Dockerfile.simulation + - dockerfile: Dockerfile.gazebo repo_name: rosbot-gazebo platforms: linux/amd64 ros_distro: humble diff --git a/Dockerfile.simulation b/Dockerfile.gazebo similarity index 55% rename from Dockerfile.simulation rename to Dockerfile.gazebo index 74ccf8e..79cb433 100644 --- a/Dockerfile.simulation +++ b/Dockerfile.gazebo @@ -1,7 +1,8 @@ ARG ROS_DISTRO=humble ARG PREFIX= -FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core +## =========================== ROS builder =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder ARG PREFIX @@ -16,24 +17,24 @@ WORKDIR /ros2_ws COPY ./healthcheck.cpp / # install everything needed -RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ - apt-get update --fix-missing && apt-get install -y \ +RUN apt-get update --fix-missing && apt-get install -y \ python3-pip \ ros-dev-tools && \ apt-get upgrade -y && \ # Clone source - source "/opt/$MYDISTRO/$ROS_DISTRO/setup.bash" && \ - git clone https://github.com/husarion/rosbot_ros.git /ros2_ws/src && \ + git clone --depth 1 https://github.com/husarion/rosbot_ros.git src && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ vcs import src < src/rosbot/rosbot_simulation.repos && \ # Install dependencies rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ - rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ - # Create healthcheck package - cd src/ && \ + rosdep install --from-paths src --ignore-src -y + +RUN cd src/ && \ + MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ + # Create healthcheck package ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ sed -i '/find_package(nav_msgs REQUIRED)/a \ add_executable(healthcheck_node src/healthcheck.cpp)\n \ @@ -44,27 +45,40 @@ RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ cd .. && \ # Build colcon build && \ - # make the image smaller - export SUDO_FORCE_REMOVE=yes && \ - apt-get remove -y \ + rm -rf build log + +## =========================== Final Stage =============================== +FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core + +ARG ROS_DISTRO +ARG PREFIX + +# select bash as default shell +SHELL ["/bin/bash", "-c"] + +ENV IGNITION_VERSION fortress +ENV HUSARION_ROS_BUILD simulation + +WORKDIR /ros2_ws + +COPY --from=ros_builder /ros2_ws /ros2_ws + +RUN apt-get update && apt-get install -y \ + python3-rosdep \ python3-pip \ - ros-dev-tools && \ - apt-get autoremove -y && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -RUN echo $(cat /ros2_ws/src/rosbot_gazebo/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt - -RUN if [ -f "/ros_entrypoint.sh" ]; then \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /ros_entrypoint.sh; \ - else \ - sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \ - ros2 run healthcheck_pkg healthcheck_node &' \ - /vulcanexus_entrypoint.sh; \ - fi - -COPY ./healthcheck.sh / + ros-$ROS_DISTRO-teleop-twist-keyboard && \ + rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ + rosdep init && \ + rosdep update --rosdistro $ROS_DISTRO && \ + rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ + apt-get clean && \ + echo $(cat /ros2_ws/src/rosbot_gazebo/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt && \ + rm -rf src && \ + rm -rf /var/lib/apt/lists/* + +COPY ros_entrypoint.sh / +COPY vulcanexus_entrypoint.sh / +COPY healthcheck.sh / + HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ - CMD ["/healthcheck.sh"] + CMD ["/healthcheck.sh"] \ No newline at end of file diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 909b006..2e30761 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -68,7 +68,7 @@ RUN apt-get update && apt-get install -y \ python3-sh \ python3-periphery && \ pip3 install pyserial && \ - git clone https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ + git clone --depth 1 https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ # it is necessary to remove simulation - otherwise rosdep tries to install dependencies rm -r src/rosbot_gazebo && \ @@ -78,10 +78,11 @@ RUN apt-get update && apt-get install -y \ rosdep update --rosdistro $ROS_DISTRO && \ rosdep install --from-paths src --ignore-src -y - # Create health check package and build + RUN cd src/ && \ MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ + # Create health check package ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \ sed -i '/find_package(nav_msgs REQUIRED)/a \ add_executable(healthcheck_node src/healthcheck.cpp)\n \ @@ -131,6 +132,7 @@ RUN apt-get update && apt-get install -y \ rosdep update --rosdistro $ROS_DISTRO && \ rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ apt-get clean && \ + 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 src && \ rm -rf /var/lib/apt/lists/* @@ -141,8 +143,6 @@ COPY --from=stm32flash_builder /stm32flash/stm32flash /usr/bin/stm32flash COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin -RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt - COPY ros_entrypoint.sh / COPY vulcanexus_entrypoint.sh / COPY healthcheck.sh / diff --git a/demo/compose.gazebo.yaml b/demo/compose.gazebo.yaml index e15dec4..8e67483 100644 --- a/demo/compose.gazebo.yaml +++ b/demo/compose.gazebo.yaml @@ -20,8 +20,11 @@ x-cpu-config: services: rosbot: - image: husarion/rosbot-gazebo:humble - <<: [ *gpu-config] + # image: husarion/rosbot-gazebo:humble + build: + context: ../ + dockerfile: Dockerfile.gazebo + <<: [ *cpu-config] volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False} From c36e834b5fd154806e177acb6c0b51c688374951 Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 5 Dec 2023 19:06:13 +0100 Subject: [PATCH 11/11] fix before merging to prod --- Dockerfile.hardware | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 2e30761..153bf47 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -68,7 +68,7 @@ RUN apt-get update && apt-get install -y \ python3-sh \ python3-periphery && \ pip3 install pyserial && \ - git clone --depth 1 https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \ + git clone --depth 1 https://github.com/husarion/rosbot_ros.git src -b humble && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ # it is necessary to remove simulation - otherwise rosdep tries to install dependencies rm -r src/rosbot_gazebo && \