Skip to content

Commit

Permalink
building the image with a new rosbot_ros driver
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Dec 8, 2023
1 parent 118a7e5 commit b964868
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
56 changes: 41 additions & 15 deletions Dockerfile.gazebo
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
ARG ROS_DISTRO=humble
ARG PREFIX=

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

FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder

ARG ROS_DISTRO
ARG PREFIX

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

COPY healthcheck.cpp src/healthcheck_pkg/src/

RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
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

Expand All @@ -22,28 +52,20 @@ RUN apt-get update --fix-missing && apt-get install -y \
ros-dev-tools && \
apt-get upgrade -y && \
# Clone source
git clone --depth 1 https://github.com/husarion/rosbot_ros.git src && \
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 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 \
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
RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf build log

Expand All @@ -62,6 +84,7 @@ 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

RUN apt-get update && apt-get install -y \
python3-rosdep \
Expand All @@ -74,6 +97,9 @@ RUN apt-get update && apt-get install -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/*
Expand All @@ -83,4 +109,4 @@ COPY vulcanexus_entrypoint.sh /
COPY healthcheck.sh /

HEALTHCHECK --interval=5s --timeout=2s --start-period=5s --retries=4 \
CMD ["/healthcheck.sh"]
CMD ["/healthcheck.sh"]
15 changes: 7 additions & 8 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
ARG ROS_DISTRO=humble
ARG PREFIX=
ARG ROSBOT_FW_RELEASE=0.8.0

## =========================== 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
Expand Down Expand Up @@ -70,7 +67,7 @@ COPY ./healthcheck.cpp /
RUN apt-get update && apt-get install -y \
python3-pip

RUN git clone --depth 1 https://github.com/husarion/rosbot_ros.git src -b ros2-rosbot-utils && \
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/ && \
Expand Down Expand Up @@ -100,6 +97,10 @@ WORKDIR /ros2_ws
COPY --from=ros_builder /ros2_ws /ros2_ws
COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck

# for backward compatibility
RUN cp src/rosbot_utils/rosbot_utils/flash-firmware.py /usr/bin/ && \
cp src/rosbot_utils/rosbot_utils/flash-firmware.py /

RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
Expand All @@ -126,9 +127,7 @@ COPY ros_entrypoint.sh /
COPY vulcanexus_entrypoint.sh /
COPY healthcheck.sh /

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

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

# copy scripts
COPY flash-firmware.py /usr/bin/
COPY print-serial-number.py /usr/bin/
16 changes: 6 additions & 10 deletions demo/namespace/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
services:

rosbot:
# image: husarion/rosbot:humble-ros2-combined-microros
build:
context: ../..
dockerfile: Dockerfile.hardware
Expand All @@ -21,17 +20,14 @@ services:
devices:
- ${SERIAL_PORT:?err}
- /dev/bus/usb/
volumes:
- ../../flash-firmware-usb.py:/usr/bin/flash-firmware-usb.py
environment:
- FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml
command: tail -f /dev/null
# command: >
# ros2 launch rosbot_bringup combined.launch.py
# mecanum:=${MECANUM:-False}
# serial_port:=$SERIAL_PORT
# serial_baudrate:=576000
# namespace:=robot1
command: >
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
serial_port:=$SERIAL_PORT
serial_baudrate:=576000
namespace:=robot1
ros2router:
image: husarnet/ros2router:1.4.0
Expand Down

0 comments on commit b964868

Please sign in to comment.