Skip to content

Commit

Permalink
Jazzy docker (#125)
Browse files Browse the repository at this point in the history
* Add hardware and sim Docker

* Fix hardware docker

* Fixes

* Fixes

* Simulation gz_gui fixes + use TwistStamped

* Use packages-up-to
  • Loading branch information
rafal-gorecki authored Dec 2, 2024
1 parent d8e9002 commit cef7b92
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 127 deletions.
97 changes: 49 additions & 48 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
---
name: Run Tests
name: Run Tests

on:
workflow_call:
workflow_dispatch:
on:
workflow_call:
workflow_dispatch:

jobs:
black:
name: Black
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Black
uses: psf/[email protected]
with:
options: --line-length=99
jobs:
black:
name: Black
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Black
uses: psf/[email protected]
with:
options: --line-length=99

industrial_ci:
name: Industrial CI
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [jazzy]
steps:
- name: Checkout
uses: actions/checkout@v3
industrial_ci:
name: Industrial CI
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [jazzy]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup ROS2 Workspace and Clone Repositories
run: |
mkdir -p src
find . -maxdepth 1 -not -name src -not -name . -exec mv {} src/ \;
python3 -m pip install -U vcstool
vcs import src < src/rosbot/rosbot_hardware.repos
vcs import src < src/rosbot/rosbot_simulation.repos
cp -r src/ros2_controllers/imu_sensor_broadcaster src/
rm -rf src/ros2_controllers
- name: Setup ROS2 Workspace and Clone Repositories
run: |
mkdir -p src
find . -maxdepth 1 -not -name src -not -name . -exec mv {} src/ \;
python3 -m pip install -U vcstool
vcs import src < src/rosbot/rosbot_hardware.repos
vcs import src < src/rosbot/rosbot_simulation.repos
cp -r src/ros2_controllers/imu_sensor_broadcaster src/
rm -rf src/ros2_controllers
# Package micro_ros_msgs does not have industrial ci and tests does not pass.
# For more information see https://github.com/micro-ROS/micro_ros_msgs/issues/7
- name: Leave only ROSbot tests
shell: bash
run: |
sed '/if(BUILD_TESTING)/,/endif()/d' src/imu_sensor_broadcaster/CMakeLists.txt -i
sed '/if(BUILD_TESTING)/,/endif()/d' src/micro_ros_msgs/CMakeLists.txt -i
# Package micro_ros_msgs does not have industrial ci and tests does not pass.
# For more information see https://github.com/micro-ROS/micro_ros_msgs/issues/7
- name: Leave only ROSbot tests
shell: bash
run: |
sed '/if(BUILD_TESTING)/,/endif()/d' src/imu_sensor_broadcaster/CMakeLists.txt -i
sed '/if(BUILD_TESTING)/,/endif()/d' src/micro_ros_msgs/CMakeLists.txt -i
- name: Running ROS Industrial CI
uses: ros-industrial/industrial_ci@master
env:
ROS_DISTRO: ${{matrix.ROS_DISTRO}}
DOCKER_IMAGE: ros:${{matrix.ROS_DISTRO}}-ros-base
IMMEDIATE_TEST_OUTPUT: true
- name: Running ROS Industrial CI
uses: ros-industrial/industrial_ci@master
env:
PIP_BREAK_SYSTEM_PACKAGES: 1
ROS_DISTRO: ${{matrix.ROS_DISTRO}}
DOCKER_IMAGE: ros:${{matrix.ROS_DISTRO}}-ros-base
IMMEDIATE_TEST_OUTPUT: true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rm -r src/rosbot_ros/rosbot_gazebo
sudo rosdep init
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release
```

Flash firmware:
Expand Down Expand Up @@ -106,7 +106,7 @@ cp -r src/ros2_controllers/imu_sensor_broadcaster src && rm -rf src/ros2_control
sudo rosdep init
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release
```

Running:
Expand Down
3 changes: 1 addition & 2 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
SERIAL_PORT=/dev/ttyUSB0
ROS_NAMESPACE=robot1
ROBOT_NAMESPACE=rosbot
29 changes: 0 additions & 29 deletions docker/Dockerfile

This file was deleted.

35 changes: 35 additions & 0 deletions docker/Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG ROS_DISTRO=jazzy

FROM husarnet/ros:${ROS_DISTRO}-ros-core

WORKDIR /ros2_ws

ENV HUSARION_ROS_BUILD_TYPE=hardware
ENV PIP_BREAK_SYSTEM_PACKAGES=1

COPY .. src/rosbot_ros

RUN apt-get update && apt-get install -y \
python3-pip \
ros-dev-tools \
stm32flash \
ros-${ROS_DISTRO}-teleop-twist-keyboard && \
# Setup workspace
vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \
rm -r src/rosbot_ros/rosbot_gazebo && \
# Install dependencies
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src -y -i && \
# Build
source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release && \
# Get 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 optimization
export SUDO_FORCE_REMOVE=yes && \
apt-get remove -y \
ros-dev-tools && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
36 changes: 36 additions & 0 deletions docker/Dockerfile.simulation
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARG ROS_DISTRO=jazzy

FROM husarnet/ros:${ROS_DISTRO}-ros-core

WORKDIR /ros2_ws

ENV HUSARION_ROS_BUILD_TYPE=simulation
ENV PIP_BREAK_SYSTEM_PACKAGES=1

COPY .. src/rosbot_ros

RUN apt-get update && apt-get install -y \
python3-pip \
ros-dev-tools \
stm32flash \
ros-${ROS_DISTRO}-teleop-twist-keyboard && \
# Setup workspace
vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \
vcs import src < src/rosbot_ros/rosbot/rosbot_simulation.repos && \
rm -rf src/ros2_controllers && \
# Install dependencies
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src -y -i && \
# Build
source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release && \
# Get 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 optimization
export SUDO_FORCE_REMOVE=yes && \
apt-get remove -y \
ros-dev-tools && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
22 changes: 22 additions & 0 deletions docker/compose.hardware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Quick Start
#
# 1. Run `docker compose -f compose.hardware.yaml up` on the ROSbot
# 2. Open a shell inside a docker container `docker compose -f compose.hardware.yaml exec -it rosbot bash`
# 3. Run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container

services:
rosbot:
build:
context: ..
dockerfile: docker/Dockerfile.hardware
network_mode: host
ipc: host
restart: unless-stopped
devices:
- ${SERIAL_PORT:-/dev/ttyUSB0}
- /dev/bus/usb/ # FTDI
command: >
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
namespace:=${ROBOT_NAMESPACE:-rosbot}
serial_port:=${SERIAL_PORT:-/dev/ttyUSB0}
32 changes: 32 additions & 0 deletions docker/compose.simulation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Quick Start
#
# 1. Run `xhost +local:docker && docker compose -f compose.simulation.yaml up` on the laptop
# (optionally you can chang `gpu-config` -> `cpu config`).
# 2. Open a shell inside a docker container `docker compose -f compose.simulation.yaml exec -it rosbot bash`
# 3. Run `ros2 run teleop_twist_keyboard teleop_twist_keyboard` inside the container

x-gpu-config:
&gpu-config
runtime: nvidia
environment:
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all

x-cpu-config:
&cpu-config
environment:
- DISPLAY=${DISPLAY:?err}

services:
rosbot:
build:
context: ..
dockerfile: docker/Dockerfile.simulation
network_mode: host
ipc: host
<<: [ *gpu-config]
command: >
ros2 launch rosbot_gazebo simulation.launch.py
mecanum:=${MECANUM:-False}
namespace:=${ROBOT_NAMESPACE:-rosbot}
19 changes: 0 additions & 19 deletions docker/compose.yaml

This file was deleted.

14 changes: 7 additions & 7 deletions docker/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ alias teleop := run-teleop-docker
# run teleop_twist_keybaord (inside rviz2 container)
run-teleop-docker: _run-as-user
#!/bin/bash
docker compose exec rosbot /bin/bash -c "/ros_entrypoint.sh ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/${ROS_NAMESPACE}"
docker compose exec rosbot /bin/bash -c "/ros_entrypoint.sh ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/${ROBOT_NAMESPACE}"

flash-firmware: _install-yq _run-as-user
#!/bin/bash
Expand All @@ -29,9 +29,9 @@ flash-firmware: _install-yq _run-as-user
gpio_chip=/dev/gpiochip4
serial_port=/dev/ttyS4
else
echo "Probably user laptop"
echo "Probably user computer"
gpio_chip=/dev/bus/usb
serial_port=$SERIAL_PORT
serial_port=/dev/ttyUSB0
enable_usb="--usb"
fi

Expand All @@ -42,13 +42,13 @@ flash-firmware: _install-yq _run-as-user
docker-rosbot \
ros2 run rosbot_utils flash_firmware ${enable_usb}

run:
run_hardware:
#/bin/bash
docker compose up
docker compose -f compose.hardware.yaml up

build:
build_hardware:
#/bin/bash
docker compose build
docker compose -f compose.hardware.yaml build

_run-as-root:
#!/bin/bash
Expand Down
4 changes: 1 addition & 3 deletions rosbot/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
<depend>rosbot_bringup</depend>
<depend>rosbot_controller</depend>
<depend>rosbot_description</depend>

<depend condition="($HUSARION_ROS_BUILD_TYPE == hardware)">rosbot_utils</depend>

<depend condition="($HUSARION_ROS_BUILD_TYPE == simulation)">rosbot_gazebo</depend>
<depend condition="($HUSARION_ROS_BUILD_TYPE == hardware)">rosbot_utils</depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
2 changes: 1 addition & 1 deletion rosbot/rosbot_simulation.repos
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ repositories:
husarion_gz_worlds:
type: git
url: https://github.com/husarion/husarion_gz_worlds
version: c0ff83a476f6e0bc250c763a806bf1769a00f515
version: 7237a7d67a476a480a74ccd3a510b76a581288c3
ros2_controllers: # Bug: There is no nice way to change `sensor_name` imu_bradcaster param when spawning multiple robots -> ros2_control refer only to single imu entity
type: git
url: https://github.com/husarion/ros2_controllers/
Expand Down
Loading

0 comments on commit cef7b92

Please sign in to comment.