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

Using new husarnet/ros image with a better support for SHM host<>docker communication #45

Merged
merged 10 commits into from
Jan 4, 2024
Merged
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
6 changes: 4 additions & 2 deletions Dockerfile.gazebo
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ RUN apt-get update && apt-get install -y \
rm -rf src && \
rm -rf /var/lib/apt/lists/*

COPY ros_entrypoint.sh /
COPY vulcanexus_entrypoint.sh /
COPY healthcheck.sh /
COPY run_healthcheck_node.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
35 changes: 8 additions & 27 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
ARG ROS_DISTRO=humble
ARG PREFIX=

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

FROM ubuntu:20.04 AS cpu_id_builder

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

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

FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder
Expand Down Expand Up @@ -82,6 +62,7 @@ RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src
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 ===============================
Expand All @@ -95,6 +76,7 @@ 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

# for backward compatibility
Expand All @@ -106,14 +88,13 @@ 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 && \
# Save version
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 && \
# Size optimalization
apt-get remove -y \
python3-rosdep \
Expand All @@ -122,15 +103,15 @@ RUN apt-get update && apt-get install -y \
rm -rf src && \
rm -rf /var/lib/apt/lists/*

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 run_healthcheck_node.sh /

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

ENV ROS_NAMESPACE=
ENV ROBOT_NAMESPACE=

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
34 changes: 34 additions & 0 deletions demo/compose.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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

x-common-config:
&common-config
network_mode: host
ipc: host
environment:
- FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml
# - ROS_DOMAIN_ID=10
- USER

services:

rosbot:
build:
context: ..
dockerfile: Dockerfile.hardware
<<: *common-config
privileged: true
devices:
- ${SERIAL_PORT:?err}
# environment:
# - ROS_NAMESPACE=rosbot
# command: tail -f /dev/null
# command: ros2 run rosbot_utils flash_firmware --usb
command: >
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
serial_port:=$SERIAL_PORT
serial_baudrate:=576000
# namespace:=rosbot
2 changes: 1 addition & 1 deletion demo/compose.gazebo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
build:
context: ../
dockerfile: Dockerfile.gazebo
<<: [ *cpu-config]
<<: [ *gpu-config]
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False}
17 changes: 17 additions & 0 deletions demo/shm-only.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<transport_descriptor>
<transport_id>shm_transport</transport_id>
<type>SHM</type>
</transport_descriptor>
</transport_descriptors>
<participant profile_name="SHMParticipant" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>shm_transport</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
</rtps>
</participant>
</profiles>
110 changes: 0 additions & 110 deletions flash-firmware.py

This file was deleted.

3 changes: 2 additions & 1 deletion healthcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ int main(int argc, char *argv[]) {
rclcpp::init(argc, argv);

std::string topic = "odometry/filtered";
if (const char *ns = std::getenv("ROS_NAMESPACE")) {

if(const char* ns = std::getenv("ROBOT_NAMESPACE")) {
topic = std::string(ns) + "/" + topic;
}

Expand Down
1 change: 0 additions & 1 deletion healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

HEALTHCHECK_FILE="/var/tmp/health_status.txt"


# Now check the health status
if [ -f "$HEALTHCHECK_FILE" ]; then
status=$(cat "$HEALTHCHECK_FILE")
Expand Down
Loading
Loading