Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Healthcheck fix #49

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 56 additions & 61 deletions Dockerfile.gazebo
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
ARG ROS_DISTRO=humble
ARG PREFIX=

## =========================== Healthcheck builder ===============================

FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder
## =========================== Install all ROS dependencies ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core AS ros-core-with-dependencies

ARG ROS_DISTRO
ARG PREFIX
Expand All @@ -12,103 +11,99 @@ SHELL ["/bin/bash", "-c"]

WORKDIR /ros2_ws

RUN mkdir src && \
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 \
ament_target_dependencies(healthcheck_node rclcpp nav_msgs)\n \
install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \
/ros2_ws/src/healthcheck_pkg/CMakeLists.txt
RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
ros-dev-tools && \
# Clone source
git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
vcs import src < src/rosbot/rosbot_simulation.repos && \
cp -r src/ros2_controllers/diff_drive_controller src/ && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \
rm -rf src/ros2_controllers && \
# Install dependencies
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src --ignore-src -y && \
apt-get remove -y \
python3-pip \
python3-rosdep \
ros-dev-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*


## =========================== Healthcheck builder ===============================

FROM ros-core-with-dependencies AS healthcheck_builder

ARG ROS_DISTRO
ARG PREFIX

COPY healthcheck.cpp src/healthcheck_pkg/src/
WORKDIR /healthcheck_ws/src

COPY husarion_utils/healthcheck.cpp /healthcheck.cpp

RUN 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 sensor_msgs && \
sed -i '/find_package(sensor_msgs REQUIRED)/a \
add_executable(healthcheck_node src/healthcheck.cpp)\n \
ament_target_dependencies(healthcheck_node rclcpp nav_msgs sensor_msgs)\n \
install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \
./healthcheck_pkg/CMakeLists.txt && \
mv /healthcheck.cpp ./healthcheck_pkg/src/ && \
cd .. && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf build log src

## =========================== ROS builder ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder
FROM ros-core-with-dependencies AS ros_builder

ARG PREFIX

# select bash as default shell
SHELL ["/bin/bash", "-c"]

ENV IGNITION_VERSION fortress
ENV HUSARION_ROS_BUILD simulation

WORKDIR /ros2_ws

COPY ./healthcheck.cpp /

# install everything needed
RUN apt-get update --fix-missing && apt-get install -y \
python3-pip \
ros-dev-tools && \
apt-get upgrade -y && \
# Clone source
git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
vcs import src < src/rosbot/rosbot_simulation.repos && \
cp -r src/ros2_controllers/diff_drive_controller src/ && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \
rm -rf src/ros2_controllers && \
# Install dependencies
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src --ignore-src -y
RUN apt-get update && apt-get install -y \
ros-dev-tools

RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
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 build log

## =========================== Final Stage ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core
FROM ros-core-with-dependencies

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
COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck
COPY --from=ros_builder /version.txt /version.txt
COPY husarion_utils /husarion_utils

RUN apt-get update && apt-get install -y \
python3-rosdep \
python3-pip \
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 && \
# Save version
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 && \
# Size optimalization
apt-get remove -y \
python3-rosdep \
python3-pip && \
apt-get clean && \
rm -rf src && \
rm -rf /var/lib/apt/lists/*

COPY healthcheck.sh /
COPY run_healthcheck_node.sh /

# Run healthcheck in background
COPY --from=healthcheck_builder /healthcheck_ws /healthcheck_ws
RUN sed -i "/# <additional-user-commands>/i /husarion_utils/run_healthcheck_node.sh" /*_entrypoint.sh
HEALTHCHECK --interval=2s --timeout=1s --start-period=30s --retries=1 \
CMD ["/healthcheck.sh"]

RUN sed -i "/# <additional-user-commands>/r /run_healthcheck_node.sh" /*_entrypoint.sh && \
sed -i "/# <additional-user-commands>/d" /*_entrypoint.sh
CMD ["/husarion_utils/healthcheck.sh"]
111 changes: 55 additions & 56 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
ARG ROS_DISTRO=humble
ARG PREFIX=

## =========================== Healthcheck builder ===============================

FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder
## =========================== Install all ROS dependencies ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core AS ros-core-with-dependencies

ARG ROS_DISTRO
ARG PREFIX
Expand All @@ -12,106 +11,106 @@ SHELL ["/bin/bash", "-c"]

WORKDIR /ros2_ws

RUN mkdir src && \
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 \
ament_target_dependencies(healthcheck_node rclcpp nav_msgs)\n \
install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \
/ros2_ws/src/healthcheck_pkg/CMakeLists.txt
RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
ros-dev-tools && \
# Clone source
git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
cp -r src/ros2_controllers/diff_drive_controller src/ && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \
rm -rf src/ros2_controllers && \
rm -r src/rosbot_gazebo && \
# Install dependencies
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src --ignore-src -y && \
apt-get remove -y \
python3-pip \
python3-rosdep \
ros-dev-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

## =========================== Healthcheck builder ===============================

COPY healthcheck.cpp src/healthcheck_pkg/src/
FROM ros-core-with-dependencies AS healthcheck_builder

ARG ROS_DISTRO
ARG PREFIX

WORKDIR /healthcheck_ws/src

COPY husarion_utils/healthcheck.cpp /healthcheck.cpp

RUN 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 sensor_msgs && \
sed -i '/find_package(sensor_msgs REQUIRED)/a \
add_executable(healthcheck_node src/healthcheck.cpp)\n \
ament_target_dependencies(healthcheck_node rclcpp nav_msgs sensor_msgs)\n \
install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \
./healthcheck_pkg/CMakeLists.txt && \
mv /healthcheck.cpp ./healthcheck_pkg/src/ && \
cd .. && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf build log src

## =========================== ROS builder ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder
FROM ros-core-with-dependencies 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 \
python3-pip
ros-dev-tools

RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
cp -r src/ros2_controllers/diff_drive_controller src/ && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \
rm -rf src/ros2_controllers && \
# 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 --from-paths src --ignore-src -y && \
MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
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 build log

## =========================== Final Stage ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core
FROM ros-core-with-dependencies

ARG ROS_DISTRO
ARG PREFIX

SHELL ["/bin/bash", "-c"]

WORKDIR /ros2_ws

COPY --from=ros_builder /ros2_ws /ros2_ws
COPY --from=ros_builder /version.txt /version.txt
COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck
COPY husarion_utils /husarion_utils

# for backward compatibility
RUN cp src/rosbot_utils/rosbot_utils/flash-firmware.py /usr/bin/ && \
RUN mv /husarion_utils/print-serial-number.py /usr/bin/ && \
# for backward compatibility
cp src/rosbot_utils/rosbot_utils/flash-firmware.py /usr/bin/ && \
cp src/rosbot_utils/rosbot_utils/flash-firmware.py / && \
cp install/rosbot_utils/share/rosbot_utils/firmware/firmware-*.bin /root/firmware.bin

RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
stm32flash \
gosu \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
pip3 install pyftdi && \
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 && \
# Size optimalization
apt-get remove -y \
python3-rosdep \
python3-pip && \
apt-get clean && \
rm -rf src && \
rm -rf /var/lib/apt/lists/*

COPY healthcheck.sh /
COPY run_healthcheck_node.sh /

COPY print-serial-number.py /usr/bin/

ENV ROBOT_NAMESPACE=

# Run healthcheck in background
COPY --from=healthcheck_builder /healthcheck_ws /healthcheck_ws
RUN sed -i "/# <additional-user-commands>/i /husarion_utils/run_healthcheck_node.sh" /*_entrypoint.sh
HEALTHCHECK --interval=2s --timeout=1s --start-period=30s --retries=1 \
CMD ["/healthcheck.sh"]

RUN sed -i "/# <additional-user-commands>/r /run_healthcheck_node.sh" /*_entrypoint.sh && \
sed -i "/# <additional-user-commands>/d" /*_entrypoint.sh
CMD ["/husarion_utils/healthcheck.sh"]
8 changes: 4 additions & 4 deletions demo/compose.build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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
# 2. run `ROS_DOMAIN_ID=10 ros2 run teleop_twist_keyboard teleop_twist_keyboard` in the robot terminal

x-common-config:
&common-config
Expand All @@ -27,8 +27,8 @@ services:
# command: tail -f /dev/null
# command: ros2 run rosbot_utils flash_firmware --usb
command: >
ros2 launch rosbot_bringup combined.launch.py
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
serial_port:=$SERIAL_PORT
serial_port:=$SERIAL_PORT
serial_baudrate:=576000
# namespace:=rosbot
2 changes: 1 addition & 1 deletion demo/shm-only.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
<useBuiltinTransports>false</useBuiltinTransports>
</rtps>
</participant>
</profiles>
</profiles>
Loading
Loading