Skip to content

Commit

Permalink
Merge pull request #40 from husarion/ros2-combined-microros
Browse files Browse the repository at this point in the history
MicroROS Agent combined bringup
  • Loading branch information
DominikN authored Dec 5, 2023
2 parents 299d1a1 + c36e834 commit 297f452
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ros-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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
- dockerfile: Dockerfile.hardware
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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vulcanexus-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 44 additions & 30 deletions Dockerfile.simulation → Dockerfile.gazebo
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 \
Expand All @@ -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 '<version>' | sed -r 's/.*<version>([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 '<version>' | sed -r 's/.*<version>([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"]
109 changes: 66 additions & 43 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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
FROM ubuntu:18.04 AS stm32flash_builder

ARG ROS_DISTRO
ARG ROSBOT_FW_RELEASE
Expand All @@ -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

## =========================== Firmware CPU ID ================================

FROM ubuntu:20.04 AS cpu_id_builder
Expand All @@ -50,48 +48,41 @@ RUN pip3 install -U platformio && \
pio run && \
chmod -x .pio/build/olimex_e407/firmware.bin

## =========================== 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 --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 && \
# 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/ && \
rosdep install --from-paths src --ignore-src -y


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 \
Expand All @@ -101,34 +92,66 @@ 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 \
admittance_controller \
bicycle_steering_controller \
tricycle_steering_controller \
effort_controllers \
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 \
tricycle_steering_controller \
velocity_controllers && \
rm -rf build 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 && \
apt-get remove -y \
git \
python3-colcon-common-extensions \
python3-rosdep \
python3-vcstool \
python3-pip \
build-essential && \
echo $(cat /ros2_ws/src/rosbot/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
rm -rf src && \
rm -rf /var/lib/apt/lists/*

RUN echo $(cat /ros2_ws/src/rosbot/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt
# 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

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 --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin

COPY ros_entrypoint.sh /
COPY vulcanexus_entrypoint.sh /
COPY healthcheck.sh /

COPY ./healthcheck.sh /
HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \
CMD ["/healthcheck.sh"]

COPY microros_localhost_only.xml /

# copy scripts
COPY flash-firmware.py /
COPY flash-firmware.py /usr/bin/
Expand Down
12 changes: 0 additions & 12 deletions demo/.env

This file was deleted.

18 changes: 10 additions & 8 deletions demo/compose.simulation.yaml → demo/compose.gazebo.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,9 +20,11 @@ x-cpu-config:

services:
rosbot:
image: husarion/rosbot-gazebo:humble
<<: [ *net-config, *gpu-config]
# image: husarion/rosbot-gazebo:humble
build:
context: ../
dockerfile: Dockerfile.gazebo
<<: [ *cpu-config]
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- /dev:/dev
command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False}
25 changes: 10 additions & 15 deletions demo/compose.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 297f452

Please sign in to comment.