From 31b831b5e72b8a8ab849c7cb739c2b0451a403db Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Thu, 25 Jan 2024 12:47:14 +0100 Subject: [PATCH 01/14] New lib for GPIO --- README.md | 42 ++++++++++++++----- rosbot_utils/package.xml | 2 +- rosbot_utils/rosbot_utils/flash-firmware.py | 46 ++++++++++++--------- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 5ab328d1..510d10d3 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,27 @@ # Rosbot ROS + ROS2 packages for ROSbot 2R and ROSbot 2 PRO. ## ROS packages + ### `rosbot` + Metapackage that contains dependencies to other repositories. ### `rosbot_bringup` + Package that contains launch, which starts all base functionalities. Also configuration for [robot_localization](https://github.com/cra-ros-pkg/robot_localization) and [ros2_controllers](https://github.com/ros-controls/ros2_controllers) are defined there. ### `rosbot_description` + URDF model used as a source of transforms on the physical robot. It was written to be compatible with ROS Industrial and preconfigured for ROS2 control. ### `rosbot_gazebo` + Launch files for Ignition Gazebo working with ROS2 control. ### `rosbot_controller` + ROS2 hardware controllers configuration for ROSbots. ## ROS API @@ -32,13 +39,15 @@ For detailed instructions refer to the [rosbot_ros2_firmware repository](https:/ ### Prerequisites Install `colcon`, `vcs` and `rosdep`: + ``` sudo apt-get update sudo apt-get install -y python3-colcon-common-extensions python3-vcstool python3-rosdep python3-pip ``` Create workspace folder and clone `rosbot_ros` repository: -``` + +```bash mkdir -p ros2_ws/src cd ros2_ws git clone https://github.com/husarion/rosbot_ros src/ @@ -47,7 +56,8 @@ git clone https://github.com/husarion/rosbot_ros src/ ### Build and run on hardware Building: -``` + +```bash export HUSARION_ROS_BUILD=hardware source /opt/ros/$ROS_DISTRO/setup.bash @@ -70,12 +80,14 @@ colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release > Before starting the software on the robot please make sure that you're using the latest firmware and run the `micro-ROS` agent (as described in the *Usage on hardware* step). Running: -``` + +```bash source install/setup.bash ros2 launch rosbot_bringup bringup.launch.py ``` ### Build and run Gazebo simulation + Prerequisites: > **Warning** @@ -84,12 +96,14 @@ Prerequisites: > Look at [the table](https://gazebosim.org/docs/garden/ros_installation#summary-of-compatible-ros-and-gazebo-combinations) to see the compatible ROS 2 and Gazebo versions. If you have installed multiple versions of Gazebo use the global variable to select the correct one: + ```bash export GZ_VERSION=fortress ``` Building: -``` + +```bash export HUSARION_ROS_BUILD=simulation source /opt/ros/$ROS_DISTRO/setup.bash @@ -110,14 +124,16 @@ colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release ``` Running: -``` + +```bash source install/setup.bash ros2 launch rosbot_gazebo simulation.launch.py ``` -## Testing package +## Developer info ### pre-commit + [pre-commit configuration](.pre-commit-config.yaml) prepares plenty of tests helping for developing and contributing. Usage: ```bash @@ -134,7 +150,8 @@ pre-commit run -a After initialization [pre-commit configuration](.pre-commit-config.yaml) will applied on every commit. ### Industrial CI -``` + +```bash colcon test ``` @@ -142,12 +159,14 @@ colcon test > Command `colcon test` does not build the code. Remember to build your code after changes. If tests finish with errors print logs: -``` + +``` bash colcon test-result --verbose ``` ### Format python code with [Black](https://github.com/psf/black) -``` + +```bash cd src/ black rosbot* ``` @@ -156,18 +175,19 @@ black rosbot* At fist install [act](https://github.com/nektos/act): -``` +```bash cd / curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash ``` And test the workflow with: -``` +```bash act -W .github/workflows/industrial_ci.yaml ``` ## Demo + Below you can find demos with ROSbots: | link | description | | - | - | diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index a78e35ea..96f24ea3 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -14,7 +14,7 @@ https://github.com/husarion/rosbot_ros/issues python3-sh - python-periphery-pip + python3-libgpiod python3-pyftdi-pip usbutils python3-serial diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index 73928af6..efb48204 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -22,7 +22,8 @@ import time import sys import argparse -from periphery import GPIO +import gpiod +from gpiod.line import Direction, Value class FirmwareFlasher: @@ -34,45 +35,52 @@ def __init__(self, sys_arch, binary_file): print(f"System architecture: {self.sys_arch}") - if self.sys_arch.stdout == b"armv7l\n": + if self.sys_arch == "armv7l": # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") self.port = "/dev/ttyS1" - boot0_pin_no = 164 - reset_pin_no = 184 + self.boot0_pin_no = 164 + self.reset_pin_no = 184 - elif self.sys_arch.stdout == b"x86_64\n": + elif self.sys_arch == "x86_64": # Setups UpBoard pins print("Device: UpBoard\n") self.port = "/dev/ttyS4" - boot0_pin_no = 17 - reset_pin_no = 18 + self.boot0_pin_no = 17 + self.reset_pin_no = 18 - elif self.sys_arch.stdout == b"aarch64\n": + elif self.sys_arch == "aarch64": # Setups RPi pins print("Device: RPi\n") self.port = "/dev/ttyAMA0" - boot0_pin_no = 17 - reset_pin_no = 18 + self.boot0_pin_no = 17 + self.reset_pin_no = 18 else: print("Unknown device...") - self.boot0_pin = GPIO(boot0_pin_no, "out") - self.reset_pin = GPIO(reset_pin_no, "out") + chip = gpiod.Chip("/dev/gpiochip0") + self.boot0_pin = chip.request_lines( + {self.boot0_pin_no: gpiod.LineSettings(Direction.OUTPUT)} + ) + self.reset_pin = chip.request_lines( + {self.reset_pin_no: gpiod.LineSettings(Direction.OUTPUT)} + ) + # gpiod.Chip("/dev/gpiochip0").get_line(self.boot0_pin_no, direction=gpiod.LINE_REQ_DIR_OUT) + # self.reset_pin = gpiod.Chip("/dev/gpiochip0").get_line(self.reset_pin_no, direction=gpiod.LINE_REQ_DIR_OUT) def enter_bootloader_mode(self): - self.boot0_pin.write(True) - self.reset_pin.write(True) + self.boot0_pin.set_value(self.boot0_pin_no, Value.ACTIVE) + self.reset_pin.set_value(self.reset_pin_no, Value.ACTIVE) time.sleep(0.2) - self.reset_pin.write(False) + self.reset_pin.set_value(self.reset_pin_no, Value.INACTIVE) time.sleep(0.2) def exit_bootloader_mode(self): - self.boot0_pin.write(False) - self.reset_pin.write(True) + self.boot0_pin.set_value(self.boot0_pin_no, Value.INACTIVE) + self.reset_pin.set_value(self.reset_pin_no, Value.ACTIVE) time.sleep(0.2) - self.reset_pin.write(False) + self.reset_pin.set_value(self.reset_pin_no, Value.INACTIVE) time.sleep(0.2) def try_flash_operation(self, operation_name, flash_command, flash_args): @@ -118,7 +126,7 @@ def main(): ) binary_file = parser.parse_args().file - sys_arch = sh.uname("-m") + sys_arch = sh.uname("-m").stdout.decode().strip() flasher = FirmwareFlasher(sys_arch, binary_file) flasher.flash_firmware() From 3ca794d68e2662cb0d4cf55484f0a5e20cf724ce Mon Sep 17 00:00:00 2001 From: rafal-gorecki <126687345+rafal-gorecki@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:12:14 +0100 Subject: [PATCH 02/14] Update .wordlist.txt --- .wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.wordlist.txt b/.wordlist.txt index cfa4a43c..51939d4c 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -150,3 +150,4 @@ subprocess cbus Dockerfile unbuffered +libgpiod From 92884275801a6ed2d1a4ce0ac2eb9fd263d086ed Mon Sep 17 00:00:00 2001 From: rafal-gorecki <126687345+rafal-gorecki@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:13:54 +0100 Subject: [PATCH 03/14] Update .wordlist.txt --- .wordlist.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.wordlist.txt b/.wordlist.txt index 51939d4c..53a4be21 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -151,3 +151,6 @@ cbus Dockerfile unbuffered libgpiod +REQ +gpiochip +gpiod From 470e25c68d25fbdbaaf6e072ffc119ccdd199786 Mon Sep 17 00:00:00 2001 From: rafal-gorecki <126687345+rafal-gorecki@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:14:40 +0100 Subject: [PATCH 04/14] Update rosbot_utils/rosbot_utils/flash-firmware.py --- rosbot_utils/rosbot_utils/flash-firmware.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index efb48204..a308ebfb 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -66,8 +66,6 @@ def __init__(self, sys_arch, binary_file): self.reset_pin = chip.request_lines( {self.reset_pin_no: gpiod.LineSettings(Direction.OUTPUT)} ) - # gpiod.Chip("/dev/gpiochip0").get_line(self.boot0_pin_no, direction=gpiod.LINE_REQ_DIR_OUT) - # self.reset_pin = gpiod.Chip("/dev/gpiochip0").get_line(self.reset_pin_no, direction=gpiod.LINE_REQ_DIR_OUT) def enter_bootloader_mode(self): self.boot0_pin.set_value(self.boot0_pin_no, Value.ACTIVE) From 77bcb2d392d2337d97b707cc20a6ef876307a961 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Fri, 26 Jan 2024 13:14:40 +0100 Subject: [PATCH 05/14] clean up --- README.md | 26 ++++++++++-------- rosbot/CHANGELOG.rst | 6 ++-- rosbot/package.xml | 13 ++++----- rosbot/rosbot_simulation.repos | 5 ---- rosbot_bringup/CHANGELOG.rst | 6 ++-- rosbot_bringup/package.xml | 7 +++-- rosbot_controller/CHANGELOG.rst | 6 ++-- rosbot_controller/package.xml | 7 ++--- rosbot_description/CHANGELOG.rst | 6 ++-- rosbot_description/package.xml | 8 ++---- rosbot_gazebo/CHANGELOG.rst | 6 ++-- rosbot_gazebo/package.xml | 8 ++---- rosbot_utils/package.xml | 6 ++-- tools/Dockerfile.dev | 47 +++++++------------------------- 14 files changed, 60 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 510d10d3..d606c1f7 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ For detailed instructions refer to the [rosbot_ros2_firmware repository](https:/ ### Prerequisites -Install `colcon`, `vcs` and `rosdep`: +Install all necessary tools: -``` +```bash sudo apt-get update -sudo apt-get install -y python3-colcon-common-extensions python3-vcstool python3-rosdep python3-pip +sudo apt-get install -y ros-dev-tools python3-pip ``` Create workspace folder and clone `rosbot_ros` repository: @@ -75,25 +75,27 @@ rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release ``` -> **Prerequisites** -> -> Before starting the software on the robot please make sure that you're using the latest firmware and run the `micro-ROS` agent (as described in the *Usage on hardware* step). - Running: ```bash source install/setup.bash -ros2 launch rosbot_bringup bringup.launch.py +ros2 launch rosbot_bringup combined.launch.py ``` ### Build and run Gazebo simulation Prerequisites: -> **Warning** -> The simulation is compatible with the Gazebo Fortress LTS version. Use [this installation guide ](https://gazebosim.org/docs/fortress/install_ubuntu#binary-installation-on-ubuntu) to install the proper version and remove the another versions e. g. Gazebo Garden: -> `sudo apt remove gz-garden && sudo apt autoremove` -> Look at [the table](https://gazebosim.org/docs/garden/ros_installation#summary-of-compatible-ros-and-gazebo-combinations) to see the compatible ROS 2 and Gazebo versions. +> [!TIP] +> The default version of Gazebo Ignition will be installed with the instructions below. If you want to install a different version of the simulator, it is necessary to: +> +> - Check compatible versions of ROS 2 and Gazebo in [this table](https://gazebosim.org/docs/garden/ros_installation#summary-of-compatible-ros-and-gazebo-combinations) +> - [Install the appropriate version](https://gazebosim.org/docs/fortress/install_ubuntu#binary-installation-on-ubuntu), +> - Add the `GZ_VERSION` environment variable appropriate to your version +> +> ```bash +> export GZ_VERSION=fortress +> ``` If you have installed multiple versions of Gazebo use the global variable to select the correct one: diff --git a/rosbot/CHANGELOG.rst b/rosbot/CHANGELOG.rst index 40050071..4123426a 100644 --- a/rosbot/CHANGELOG.rst +++ b/rosbot/CHANGELOG.rst @@ -2,9 +2,6 @@ Changelog for package rosbot ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.10.5 (2023-12-05) -------------------- - 0.13.0 (2024-01-15) ------------------- @@ -17,6 +14,9 @@ Changelog for package rosbot 0.11.0 (2023-12-08) ------------------- +0.10.5 (2023-12-05) +------------------- + 0.10.4 (2023-12-01) ------------------- diff --git a/rosbot/package.xml b/rosbot/package.xml index ad282059..8ce7836c 100644 --- a/rosbot/package.xml +++ b/rosbot/package.xml @@ -3,12 +3,11 @@ rosbot 0.13.0 - Meta package that contains all packages of Rosbot 2 2R PRO - Apache License 2.0 - - Jakub Delicat Husarion + Jakub Delicat + Rafal Gorecki + Apache License 2.0 https://husarion.com/ https://github.com/husarion/rosbot_ros @@ -17,13 +16,11 @@ ament_cmake rosbot_bringup - rosbot_description rosbot_controller + rosbot_description rosbot_utils - - rosbot_gazebo - + rosbot_gazebo ament_cmake diff --git a/rosbot/rosbot_simulation.repos b/rosbot/rosbot_simulation.repos index 40ba729f..e4d80df2 100644 --- a/rosbot/rosbot_simulation.repos +++ b/rosbot/rosbot_simulation.repos @@ -1,9 +1,4 @@ repositories: - gazebosim/gz_ros2_control: - type: git - url: https://github.com/ros-controls/gz_ros2_control - version: humble - husarion/husarion_office_gz: type: git url: https://github.com/husarion/husarion_office_gz diff --git a/rosbot_bringup/CHANGELOG.rst b/rosbot_bringup/CHANGELOG.rst index eca7786a..8942298e 100644 --- a/rosbot_bringup/CHANGELOG.rst +++ b/rosbot_bringup/CHANGELOG.rst @@ -2,9 +2,6 @@ Changelog for package rosbot_bringup ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.10.5 (2023-12-05) -------------------- - 0.13.0 (2024-01-15) ------------------- @@ -17,6 +14,9 @@ Changelog for package rosbot_bringup 0.11.0 (2023-12-08) ------------------- +0.10.5 (2023-12-05) +------------------- + 0.10.4 (2023-12-01) ------------------- diff --git a/rosbot_bringup/package.xml b/rosbot_bringup/package.xml index b6a269ba..7ff6696c 100644 --- a/rosbot_bringup/package.xml +++ b/rosbot_bringup/package.xml @@ -4,10 +4,10 @@ rosbot_bringup 0.13.0 ROSbot 2, 2R, PRO bringup package - Apache License 2.0 - - Jakub Delicat Husarion + Jakub Delicat + Rafal Gorecki + Apache License 2.0 https://husarion.com/ https://github.com/husarion/rosbot_ros @@ -18,6 +18,7 @@ rosbot_controller robot_localization micro_ros_agent + micro_ros_msgs python3-pytest launch diff --git a/rosbot_controller/CHANGELOG.rst b/rosbot_controller/CHANGELOG.rst index 257a0b98..0410b053 100644 --- a/rosbot_controller/CHANGELOG.rst +++ b/rosbot_controller/CHANGELOG.rst @@ -2,9 +2,6 @@ Changelog for package rosbot_controller ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.10.5 (2023-12-05) -------------------- - 0.13.0 (2024-01-15) ------------------- @@ -17,6 +14,9 @@ Changelog for package rosbot_controller 0.11.0 (2023-12-08) ------------------- +0.10.5 (2023-12-05) +------------------- + 0.10.4 (2023-12-01) ------------------- diff --git a/rosbot_controller/package.xml b/rosbot_controller/package.xml index 9d30ccdb..926973de 100644 --- a/rosbot_controller/package.xml +++ b/rosbot_controller/package.xml @@ -3,13 +3,12 @@ rosbot_controller 0.13.0 - Hardware configuration for ROSbot 2, 2R, PRO + Husarion + Jakub Delicat + Rafal Gorecki Apache License 2.0 - Jakub Delicat - Husarion - https://husarion.com/ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues diff --git a/rosbot_description/CHANGELOG.rst b/rosbot_description/CHANGELOG.rst index 08d2a258..ab24988d 100644 --- a/rosbot_description/CHANGELOG.rst +++ b/rosbot_description/CHANGELOG.rst @@ -2,9 +2,6 @@ Changelog for package rosbot_description ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.10.5 (2023-12-05) -------------------- - 0.13.0 (2024-01-15) ------------------- @@ -17,6 +14,9 @@ Changelog for package rosbot_description 0.11.0 (2023-12-08) ------------------- +0.10.5 (2023-12-05) +------------------- + 0.10.4 (2023-12-01) ------------------- diff --git a/rosbot_description/package.xml b/rosbot_description/package.xml index 3e9b0a43..0c988519 100644 --- a/rosbot_description/package.xml +++ b/rosbot_description/package.xml @@ -3,14 +3,12 @@ rosbot_description 0.13.0 - ROSbot 2, 2R, PRO description package + Husarion + Jakub Delicat + Maciej Stepien Apache License 2.0 - Jakub Delicat - Maciej Stepien - Husarion - https://husarion.com/ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues diff --git a/rosbot_gazebo/CHANGELOG.rst b/rosbot_gazebo/CHANGELOG.rst index c71a9853..1b99e9ee 100644 --- a/rosbot_gazebo/CHANGELOG.rst +++ b/rosbot_gazebo/CHANGELOG.rst @@ -2,9 +2,6 @@ Changelog for package rosbot_gazebo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.10.5 (2023-12-05) -------------------- - 0.13.0 (2024-01-15) ------------------- @@ -20,6 +17,9 @@ Changelog for package rosbot_gazebo Test gazebo fix * Contributors: Dominik Nowak +0.10.5 (2023-12-05) +------------------- + 0.10.4 (2023-12-01) ------------------- diff --git a/rosbot_gazebo/package.xml b/rosbot_gazebo/package.xml index 00b3993c..435326cc 100644 --- a/rosbot_gazebo/package.xml +++ b/rosbot_gazebo/package.xml @@ -3,13 +3,11 @@ rosbot_gazebo 0.13.0 - Gazebo Ignition simulation for ROSbot 2, 2R, PRO - Apache License 2.0 - - Jakub Delicat - Krzysztof Wojciechowski Husarion + Jakub Delicat + Rafal Gorecki + Apache License 2.0 https://husarion.com/ https://github.com/husarion/rosbot_ros diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index 96f24ea3..c6628c21 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -4,10 +4,10 @@ rosbot_utils 0.13.0 Utilities for ROSbot 2R and 2 PRO - Apache License 2.0 - - Dominik Nowak Husarion + Jakub Delicat + Rafal Gorecki + Apache License 2.0 https://husarion.com/ https://github.com/husarion/rosbot_ros diff --git a/tools/Dockerfile.dev b/tools/Dockerfile.dev index 028806f4..d8c7f5fd 100644 --- a/tools/Dockerfile.dev +++ b/tools/Dockerfile.dev @@ -1,33 +1,15 @@ 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 +ARG HUSARION_ROS_BUILD_TYPE=hardware ## =========================== ROS builder =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder ARG ROS_DISTRO ARG PREFIX +ARG HUSARION_ROS_BUILD_TYPE -SHELL ["/bin/bash", "-c"] +ENV HUSARION_ROS_BUILD_TYPE=${HUSARION_ROS_BUILD_TYPE} WORKDIR /ros2_ws RUN mkdir src @@ -36,6 +18,7 @@ COPY rosbot src/rosbot COPY rosbot_bringup src/rosbot_bringup COPY rosbot_controller src/rosbot_controller COPY rosbot_description src/rosbot_description +COPY rosbot_gazebo src/rosbot_gazebo COPY rosbot_utils src/rosbot_utils RUN apt-get update && apt-get install -y \ @@ -43,26 +26,16 @@ RUN apt-get update && apt-get install -y \ stm32flash 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 && \ - # without this line (using vulcanexus base image) rosdep init throws error: "ERROR: default sources list file already exists:" + if [ "$HUSARION_ROS_BUILD_TYPE" == "simulation" ]; then \ + vcs import src < src/rosbot/rosbot_simulation.repos; \ + else \ + rm -rf src/rosbot_gazebo; \ + fi && \ 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 -# COPY --from=stm32flash_builder /stm32flash /usr/bin/stm32flash - -# Build RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ - colcon build --cmake-args --symlink-install - -# copy scripts -# COPY tools/flash-firmware.py / -# COPY tools/flash-firmware.py /usr/bin/ -# COPY tools/flash-firmware-usb.py /usr/bin/ - -HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \ - CMD ["/healthcheck.sh"] + colcon build --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release From 573ee2f2012dac8962ed0fe4648ff759f9aad03c Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Tue, 30 Jan 2024 10:54:43 +0100 Subject: [PATCH 06/14] spellcheck fix --- .wordlist.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.wordlist.txt b/.wordlist.txt index 53a4be21..8a5a02b9 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -154,3 +154,5 @@ libgpiod REQ gpiochip gpiod +Rafal +Gorecki From 1036cd97fc7537de0c9ff35d59fe9aebf57b3550 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Tue, 30 Jan 2024 12:34:24 +0100 Subject: [PATCH 07/14] Jakub suggestions --- rosbot_utils/rosbot_utils/flash-firmware.py | 40 ++++++++++----------- tools/Dockerfile.dev | 7 +--- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index a308ebfb..1403e9ac 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -38,53 +38,51 @@ def __init__(self, sys_arch, binary_file): if self.sys_arch == "armv7l": # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") - self.port = "/dev/ttyS1" - self.boot0_pin_no = 164 - self.reset_pin_no = 184 + self.serial_port = "/dev/ttyS1" + self.boot0_pin = 164 + self.reset_pin = 184 elif self.sys_arch == "x86_64": # Setups UpBoard pins print("Device: UpBoard\n") - self.port = "/dev/ttyS4" - self.boot0_pin_no = 17 - self.reset_pin_no = 18 + self.serial_port = "/dev/ttyS4" + self.boot0_pin = 17 + self.reset_pin = 18 elif self.sys_arch == "aarch64": # Setups RPi pins print("Device: RPi\n") - self.port = "/dev/ttyAMA0" - self.boot0_pin_no = 17 - self.reset_pin_no = 18 + self.serial_port = "/dev/ttyAMA0" + self.boot0_pin = 17 + self.reset_pin = 18 else: print("Unknown device...") chip = gpiod.Chip("/dev/gpiochip0") - self.boot0_pin = chip.request_lines( - {self.boot0_pin_no: gpiod.LineSettings(Direction.OUTPUT)} - ) - self.reset_pin = chip.request_lines( - {self.reset_pin_no: gpiod.LineSettings(Direction.OUTPUT)} + self.gpio_port = chip.request_lines( + {self.boot0_pin: gpiod.LineSettings(Direction.OUTPUT), + self.reset_pin: gpiod.LineSettings(Direction.OUTPUT)} ) def enter_bootloader_mode(self): - self.boot0_pin.set_value(self.boot0_pin_no, Value.ACTIVE) - self.reset_pin.set_value(self.reset_pin_no, Value.ACTIVE) + self.gpio_port.set_value(self.boot0_pin, Value.ACTIVE) + self.gpio_port.set_value(self.reset_pin, Value.ACTIVE) time.sleep(0.2) - self.reset_pin.set_value(self.reset_pin_no, Value.INACTIVE) + self.gpio_port.set_value(self.reset_pin, Value.INACTIVE) time.sleep(0.2) def exit_bootloader_mode(self): - self.boot0_pin.set_value(self.boot0_pin_no, Value.INACTIVE) - self.reset_pin.set_value(self.reset_pin_no, Value.ACTIVE) + self.gpio_port.set_value(self.boot0_pin, Value.INACTIVE) + self.gpio_port.set_value(self.reset_pin, Value.ACTIVE) time.sleep(0.2) - self.reset_pin.set_value(self.reset_pin_no, Value.INACTIVE) + self.gpio_port.set_value(self.reset_pin, Value.INACTIVE) time.sleep(0.2) def try_flash_operation(self, operation_name, flash_command, flash_args): for i in range(self.max_approach_no): try: - flash_command(self.port, *flash_args, _out=sys.stdout) + flash_command(self.serial_port, *flash_args, _out=sys.stdout) time.sleep(0.2) break except Exception as e: diff --git a/tools/Dockerfile.dev b/tools/Dockerfile.dev index d8c7f5fd..76ff00e0 100644 --- a/tools/Dockerfile.dev +++ b/tools/Dockerfile.dev @@ -14,12 +14,7 @@ ENV HUSARION_ROS_BUILD_TYPE=${HUSARION_ROS_BUILD_TYPE} WORKDIR /ros2_ws RUN mkdir src -COPY rosbot src/rosbot -COPY rosbot_bringup src/rosbot_bringup -COPY rosbot_controller src/rosbot_controller -COPY rosbot_description src/rosbot_description -COPY rosbot_gazebo src/rosbot_gazebo -COPY rosbot_utils src/rosbot_utils +COPY ./ src/ RUN apt-get update && apt-get install -y \ python3-pip \ From 16caf9cca4d4e5d67dc4b111d7e956ce88e573b8 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Tue, 30 Jan 2024 17:21:01 +0100 Subject: [PATCH 08/14] Use gpiozero --- rosbot_utils/package.xml | 8 ++--- rosbot_utils/rosbot_utils/flash-firmware.py | 40 ++++++++++----------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index c6628c21..0bcc59f2 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -13,12 +13,12 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues - python3-sh - python3-libgpiod + python3-gpiozero python3-pyftdi-pip - usbutils - python3-serial python3-requests + python3-serial + python3-sh + usbutils ament_copyright ament_flake8 diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index 1403e9ac..d55d3f42 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -22,8 +22,7 @@ import time import sys import argparse -import gpiod -from gpiod.line import Direction, Value +from gpiozero import OutputDevice class FirmwareFlasher: @@ -39,44 +38,41 @@ def __init__(self, sys_arch, binary_file): # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") self.serial_port = "/dev/ttyS1" - self.boot0_pin = 164 - self.reset_pin = 184 + boot0_pin_no = 164 + reset_pin_no = 184 elif self.sys_arch == "x86_64": # Setups UpBoard pins print("Device: UpBoard\n") self.serial_port = "/dev/ttyS4" - self.boot0_pin = 17 - self.reset_pin = 18 + boot0_pin_no = 17 + reset_pin_no = 18 elif self.sys_arch == "aarch64": # Setups RPi pins print("Device: RPi\n") self.serial_port = "/dev/ttyAMA0" - self.boot0_pin = 17 - self.reset_pin = 18 + boot0_pin_no = 17 + reset_pin_no = 18 else: print("Unknown device...") - chip = gpiod.Chip("/dev/gpiochip0") - self.gpio_port = chip.request_lines( - {self.boot0_pin: gpiod.LineSettings(Direction.OUTPUT), - self.reset_pin: gpiod.LineSettings(Direction.OUTPUT)} - ) + self.boot0_pin = OutputDevice(boot0_pin_no) + self.reset_pin = OutputDevice(reset_pin_no) def enter_bootloader_mode(self): - self.gpio_port.set_value(self.boot0_pin, Value.ACTIVE) - self.gpio_port.set_value(self.reset_pin, Value.ACTIVE) + self.boot0_pin.on() + self.reset_pin.on() time.sleep(0.2) - self.gpio_port.set_value(self.reset_pin, Value.INACTIVE) + self.reset_pin.off() time.sleep(0.2) def exit_bootloader_mode(self): - self.gpio_port.set_value(self.boot0_pin, Value.INACTIVE) - self.gpio_port.set_value(self.reset_pin, Value.ACTIVE) + self.boot0_pin.off() + self.reset_pin.on() time.sleep(0.2) - self.gpio_port.set_value(self.reset_pin, Value.INACTIVE) + self.reset_pin.off() time.sleep(0.2) def try_flash_operation(self, operation_name, flash_command, flash_args): @@ -95,12 +91,12 @@ def try_flash_operation(self, operation_name, flash_command, flash_args): def flash_firmware(self): self.enter_bootloader_mode() - # Disable the flash write-protection - self.try_flash_operation("Write-UnProtection", sh.stm32flash, ["-u"]) - # Disable the flash read-protection self.try_flash_operation("Read-UnProtection", sh.stm32flash, ["-k"]) + # Disable the flash write-protection + self.try_flash_operation("Write-UnProtection", sh.stm32flash, ["-u"]) + # Flashing the firmware flash_args = ["-v", "-w", self.binary_file, "-b", "115200"] self.try_flash_operation("Flashing", sh.stm32flash, flash_args) From fc6bb5d740775adf7c8e71dd26fbc03f8fb30871 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Tue, 30 Jan 2024 17:33:13 +0100 Subject: [PATCH 09/14] readme --- README.md | 7 +++++++ rosbot_utils/rosbot_utils/flash-firmware.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d606c1f7..6afaf26c 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,13 @@ rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release ``` +Flash firmware: + +```bash +source install/setup.bash +ros2 launch rosbot_utils flash_firmware +``` + Running: ```bash diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index d55d3f42..b2b5a0e8 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -91,12 +91,12 @@ def try_flash_operation(self, operation_name, flash_command, flash_args): def flash_firmware(self): self.enter_bootloader_mode() - # Disable the flash read-protection - self.try_flash_operation("Read-UnProtection", sh.stm32flash, ["-k"]) - # Disable the flash write-protection self.try_flash_operation("Write-UnProtection", sh.stm32flash, ["-u"]) + # Disable the flash read-protection + self.try_flash_operation("Read-UnProtection", sh.stm32flash, ["-k"]) + # Flashing the firmware flash_args = ["-v", "-w", self.binary_file, "-b", "115200"] self.try_flash_operation("Flashing", sh.stm32flash, flash_args) From ffd6ad5ef4bda5c07f7451dcc14c2461a8c50546 Mon Sep 17 00:00:00 2001 From: Jakub Delicat <109142865+delihus@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:17:34 +0100 Subject: [PATCH 10/14] Update .wordlist.txt --- .wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.wordlist.txt b/.wordlist.txt index 8a5a02b9..2d1916c6 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -156,3 +156,4 @@ gpiochip gpiod Rafal Gorecki +gpiozero From c467da039e76156d9e9809c1bcaba8aa06946368 Mon Sep 17 00:00:00 2001 From: rafal-gorecki <126687345+rafal-gorecki@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:58:14 +0100 Subject: [PATCH 11/14] Update rosbot_utils/package.xml --- rosbot_utils/package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index 0bcc59f2..eeae5fd2 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -5,6 +5,7 @@ 0.13.0 Utilities for ROSbot 2R and 2 PRO Husarion + Dominik Nowak Jakub Delicat Rafal Gorecki Apache License 2.0 From 56d1fe7c5fba4e192fce0e4989405c42b124f756 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Wed, 31 Jan 2024 13:24:01 +0100 Subject: [PATCH 12/14] Add author --- rosbot_bringup/package.xml | 2 ++ rosbot_controller/package.xml | 2 ++ rosbot_description/package.xml | 2 ++ rosbot_gazebo/package.xml | 3 +++ rosbot_utils/package.xml | 3 ++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rosbot_bringup/package.xml b/rosbot_bringup/package.xml index 7ff6696c..8326e44c 100644 --- a/rosbot_bringup/package.xml +++ b/rosbot_bringup/package.xml @@ -13,6 +13,8 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Jakub Delicat + launch launch_ros rosbot_controller diff --git a/rosbot_controller/package.xml b/rosbot_controller/package.xml index 926973de..e84687e6 100644 --- a/rosbot_controller/package.xml +++ b/rosbot_controller/package.xml @@ -13,6 +13,8 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Jakub Delicat + ament_cmake launch diff --git a/rosbot_description/package.xml b/rosbot_description/package.xml index 0c988519..1078aa01 100644 --- a/rosbot_description/package.xml +++ b/rosbot_description/package.xml @@ -13,6 +13,8 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Jakub Delicat + ament_cmake diff --git a/rosbot_gazebo/package.xml b/rosbot_gazebo/package.xml index 435326cc..41fd39b5 100644 --- a/rosbot_gazebo/package.xml +++ b/rosbot_gazebo/package.xml @@ -13,6 +13,9 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Jakub Delicat + Krzysztof Wojciechowski + rosbot_bringup launch diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index eeae5fd2..50c54403 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -5,7 +5,6 @@ 0.13.0 Utilities for ROSbot 2R and 2 PRO Husarion - Dominik Nowak Jakub Delicat Rafal Gorecki Apache License 2.0 @@ -14,6 +13,8 @@ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Dominik Nowak + python3-gpiozero python3-pyftdi-pip python3-requests From d5126ecbd9a413b90d2271c483322617382f9b69 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Wed, 31 Jan 2024 13:29:56 +0100 Subject: [PATCH 13/14] better --- rosbot/package.xml | 4 ++-- rosbot_bringup/package.xml | 3 +-- rosbot_controller/package.xml | 2 -- rosbot_description/package.xml | 3 +-- rosbot_gazebo/package.xml | 3 +-- rosbot_utils/package.xml | 4 ++-- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/rosbot/package.xml b/rosbot/package.xml index 8ce7836c..38eeae28 100644 --- a/rosbot/package.xml +++ b/rosbot/package.xml @@ -5,14 +5,14 @@ 0.13.0 Meta package that contains all packages of Rosbot 2 2R PRO Husarion - Jakub Delicat - Rafal Gorecki Apache License 2.0 https://husarion.com/ https://github.com/husarion/rosbot_ros https://github.com/husarion/rosbot_ros/issues + Jakub Delicat + ament_cmake rosbot_bringup diff --git a/rosbot_bringup/package.xml b/rosbot_bringup/package.xml index 8326e44c..6b64f32b 100644 --- a/rosbot_bringup/package.xml +++ b/rosbot_bringup/package.xml @@ -5,8 +5,6 @@ 0.13.0 ROSbot 2, 2R, PRO bringup package Husarion - Jakub Delicat - Rafal Gorecki Apache License 2.0 https://husarion.com/ @@ -14,6 +12,7 @@ https://github.com/husarion/rosbot_ros/issues Jakub Delicat + Rafal Gorecki launch launch_ros diff --git a/rosbot_controller/package.xml b/rosbot_controller/package.xml index e84687e6..a3c22949 100644 --- a/rosbot_controller/package.xml +++ b/rosbot_controller/package.xml @@ -5,8 +5,6 @@ 0.13.0 Hardware configuration for ROSbot 2, 2R, PRO Husarion - Jakub Delicat - Rafal Gorecki Apache License 2.0 https://husarion.com/ diff --git a/rosbot_description/package.xml b/rosbot_description/package.xml index 1078aa01..449e537f 100644 --- a/rosbot_description/package.xml +++ b/rosbot_description/package.xml @@ -5,8 +5,6 @@ 0.13.0 ROSbot 2, 2R, PRO description package Husarion - Jakub Delicat - Maciej Stepien Apache License 2.0 https://husarion.com/ @@ -14,6 +12,7 @@ https://github.com/husarion/rosbot_ros/issues Jakub Delicat + Maciej Stepien ament_cmake diff --git a/rosbot_gazebo/package.xml b/rosbot_gazebo/package.xml index 41fd39b5..a684dea4 100644 --- a/rosbot_gazebo/package.xml +++ b/rosbot_gazebo/package.xml @@ -5,8 +5,6 @@ 0.13.0 Gazebo Ignition simulation for ROSbot 2, 2R, PRO Husarion - Jakub Delicat - Rafal Gorecki Apache License 2.0 https://husarion.com/ @@ -14,6 +12,7 @@ https://github.com/husarion/rosbot_ros/issues Jakub Delicat + Rafal Gorecki Krzysztof Wojciechowski rosbot_bringup diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index 50c54403..782fd3da 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -5,8 +5,6 @@ 0.13.0 Utilities for ROSbot 2R and 2 PRO Husarion - Jakub Delicat - Rafal Gorecki Apache License 2.0 https://husarion.com/ @@ -14,6 +12,8 @@ https://github.com/husarion/rosbot_ros/issues Dominik Nowak + Jakub Delicat + Rafal Gorecki python3-gpiozero python3-pyftdi-pip From 5f8e06bc07fb5513dd6faf5e00694a2c2bdf97b8 Mon Sep 17 00:00:00 2001 From: rafal-gorecki Date: Wed, 31 Jan 2024 17:23:43 +0100 Subject: [PATCH 14/14] GPIOD --- rosbot_utils/package.xml | 2 +- rosbot_utils/rosbot_utils/flash-firmware.py | 25 +++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/rosbot_utils/package.xml b/rosbot_utils/package.xml index 782fd3da..9dd137df 100644 --- a/rosbot_utils/package.xml +++ b/rosbot_utils/package.xml @@ -15,7 +15,7 @@ Jakub Delicat Rafal Gorecki - python3-gpiozero + python3-libgpiod python3-pyftdi-pip python3-requests python3-serial diff --git a/rosbot_utils/rosbot_utils/flash-firmware.py b/rosbot_utils/rosbot_utils/flash-firmware.py index cd5b0246..cd36c3a2 100755 --- a/rosbot_utils/rosbot_utils/flash-firmware.py +++ b/rosbot_utils/rosbot_utils/flash-firmware.py @@ -22,7 +22,7 @@ import time import sys import argparse -from gpiozero import OutputDevice +import gpiod class FirmwareFlasher: @@ -38,6 +38,7 @@ def __init__(self, sys_arch, binary_file): # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") self.serial_port = "/dev/ttyS1" + gpio_chip = "/dev/gpiochip0" boot0_pin_no = 164 reset_pin_no = 184 @@ -45,6 +46,7 @@ def __init__(self, sys_arch, binary_file): # Setups UpBoard pins print("Device: UpBoard\n") self.serial_port = "/dev/ttyS4" + gpio_chip = "/dev/gpiochip4" boot0_pin_no = 17 reset_pin_no = 18 @@ -52,27 +54,32 @@ def __init__(self, sys_arch, binary_file): # Setups RPi pins print("Device: RPi\n") self.serial_port = "/dev/ttyAMA0" + gpio_chip = "/dev/gpiochip0" boot0_pin_no = 17 reset_pin_no = 18 else: print("Unknown device...") - self.boot0_pin = OutputDevice(boot0_pin_no) - self.reset_pin = OutputDevice(reset_pin_no) + chip = gpiod.Chip(gpio_chip) + self.boot0_pin = chip.get_line(boot0_pin_no) + self.reset_pin = chip.get_line(reset_pin_no) + + self.boot0_pin.request("Flash", type=gpiod.LINE_REQ_DIR_OUT, default_val=False) + self.reset_pin.request("Flash", type=gpiod.LINE_REQ_DIR_OUT, default_val=False) def enter_bootloader_mode(self): - self.boot0_pin.on() - self.reset_pin.on() + self.boot0_pin.set_value(1) + self.reset_pin.set_value(1) time.sleep(0.2) - self.reset_pin.off() + self.reset_pin.set_value(0) time.sleep(0.2) def exit_bootloader_mode(self): - self.boot0_pin.off() - self.reset_pin.on() + self.boot0_pin.set_value(0) + self.reset_pin.set_value(1) time.sleep(0.2) - self.reset_pin.off() + self.reset_pin.set_value(0) time.sleep(0.2) def try_flash_operation(self, operation_name, flash_command, flash_args):