Skip to content

Commit

Permalink
use husarion-controller from main branch (#116)
Browse files Browse the repository at this point in the history
* added docker setup for local build

* ros2 humble works without custom controllers
  • Loading branch information
DominikN authored Nov 21, 2024
1 parent 3b64118 commit 353eebf
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SERIAL_PORT=/dev/ttyUSB0
ROS_NAMESPACE=robot1
32 changes: 32 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG ROS_DISTRO=humble

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

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

WORKDIR /ros2_ws

COPY . src/

RUN apt-get update && apt-get install -y \
python3-pip \
stm32flash \
ros-${ROS_DISTRO}-teleop-twist-keyboard

RUN 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

# Create a script to install runtime dependencies for final image
RUN apt update && \
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} --reinstall --simulate -y --dependency-types exec >> /rosdep_install.sh && \
chmod +x /rosdep_install.sh

RUN apt update && \
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y && \
source /opt/ros/$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 src
19 changes: 19 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
rosbot:
build:
context: ..
dockerfile: docker/Dockerfile
network_mode: host
ipc: host
devices:
- ${SERIAL_PORT:?err}
- /dev/bus/usb/ # FTDI
# environment:
# - ROS_NAMESPACE
# command: tail -f /dev/null
command: >
ros2 launch rosbot_bringup combined.launch.py
mecanum:=${MECANUM:-False}
serial_port:=$SERIAL_PORT
serial_baudrate:=576000
# namespace:=${ROS_NAMESPACE:-rosbot}
89 changes: 89 additions & 0 deletions docker/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
set dotenv-load # to read ROBOT_NAMESPACE from .env file

[private]
default:
@just --list --unsorted

[private]
alias flash := flash-firmware

[private]
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}"

flash-firmware: _install-yq _run-as-user
#!/bin/bash
echo "Stopping all running containers"
docker ps -q | xargs -r docker stop

if grep -q "Raspberry Pi" /proc/cpuinfo; then
echo "Setting up Raspberry Pi GPIO Port"
gpio_chip=/dev/gpiochip0
serial_port=/dev/ttyAMA0
elif grep -q "Intel(R) Atom(TM) x5-Z8350" /proc/cpuinfo; then
echo "Setting up UpBoard GPIO Port"
gpio_chip=/dev/gpiochip4
serial_port=/dev/ttyS4
else
echo "Probably user laptop"
gpio_chip=/dev/bus/usb
serial_port=$SERIAL_PORT
enable_usb="--usb"
fi

echo "Flashing the firmware for STM32 microcontroller in ROSbot through $serial_port"
docker run --rm -it \
--device $gpio_chip \
--device $serial_port \
docker-rosbot \
ros2 run rosbot_utils flash_firmware ${enable_usb}

run:
#/bin/bash
docker compose up

build:
#/bin/bash
docker compose build

_run-as-root:
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo -e "\e[1;33mPlease re-run as root user to install dependencies\e[0m"
exit 0
fi

_run-as-user:
#!/bin/bash
if [ "$EUID" -eq 0 ]; then
echo -e "\e[1;33mPlease re-run as non-root user\e[0m"
exit 0
fi

_install-yq:
#!/bin/bash
if ! command -v /usr/bin/yq &> /dev/null; then
if [ "$EUID" -ne 0 ]; then
echo -e "\e[1;33mPlease run as root to install dependencies\e[0m"
exit 0
fi

YQ_VERSION=v4.35.1
ARCH=$(arch)

if [ "$ARCH" = "x86_64" ]; then
YQ_ARCH="amd64"
elif [ "$ARCH" = "aarch64" ]; then
YQ_ARCH="arm64"
else
YQ_ARCH="$ARCH"
fi

curl -L https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${YQ_ARCH} -o /usr/bin/yq
chmod +x /usr/bin/yq
echo "yq installed successfully!"
fi
9 changes: 1 addition & 8 deletions rosbot/rosbot_hardware.repos
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ repositories:
husarion_controllers:
type: git
url: https://github.com/husarion/husarion_controllers
version: 217b09830f5f42930098b9992eda41710702b625
# Waiting for backporting to the humble version
# https://github.com/ros-controls/ros2_controllers/pull/726 and
# https://github.com/ros-controls/ros2_controllers/pull/831
ros2_controllers:
type: git
url: https://github.com/delihus/ros2_controllers
version: humble
version: main
micro_ros_msgs:
type: git
url: https://github.com/micro-ROS/micro_ros_msgs.git
Expand Down

0 comments on commit 353eebf

Please sign in to comment.