From 8f484291d8b496040120fd048dfcbdc47847d2ba Mon Sep 17 00:00:00 2001 From: Jakub Delicat Date: Tue, 24 Oct 2023 12:48:41 +0200 Subject: [PATCH] Added and aplied precommit Signed-off-by: Jakub Delicat --- .github/workflows/ros-docker-image.yaml | 135 +++++++++--------- .../workflows/vulcanexus-docker-image.yaml | 121 ++++++++-------- .gitignore | 2 +- Dockerfile.simulation | 2 +- README.md | 19 ++- demo/README.md | 2 +- demo/compose.simulation.yaml | 2 +- demo/net.env | 2 +- flash-firmware.py | 28 ++-- print-serial-number.py | 47 +++--- read_cpu_id/platformio.ini | 4 +- read_cpu_id/src/main.cpp | 11 +- sync_with_rosbot.sh | 2 +- 13 files changed, 190 insertions(+), 187 deletions(-) diff --git a/.github/workflows/ros-docker-image.yaml b/.github/workflows/ros-docker-image.yaml index d458d1f..929b8ce 100644 --- a/.github/workflows/ros-docker-image.yaml +++ b/.github/workflows/ros-docker-image.yaml @@ -1,77 +1,78 @@ +--- name: Build/Publish ROS Docker Image on: - workflow_dispatch: - inputs: - build_type: - description: "Is it a \"development\" or a \"stable\" release?" - required: true - default: 'development' - type: choice - options: - - development - - stable - target_distro: - description: "In case of \"stable\" release specify the ROS distro of the existing docker image (eg. humble)" - type: string - default: "ardent" - target_release: - description: "In case of \"stable\" release specify the version of the existing docker image (eg. 1.0.12)" - type: string - default: "0.0.0" - target_date: - description: "In case of \"stable\" release specify the date of the existing docker image in format YYYYMMDD (eg. 20220124)" - type: string - default: "20131206" - repository_dispatch: - types: [rebuild, ros-package-update] - pull_request: - types: - - closed - - opened + workflow_dispatch: + inputs: + build_type: + description: Is it a "development" or a "stable" release? + required: true + default: development + type: choice + options: + - development + - stable + target_distro: + description: In case of "stable" release specify the ROS distro of the existing docker image (eg. humble) + type: string + default: ardent + target_release: + description: In case of "stable" release specify the version of the existing docker image (eg. 1.0.12) + type: string + default: 0.0.0 + target_date: + description: In case of "stable" release specify the date of the existing docker image in format YYYYMMDD (eg. 20220124) + type: string + default: '20131206' + repository_dispatch: + types: [rebuild, ros-package-update] + pull_request: + types: + - closed + - opened jobs: - build: - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: + build: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: - include: - - dockerfile: Dockerfile.hardware - repo_name: "" - platforms: "linux/amd64, linux/arm64" - ros_distro: "humble" - - dockerfile: Dockerfile.simulation - repo_name: "rosbot-gazebo" - platforms: "linux/amd64" - ros_distro: "humble" - - dockerfile: Dockerfile.hardware - repo_name: "" - platforms: "linux/amd64, linux/arm64" - ros_distro: "iron" - - dockerfile: Dockerfile.simulation - repo_name: "rosbot-gazebo" - platforms: "linux/amd64" - ros_distro: "iron" + include: + - dockerfile: Dockerfile.hardware + repo_name: '' + platforms: linux/amd64, linux/arm64 + ros_distro: humble + - dockerfile: Dockerfile.simulation + repo_name: rosbot-gazebo + platforms: linux/amd64 + ros_distro: humble + - dockerfile: Dockerfile.hardware + repo_name: '' + platforms: linux/amd64, linux/arm64 + ros_distro: iron + - dockerfile: Dockerfile.simulation + repo_name: rosbot-gazebo + platforms: linux/amd64 + ros_distro: iron - steps: + steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: ${{ matrix.dockerfile }} | ${{ matrix.ros_distro }} | Build - uses: husarion-ci/ros-docker-img-action@v0.4 - with: - dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} - dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} - main_branch_name: ros2 - dockerfile: ${{ matrix.dockerfile }} - repo_name: ${{ matrix.repo_name }} - build_type: ${{ inputs.build_type }} - ros_distro: ${{ matrix.ros_distro }} - platforms: ${{ matrix.platforms }} + - name: ${{ matrix.dockerfile }} | ${{ matrix.ros_distro }} | Build + uses: husarion-ci/ros-docker-img-action@v0.4 + with: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} + main_branch_name: ros2 + dockerfile: ${{ matrix.dockerfile }} + repo_name: ${{ matrix.repo_name }} + build_type: ${{ inputs.build_type }} + ros_distro: ${{ matrix.ros_distro }} + platforms: ${{ matrix.platforms }} # variables important only for stable release - target_distro: ${{ inputs.target_distro }} - target_release: ${{ inputs.target_release }} - target_date: ${{ inputs.target_date }} + target_distro: ${{ inputs.target_distro }} + target_release: ${{ inputs.target_release }} + target_date: ${{ inputs.target_date }} diff --git a/.github/workflows/vulcanexus-docker-image.yaml b/.github/workflows/vulcanexus-docker-image.yaml index f9fb718..1ecd2be 100644 --- a/.github/workflows/vulcanexus-docker-image.yaml +++ b/.github/workflows/vulcanexus-docker-image.yaml @@ -1,70 +1,71 @@ +--- name: Build/Publish Vulcanexus Docker Image on: - workflow_dispatch: - inputs: - build_type: - description: "Is it a \"development\" or a \"stable\" release?" - required: true - default: 'development' - type: choice - options: - - development - - stable - target_distro: - description: "In case of \"stable\" release specify the ROS distro of the existing docker image (eg. humble)" - type: string - default: "ardent" - target_release: - description: "In case of \"stable\" release specify the version of the existing docker image (eg. 1.0.12)" - type: string - default: "0.0.0" - target_date: - description: "In case of \"stable\" release specify the date of the existing docker image in format YYYYMMDD (eg. 20220124)" - type: string - default: "20131206" - repository_dispatch: - types: [rebuild, ros-package-update] - pull_request: - types: - - closed - - opened + workflow_dispatch: + inputs: + build_type: + description: Is it a "development" or a "stable" release? + required: true + default: development + type: choice + options: + - development + - stable + target_distro: + description: In case of "stable" release specify the ROS distro of the existing docker image (eg. humble) + type: string + default: ardent + target_release: + description: In case of "stable" release specify the version of the existing docker image (eg. 1.0.12) + type: string + default: 0.0.0 + target_date: + description: In case of "stable" release specify the date of the existing docker image in format YYYYMMDD (eg. 20220124) + type: string + default: '20131206' + repository_dispatch: + types: [rebuild, ros-package-update] + pull_request: + types: + - closed + - opened jobs: - build: - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: + build: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: - include: - - dockerfile: Dockerfile.hardware - repo_name: "" - platforms: "linux/amd64, linux/arm64" - ros_distro: "humble" - - dockerfile: Dockerfile.simulation - repo_name: "rosbot-gazebo" - platforms: "linux/amd64" - ros_distro: "humble" + include: + - dockerfile: Dockerfile.hardware + repo_name: '' + platforms: linux/amd64, linux/arm64 + ros_distro: humble + - dockerfile: Dockerfile.simulation + repo_name: rosbot-gazebo + platforms: linux/amd64 + ros_distro: humble - steps: + steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: ${{ matrix.dockerfile }} | ${{ matrix.ros_distro }} | Build - uses: husarion-ci/ros-docker-img-action@v0.4 - with: - dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} - dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} - main_branch_name: ros2 - dockerfile: ${{ matrix.dockerfile }} - repo_name: ${{ matrix.repo_name }} - build_type: ${{ inputs.build_type }} - ros_distro: ${{ matrix.ros_distro }} - platforms: ${{ matrix.platforms }} - prefix: "vulcanexus-" + - name: ${{ matrix.dockerfile }} | ${{ matrix.ros_distro }} | Build + uses: husarion-ci/ros-docker-img-action@v0.4 + with: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} + main_branch_name: ros2 + dockerfile: ${{ matrix.dockerfile }} + repo_name: ${{ matrix.repo_name }} + build_type: ${{ inputs.build_type }} + ros_distro: ${{ matrix.ros_distro }} + platforms: ${{ matrix.platforms }} + prefix: vulcanexus- # variables important only for stable release - target_distro: ${{ inputs.target_distro }} - target_release: ${{ inputs.target_release }} - target_date: ${{ inputs.target_date }} + target_distro: ${{ inputs.target_distro }} + target_release: ${{ inputs.target_release }} + target_date: ${{ inputs.target_date }} diff --git a/.gitignore b/.gitignore index 042bcb4..fce4737 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -rosbot_ros/ \ No newline at end of file +rosbot_ros/ diff --git a/Dockerfile.simulation b/Dockerfile.simulation index ec0391e..ccd6017 100644 --- a/Dockerfile.simulation +++ b/Dockerfile.simulation @@ -49,4 +49,4 @@ RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -RUN echo $(cat /ros2_ws/src/rosbot_gazebo/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt \ No newline at end of file +RUN echo $(cat /ros2_ws/src/rosbot_gazebo/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt diff --git a/README.md b/README.md index 175df01..0d8bbf4 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ In *docker-compose.yaml* you have to change `device` passed to docker. For more docker run \ --rm -it --privileged \ husarion/rosbot:humble \ -print-serial-number.py +print-serial-number.py ``` ## ROS node @@ -49,6 +49,21 @@ For more details on what is being published and subscribed by nodes running in t - [rosbot_ros](https://github.com/husarion/rosbot_ros/tree/humble) - [rosbot_ros2_firmware](https://github.com/husarion/rosbot_ros2_firmware/) + +## Developing +[pre-commit configuration](.pre-commit-config.yaml) prepares plenty of tests helping for developing and contributing. Usage: + +```bash +# install pre-commit +pip install pre-commit + +# initialize pre-commit workspace +pre-commit install + +# manually run tests +pre-commit run -a +``` + ## How to use `rosbot` Docker image? Find available projects below: @@ -57,5 +72,5 @@ Find available projects below: | - | - | | [rosbot-sensors](https://github.com/husarion/rosbot-sensors) | Visualize all ROSbot sensors | | [rosbot-gamepad](https://github.com/husarion/rosbot-gamepad) | Control the robot manually using a Logitech F710 gamepad | -| [rosbot-mapping](https://github.com/husarion/rosbot-mapping) | Create a map (using [slam_toolbox](https://github.com/SteveMacenski/slam_toolbox)) of the unknow environment with ROSbot controlled in LAN or over the Internet | +| [rosbot-mapping](https://github.com/husarion/rosbot-mapping) | Create a map (using [slam_toolbox](https://github.com/SteveMacenski/slam_toolbox)) of the unknown environment with ROSbot controlled in LAN or over the Internet | | [rosbot-navigation](https://github.com/husarion/rosbot-navigation) | Autonomous navigation (using [navigation2](https://github.com/ros-planning/navigation2)) on a given map. | diff --git a/demo/README.md b/demo/README.md index 64a0a3b..5666aa9 100644 --- a/demo/README.md +++ b/demo/README.md @@ -43,4 +43,4 @@ and run inside `teleop_twist_keyboard` to drive the ROSbot ros2 run teleop_twist_keyboard teleop_twist_keyboard ``` -With keys `i`, `j`, `l`, `,` you can drive forward, counter clockwise, clockwise and backwards. If you are using macanum wheels (see `demo/.env` file) hold `Shift` key that way the ROSbot goes left and right with `j` and `l` keys instead rotates. \ No newline at end of file +With keys `i`, `j`, `l`, `,` you can drive forward, counter clockwise, clockwise and backwards. If you are using macanum wheels (see `demo/.env` file) hold `Shift` key that way the ROSbot goes left and right with `j` and `l` keys instead rotates. diff --git a/demo/compose.simulation.yaml b/demo/compose.simulation.yaml index f2218b4..616a95c 100644 --- a/demo/compose.simulation.yaml +++ b/demo/compose.simulation.yaml @@ -25,4 +25,4 @@ services: volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw - /dev:/dev - command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False} \ No newline at end of file + command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False} diff --git a/demo/net.env b/demo/net.env index 6c18d8e..029bdbe 100644 --- a/demo/net.env +++ b/demo/net.env @@ -14,4 +14,4 @@ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp # 4. Cyclone DDS + VPN # RMW_IMPLEMENTATION=rmw_cyclonedds_cpp -# CYCLONEDDS_URI=file:///husarnet-cyclonedds.xml \ No newline at end of file +# CYCLONEDDS_URI=file:///husarnet-cyclonedds.xml diff --git a/flash-firmware.py b/flash-firmware.py index 970a8c5..0e5adcd 100755 --- a/flash-firmware.py +++ b/flash-firmware.py @@ -17,22 +17,21 @@ 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.stdout == b"armv7l\n": # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") self.port = "/dev/ttyS1" boot0_pin_no = 164 reset_pin_no = 184 - - elif self.sys_arch.stdout == b'x86_64\n': + elif self.sys_arch.stdout == b"x86_64\n": # Setups UpBoard pins print("Device: UpBoard\n") self.port = "/dev/ttyS4" boot0_pin_no = 17 reset_pin_no = 18 - elif self.sys_arch.stdout == b'aarch64\n': + elif self.sys_arch.stdout == b"aarch64\n": # Setups RPi pins print("Device: RPi\n") self.port = "/dev/ttyAMA0" @@ -45,7 +44,6 @@ def __init__(self, sys_arch, binary_file): self.boot0_pin = GPIO(boot0_pin_no, "out") self.reset_pin = GPIO(reset_pin_no, "out") - def enter_bootloader_mode(self): self.boot0_pin.write(True) @@ -54,7 +52,6 @@ def enter_bootloader_mode(self): self.reset_pin.write(False) time.sleep(0.2) - def exit_bootloader_mode(self): self.boot0_pin.write(False) @@ -63,7 +60,6 @@ def exit_bootloader_mode(self): self.reset_pin.write(False) time.sleep(0.2) - def flash_firmware(self): self.enter_bootloader_mode() @@ -89,30 +85,30 @@ def flash_firmware(self): sh.stm32flash(self.port, "-v", w=self.binary_file, b="115200", _out=sys.stdout) time.sleep(0.2) break - except: + except Exception: pass else: - print('ERROR! Something goes wrong. Try again.') - + print("ERROR! Something goes wrong. Try again.") self.exit_bootloader_mode() - def main(): parser = argparse.ArgumentParser( - description='Flashing the firmware on STM32 microcontroller in ROSbot') + description="Flashing the firmware on STM32 microcontroller in ROSbot" + ) parser.add_argument( "file", - nargs='?', + nargs="?", default="/root/firmware.bin", - help="Path to a firmware file. Default = /root/firmware.bin") + help="Path to a firmware file. Default = /root/firmware.bin", + ) binary_file = parser.parse_args().file - sys_arch = sh.uname('-m') + sys_arch = sh.uname("-m") flasher = FirmwareFlasher(sys_arch, binary_file) flasher.flash_firmware() @@ -120,4 +116,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/print-serial-number.py b/print-serial-number.py index cbe0941..7738574 100755 --- a/print-serial-number.py +++ b/print-serial-number.py @@ -8,30 +8,29 @@ import sys from periphery import GPIO -class SerialNumberGenerator: +class SerialNumberGenerator: def __init__(self, sys_arch, binary_file): self.binary_file = binary_file self.sys_arch = sys_arch print(f"System architecture: {self.sys_arch}") - if self.sys_arch.stdout == b'armv7l\n': + if self.sys_arch.stdout == b"armv7l\n": # Setups ThinkerBoard pins print("Device: ThinkerBoard\n") self.port = "/dev/ttyS1" boot0_pin_no = 164 reset_pin_no = 184 - - elif self.sys_arch.stdout == b'x86_64\n': + elif self.sys_arch.stdout == b"x86_64\n": # Setups UpBoard pins print("Device: UpBoard\n") self.port = "/dev/ttyS4" boot0_pin_no = 17 reset_pin_no = 18 - elif self.sys_arch.stdout == b'aarch64\n': + elif self.sys_arch.stdout == b"aarch64\n": # Setups RPi pins print("Device: RPi\n") self.port = "/dev/ttyAMA0" @@ -48,19 +47,19 @@ def hex_to_num(self, hex_str): # Check if the hex string is valid if not all(c in string.hexdigits for c in hex_str): raise ValueError("Invalid hex string") - + # Convert the hex string to bytes try: hex_bytes = bytes.fromhex(hex_str) except ValueError: raise ValueError("Invalid hex string") - + # Compute the SHA-256 hash of the hex bytes hash = hashlib.sha256(hex_bytes).hexdigest() - + # Truncate the hash to 6 characters hash = hash[:6] - + # Return the hash as an ASCII string return hash @@ -80,15 +79,15 @@ def convert_hex_string(self, hex_str): return hex_str def generate(self): - print('flash the firmware that prints STM32 unique ID') - sh.python3('/usr/bin/flash-firmware.py', self.binary_file) - print('done') - print('') + print("flash the firmware that prints STM32 unique ID") + sh.python3("/usr/bin/flash-firmware.py", self.binary_file) + print("done") + print("") # Open the serial port - with serial.Serial(self.port, baudrate=9600, timeout=1) as ser: + with serial.Serial(self.port, baudrate=9600, timeout=1) as stm32_serial: # Read a line of input from the serial port - hex_str = ser.readline().decode("utf-8").strip() + hex_str = stm32_serial.readline().decode("utf-8").strip() hex_str = self.convert_hex_string(hex_str) print(f"CPU ID = 0x{hex_str}") @@ -103,34 +102,30 @@ def generate(self): print() # Close the serial port - ser.close() + stm32_serial.close() return result def main(): - parser = argparse.ArgumentParser( - description='Printing ROSbot 2R / 2 PRO serial number') + parser = argparse.ArgumentParser(description="Printing ROSbot 2R / 2 PRO serial number") parser.add_argument( "-f", "--file", - nargs='?', + nargs="?", default="/firmware_read_cpu_id.bin", - help="Path to a firmware file. Default: /firmware_read_cpu_id.bin") + help="Path to a firmware file. Default: /firmware_read_cpu_id.bin", + ) binary_file = parser.parse_args().file - sys_arch = sh.uname('-m') + sys_arch = sh.uname("-m") sn = SerialNumberGenerator(sys_arch, binary_file) serialNumber = sn.generate() sys.exit(serialNumber) + if __name__ == "__main__": main() - - - - - diff --git a/read_cpu_id/platformio.ini b/read_cpu_id/platformio.ini index 6dc8173..d9a534b 100644 --- a/read_cpu_id/platformio.ini +++ b/read_cpu_id/platformio.ini @@ -20,8 +20,8 @@ upload_protocol = stlink monitor_speed = 460800 -build_flags = +build_flags = -D SERIAL_UART_INSTANCE=1 -D TARGET_STM32F4 -debug_tool = stlink \ No newline at end of file +debug_tool = stlink diff --git a/read_cpu_id/src/main.cpp b/read_cpu_id/src/main.cpp index 74636ec..f7ccf23 100644 --- a/read_cpu_id/src/main.cpp +++ b/read_cpu_id/src/main.cpp @@ -4,8 +4,7 @@ const uint32_t ADDRESS = 0x1FFF7A10; const uint8_t NUM_BYTES = 12; uint8_t buffer[NUM_BYTES]; -void setup() -{ +void setup() { Serial1.setRx(PA10); Serial1.setTx(PA9); Serial1.begin(9600); @@ -14,11 +13,9 @@ void setup() memcpy(buffer, (void *)ADDRESS, NUM_BYTES); } -void loop() -{ +void loop() { // Print the bytes to the terminal - for (int i = 0; i < NUM_BYTES; i++) - { + for (int i = 0; i < NUM_BYTES; i++) { Serial1.print(buffer[i], HEX); Serial1.print(" "); } @@ -27,5 +24,3 @@ void loop() // Wait for a second before printing again delay(1000); } - - diff --git a/sync_with_rosbot.sh b/sync_with_rosbot.sh index 35ba424..2dbd9c5 100755 --- a/sync_with_rosbot.sh +++ b/sync_with_rosbot.sh @@ -7,4 +7,4 @@ sshpass -p "husarion" rsync -vRr ./ husarion@$1:/home/husarion/${PWD##*/} while inotifywait -r -e modify,create,delete,move ./ ; do sshpass -p "husarion" rsync -vRr ./ husarion@$1:/home/husarion/${PWD##*/} -done \ No newline at end of file +done