diff --git a/docker/.env b/docker/.env new file mode 100644 index 00000000..7725261e --- /dev/null +++ b/docker/.env @@ -0,0 +1,2 @@ +SERIAL_PORT=/dev/ttyUSB0 +ROS_NAMESPACE=robot1 \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..d89cffbe --- /dev/null +++ b/docker/Dockerfile @@ -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 '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ + rm -rf build log src \ No newline at end of file diff --git a/docker/compose.yaml b/docker/compose.yaml new file mode 100644 index 00000000..a4fff438 --- /dev/null +++ b/docker/compose.yaml @@ -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} \ No newline at end of file diff --git a/docker/justfile b/docker/justfile new file mode 100644 index 00000000..ff972714 --- /dev/null +++ b/docker/justfile @@ -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 \ No newline at end of file diff --git a/rosbot/rosbot_hardware.repos b/rosbot/rosbot_hardware.repos index 374a0c6d..1a054c48 100644 --- a/rosbot/rosbot_hardware.repos +++ b/rosbot/rosbot_hardware.repos @@ -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