Skip to content

Commit

Permalink
Merge pull request #42 from husarion/ros2-robot-utils
Browse files Browse the repository at this point in the history
Ros2 robot utils
  • Loading branch information
DominikN authored Dec 11, 2023
2 parents 8919443 + 1823c9d commit bd7cc5c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 209 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"]
63 changes: 16 additions & 47 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
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
ARG TARGETARCH

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

RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE

# Copy firmware binaries
RUN curl -L https://github.com/husarion/stm32flash/releases/download/2023-12-05/stm32flash-$TARGETARCH -o /stm32flash && \
chmod +x /stm32flash

# 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
Expand Down Expand Up @@ -91,13 +65,9 @@ RUN mkdir src
COPY ./healthcheck.cpp /

RUN apt-get update && apt-get install -y \
git \
python3-pip \
python3-sh \
python3-periphery && \
pip3 install pyserial
python3-pip

RUN git clone --depth 1 https://github.com/husarion/rosbot_ros.git src -b humble && \
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 @@ -127,41 +97,40 @@ 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 / && \
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 \
usbutils \
stm32flash \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
pip3 install pyftdi sh && \
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 \
python3-pip && \
apt-get clean && \
rm -rf src && \
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 /usr/bin/stm32flash

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 /

HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=4 \
CMD ["/healthcheck.sh"]
COPY print-serial-number.py /usr/bin/

COPY microros_localhost_only.xml /
ENV ROS_NAMESPACE=

# copy scripts
COPY flash-firmware.py /
COPY flash-firmware.py /usr/bin/
COPY flash-firmware-usb.py /usr/bin/
COPY print-serial-number.py /usr/bin/
HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \
CMD ["/healthcheck.sh"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ Docker Image for ROS Humble Node providing interface for STM32 firmware over [Mi

With *docker-compose* configuration shown in [demo](./demo) it can communicate with hardware of ROSbot 2R, ROSbot 2 PRO and ROSbot 2.0.

## Quick Start

```yaml
services:

rosbot:
image: husarion/rosbot:humble
devices:
- ${SERIAL_PORT:?err}
- /dev/bus/usb/ # FTDI (if connecting over USB port with STM32)
environment:
- ROS_DOMAIN_ID=30
command: >
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
serial_port:=$SERIAL_PORT
serial_baudrate:=576000
namespace:=robot1
```
## Flashing the firmware
Firmware if flashed from inside of the container running on the ROSbot:
Expand Down
21 changes: 10 additions & 11 deletions demo/namespace/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
services:

rosbot:
# image: husarion/rosbot:humble-ros2-combined-microros
build:
context: ../..
dockerfile: Dockerfile.hardware
# image: husarion/rosbot:humble-ros2-robot-utils
network_mode: host
ipc: host
devices:
- ${SERIAL_PORT:?err}
- /dev/bus/usb/
volumes:
- ../../flash-firmware-usb.py:/usr/bin/flash-firmware-usb.py
- /dev/bus/usb/ # FTDI
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
- ROS_DOMAIN_ID=30
- ROS_NAMESPACE=robot1 # For healthckeck node
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
109 changes: 0 additions & 109 deletions flash-firmware-usb.py

This file was deleted.

Empty file modified flash-firmware.py
100755 → 100644
Empty file.
Loading

0 comments on commit bd7cc5c

Please sign in to comment.