From ef685011248b9de06fcdd53ffa93e74a7dd39c17 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Tue, 20 Jun 2023 20:08:38 -0300 Subject: [PATCH 01/19] ci: setup CI using script - Run the same script that packages in ros-controls github org use - https://rtw.stoglrobotics.de/master/use-cases/ros_packages/configure_repository.html These will likely fail due to serial not being released for ROS2 - see #21 - https://github.com/wjwwood/serial/issues/204 - https://github.com/wjwwood/serial/issues/283 Signed-off-by: Alex Moriarty --- .codespell-ignore-words.txt | 0 .github/workflows/README.md | 72 ++++++++++++++ .github/workflows/ci-coverage-build.yml | 50 ++++++++++ .github/workflows/ci-format.yml | 23 +++++ .github/workflows/ci-ros-lint.yml | 45 +++++++++ .../workflows/humble-abi-compatibility.yml | 20 ++++ .../workflows/humble-binary-build-main.yml | 26 +++++ .../workflows/humble-binary-build-testing.yml | 26 +++++ .../workflows/humble-rhel-binary-build.yml | 33 +++++++ .../humble-semi-binary-build-main.yml | 25 +++++ .../humble-semi-binary-build-testing.yml | 25 +++++ .github/workflows/humble-source-build.yml | 19 ++++ .github/workflows/iron-abi-compatibility.yml | 20 ++++ .github/workflows/iron-binary-build-main.yml | 26 +++++ .../workflows/iron-binary-build-testing.yml | 26 +++++ .github/workflows/iron-rhel-binary-build.yml | 33 +++++++ .../workflows/iron-semi-binary-build-main.yml | 25 +++++ .../iron-semi-binary-build-testing.yml | 25 +++++ .github/workflows/iron-source-build.yml | 19 ++++ .github/workflows/prerelease-check.yml | 41 ++++++++ .../reusable-industrial-ci-with-cache.yml | 96 +++++++++++++++++++ .../reusable-ros-tooling-source-build.yml | 51 ++++++++++ .../workflows/rolling-abi-compatibility.yml | 20 ++++ .../workflows/rolling-binary-build-main.yml | 26 +++++ .../rolling-binary-build-testing.yml | 26 +++++ .../workflows/rolling-rhel-binary-build.yml | 33 +++++++ .../rolling-semi-binary-build-main.yml | 25 +++++ .../rolling-semi-binary-build-testing.yml | 25 +++++ .github/workflows/rolling-source-build.yml | 19 ++++ .pre-commit-config.yaml | 8 +- README.md | 37 +++++++ .../launch/view_gripper.launch.py | 4 +- .../src/robotiq_gripper_interface.cpp | 8 +- ..._robotiq_gripper-not-released.humble.repos | 6 ++ ros2_robotiq_gripper-not-released.iron.repos | 6 ++ ...robotiq_gripper-not-released.rolling.repos | 6 ++ ros2_robotiq_gripper.humble.repos | 6 ++ ros2_robotiq_gripper.iron.repos | 6 ++ ros2_robotiq_gripper.rolling.repos | 6 ++ 39 files changed, 986 insertions(+), 7 deletions(-) create mode 100644 .codespell-ignore-words.txt create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/ci-coverage-build.yml create mode 100644 .github/workflows/ci-format.yml create mode 100644 .github/workflows/ci-ros-lint.yml create mode 100644 .github/workflows/humble-abi-compatibility.yml create mode 100644 .github/workflows/humble-binary-build-main.yml create mode 100644 .github/workflows/humble-binary-build-testing.yml create mode 100644 .github/workflows/humble-rhel-binary-build.yml create mode 100644 .github/workflows/humble-semi-binary-build-main.yml create mode 100644 .github/workflows/humble-semi-binary-build-testing.yml create mode 100644 .github/workflows/humble-source-build.yml create mode 100644 .github/workflows/iron-abi-compatibility.yml create mode 100644 .github/workflows/iron-binary-build-main.yml create mode 100644 .github/workflows/iron-binary-build-testing.yml create mode 100644 .github/workflows/iron-rhel-binary-build.yml create mode 100644 .github/workflows/iron-semi-binary-build-main.yml create mode 100644 .github/workflows/iron-semi-binary-build-testing.yml create mode 100644 .github/workflows/iron-source-build.yml create mode 100644 .github/workflows/prerelease-check.yml create mode 100644 .github/workflows/reusable-industrial-ci-with-cache.yml create mode 100644 .github/workflows/reusable-ros-tooling-source-build.yml create mode 100644 .github/workflows/rolling-abi-compatibility.yml create mode 100644 .github/workflows/rolling-binary-build-main.yml create mode 100644 .github/workflows/rolling-binary-build-testing.yml create mode 100644 .github/workflows/rolling-rhel-binary-build.yml create mode 100644 .github/workflows/rolling-semi-binary-build-main.yml create mode 100644 .github/workflows/rolling-semi-binary-build-testing.yml create mode 100644 .github/workflows/rolling-source-build.yml create mode 100644 ros2_robotiq_gripper-not-released.humble.repos create mode 100644 ros2_robotiq_gripper-not-released.iron.repos create mode 100644 ros2_robotiq_gripper-not-released.rolling.repos create mode 100644 ros2_robotiq_gripper.humble.repos create mode 100644 ros2_robotiq_gripper.iron.repos create mode 100644 ros2_robotiq_gripper.rolling.repos diff --git a/.codespell-ignore-words.txt b/.codespell-ignore-words.txt new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..103f7ad --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,72 @@ + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Rolling** | [`rolling`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/rolling) | [![Rolling Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-main.yml?branch=main)
[![Rolling Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-testing.yml?branch=main)
[![Rolling Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-main.yml?branch=main)
[![Rolling Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-testing.yml?branch=main)
[![Rolling Source Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-source-build.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-source-build.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/rolling/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#rolling) + +## Build status + + +### Explanation of different build types + +**NOTE**: There are three build stages checking current and future compatibility of the package. + +[Detailed build status](.github/workflows/README.md) + +1. Binary builds - against released packages (main and testing) in ROS distributions. Shows that direct local build is possible. + + Uses repos file: `$NAME$-not-released..repos` + +1. Semi-binary builds - against released core ROS packages (main and testing), but the immediate dependencies are pulled from source. + Shows that local build with dependencies is possible and if fails there we can expect that after the next package sync we will not be able to build. + + Uses repos file: `$NAME$.repos` + +1. Source build - also core ROS packages are build from source. It shows potential issues in the mid future. + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Humble** | [`humble`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/humble) | [![Humble Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-main.yml?branch=main)
[![Humble Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-testing.yml?branch=main)
[![Humble Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-main.yml?branch=main)
[![Humble Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-testing.yml?branch=main)
[![Humble Source Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-source-build.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-source-build.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/humble/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#humble) + +## Build status + + +### Explanation of different build types + +**NOTE**: There are three build stages checking current and future compatibility of the package. + +[Detailed build status](.github/workflows/README.md) + +1. Binary builds - against released packages (main and testing) in ROS distributions. Shows that direct local build is possible. + + Uses repos file: `$NAME$-not-released..repos` + +1. Semi-binary builds - against released core ROS packages (main and testing), but the immediate dependencies are pulled from source. + Shows that local build with dependencies is possible and if fails there we can expect that after the next package sync we will not be able to build. + + Uses repos file: `$NAME$.repos` + +1. Source build - also core ROS packages are build from source. It shows potential issues in the mid future. + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Iron** | [`iron`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/iron) | [![Iron Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-main.yml?branch=main)
[![Iron Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-testing.yml?branch=main)
[![Iron Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-main.yml?branch=main)
[![Iron Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-testing.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-testing.yml?branch=main)
[![Iron Source Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-source-build.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-source-build.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/iron/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#iron) + +## Build status + + +### Explanation of different build types + +**NOTE**: There are three build stages checking current and future compatibility of the package. + +[Detailed build status](.github/workflows/README.md) + +1. Binary builds - against released packages (main and testing) in ROS distributions. Shows that direct local build is possible. + + Uses repos file: `$NAME$-not-released..repos` + +1. Semi-binary builds - against released core ROS packages (main and testing), but the immediate dependencies are pulled from source. + Shows that local build with dependencies is possible and if fails there we can expect that after the next package sync we will not be able to build. + + Uses repos file: `$NAME$.repos` + +1. Source build - also core ROS packages are build from source. It shows potential issues in the mid future. diff --git a/.github/workflows/ci-coverage-build.yml b/.github/workflows/ci-coverage-build.yml new file mode 100644 index 0000000..336fb7d --- /dev/null +++ b/.github/workflows/ci-coverage-build.yml @@ -0,0 +1,50 @@ +name: Coverage Build +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + +jobs: + coverage: + name: coverage build + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + env: + ROS_DISTRO: rolling + steps: + - uses: ros-tooling/setup-ros@0.3.4 + with: + required-ros-distributions: ${{ env.ROS_DISTRO }} + - uses: actions/checkout@v3 + - uses: ros-tooling/action-ros-ci@0.2.6 + with: + target-ros2-distro: ${{ env.ROS_DISTRO }} + import-token: ${{ secrets.GITHUB_TOKEN }} + # build all packages listed in the meta package + package-name: + robotiq_driver + robotiq_controllers + robotiq_description + + vcs-repo-file-url: | + https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/ros2_robotiq_gripper-not-released.${{ env.ROS_DISTRO }}.repos?token=${{ secrets.GITHUB_TOKEN }} + colcon-defaults: | + { + "build": { + "mixin": ["coverage-gcc"] + } + } + colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml + - uses: codecov/codecov-action@v3.1.0 + with: + file: ros_ws/lcov/total_coverage.info + flags: unittests + name: codecov-umbrella + - uses: actions/upload-artifact@v3.1.0 + with: + name: colcon-logs-coverage-rolling + path: ros_ws/log diff --git a/.github/workflows/ci-format.yml b/.github/workflows/ci-format.yml new file mode 100644 index 0000000..2d02865 --- /dev/null +++ b/.github/workflows/ci-format.yml @@ -0,0 +1,23 @@ +# This is a format job. Pre-commit has a first-party GitHub action, so we use +# that: https://github.com/pre-commit/action + +name: Format + +on: + workflow_dispatch: + pull_request: + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4.4.0 + with: + python-version: '3.10' + - name: Install system hooks + run: sudo apt install -qq clang-format-14 cppcheck + - uses: pre-commit/action@v3.0.0 + with: + extra_args: --all-files --hook-stage manual diff --git a/.github/workflows/ci-ros-lint.yml b/.github/workflows/ci-ros-lint.yml new file mode 100644 index 0000000..e27cf4e --- /dev/null +++ b/.github/workflows/ci-ros-lint.yml @@ -0,0 +1,45 @@ +name: ROS Lint +on: + pull_request: + +jobs: + ament_lint: + name: ament_${{ matrix.linter }} + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + linter: [cppcheck, copyright, lint_cmake] + steps: + - uses: actions/checkout@v3 + - uses: ros-tooling/setup-ros@v0.2 + - uses: ros-tooling/action-ros-lint@v0.1 + with: + distribution: rolling + linter: ${{ matrix.linter }} + package-name: + robotiq_driver + robotiq_controllers + robotiq_description + + + ament_lint_100: + name: ament_${{ matrix.linter }} + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + linter: [cpplint] + steps: + - uses: actions/checkout@v3 + - uses: ros-tooling/setup-ros@v0.2 + - uses: ros-tooling/action-ros-lint@v0.1 + with: + distribution: rolling + linter: cpplint + arguments: "--linelength=100 --filter=-whitespace/newline" + package-name: + robotiq_driver + robotiq_controllers + robotiq_description + ros2_robotiq_gripper diff --git a/.github/workflows/humble-abi-compatibility.yml b/.github/workflows/humble-abi-compatibility.yml new file mode 100644 index 0000000..4df57dc --- /dev/null +++ b/.github/workflows/humble-abi-compatibility.yml @@ -0,0 +1,20 @@ +name: Humble - ABI Compatibility Check +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + +jobs: + abi_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ros-industrial/industrial_ci@master + env: + ROS_DISTRO: humble + ROS_REPO: main + ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} + NOT_TEST_BUILD: true diff --git a/.github/workflows/humble-binary-build-main.yml b/.github/workflows/humble-binary-build-main.yml new file mode 100644 index 0000000..fd97c85 --- /dev/null +++ b/.github/workflows/humble-binary-build-main.yml @@ -0,0 +1,26 @@ +name: Humble Binary Build - main +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: humble + ros_repo: main + upstream_workspace: ros2_robotiq_gripper-not-released.humble.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/humble-binary-build-testing.yml b/.github/workflows/humble-binary-build-testing.yml new file mode 100644 index 0000000..36076de --- /dev/null +++ b/.github/workflows/humble-binary-build-testing.yml @@ -0,0 +1,26 @@ +name: Humble Binary Build - testing +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: humble + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper-not-released.humble.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/humble-rhel-binary-build.yml b/.github/workflows/humble-rhel-binary-build.yml new file mode 100644 index 0000000..25e9883 --- /dev/null +++ b/.github/workflows/humble-rhel-binary-build.yml @@ -0,0 +1,33 @@ +name: Humble RHEL Binary Build +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 1 * * *' + + +jobs: + humble_rhel_binary: + name: Humble RHEL binary build + runs-on: ubuntu-latest + env: + ROS_DISTRO: humble + container: ghcr.io/ros-controls/ros:humble-rhel + steps: + - uses: actions/checkout@v3 + with: + path: src/ros2_robotiq_gripper + - run: | + rosdep update + rosdep install -iy --from-path src/ros2_robotiq_gripper + source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash + colcon build + colcon test diff --git a/.github/workflows/humble-semi-binary-build-main.yml b/.github/workflows/humble-semi-binary-build-main.yml new file mode 100644 index 0000000..17ababa --- /dev/null +++ b/.github/workflows/humble-semi-binary-build-main.yml @@ -0,0 +1,25 @@ +name: Humble Semi-Binary Build - main +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: humble + ros_repo: main + upstream_workspace: ros2_robotiq_gripper.humble.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/humble-semi-binary-build-testing.yml b/.github/workflows/humble-semi-binary-build-testing.yml new file mode 100644 index 0000000..0292176 --- /dev/null +++ b/.github/workflows/humble-semi-binary-build-testing.yml @@ -0,0 +1,25 @@ +name: Humble Semi-Binary Build - testing +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: humble + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper.humble.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/humble-source-build.yml b/.github/workflows/humble-source-build.yml new file mode 100644 index 0000000..9869d1f --- /dev/null +++ b/.github/workflows/humble-source-build.yml @@ -0,0 +1,19 @@ +name: Humble Source Build +on: + workflow_dispatch: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 3 * * *' + +jobs: + source: + uses: ./.github/workflows/reusable-ros-tooling-source-build.yml + with: + ros_distro: humble + ref: main + ros2_repo_branch: humble diff --git a/.github/workflows/iron-abi-compatibility.yml b/.github/workflows/iron-abi-compatibility.yml new file mode 100644 index 0000000..22dc31d --- /dev/null +++ b/.github/workflows/iron-abi-compatibility.yml @@ -0,0 +1,20 @@ +name: Iron - ABI Compatibility Check +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + +jobs: + abi_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ros-industrial/industrial_ci@master + env: + ROS_DISTRO: iron + ROS_REPO: main + ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} + NOT_TEST_BUILD: true diff --git a/.github/workflows/iron-binary-build-main.yml b/.github/workflows/iron-binary-build-main.yml new file mode 100644 index 0000000..cea9495 --- /dev/null +++ b/.github/workflows/iron-binary-build-main.yml @@ -0,0 +1,26 @@ +name: Iron Binary Build - main +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: iron + ros_repo: main + upstream_workspace: ros2_robotiq_gripper-not-released.iron.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/iron-binary-build-testing.yml b/.github/workflows/iron-binary-build-testing.yml new file mode 100644 index 0000000..9470611 --- /dev/null +++ b/.github/workflows/iron-binary-build-testing.yml @@ -0,0 +1,26 @@ +name: Iron Binary Build - testing +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: iron + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper-not-released.iron.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/iron-rhel-binary-build.yml b/.github/workflows/iron-rhel-binary-build.yml new file mode 100644 index 0000000..b4c175e --- /dev/null +++ b/.github/workflows/iron-rhel-binary-build.yml @@ -0,0 +1,33 @@ +name: Iron RHEL Binary Build +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 1 * * *' + + +jobs: + iron_rhel_binary: + name: Iron RHEL binary build + runs-on: ubuntu-latest + env: + ROS_DISTRO: iron + container: ghcr.io/ros-controls/ros:iron-rhel + steps: + - uses: actions/checkout@v3 + with: + path: src/ros2_robotiq_gripper + - run: | + rosdep update + rosdep install -iy --from-path src/ros2_robotiq_gripper + source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash + colcon build + colcon test diff --git a/.github/workflows/iron-semi-binary-build-main.yml b/.github/workflows/iron-semi-binary-build-main.yml new file mode 100644 index 0000000..ac9efb5 --- /dev/null +++ b/.github/workflows/iron-semi-binary-build-main.yml @@ -0,0 +1,25 @@ +name: Iron Semi-Binary Build - main +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: iron + ros_repo: main + upstream_workspace: ros2_robotiq_gripper.iron.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/iron-semi-binary-build-testing.yml b/.github/workflows/iron-semi-binary-build-testing.yml new file mode 100644 index 0000000..ec93f8f --- /dev/null +++ b/.github/workflows/iron-semi-binary-build-testing.yml @@ -0,0 +1,25 @@ +name: Iron Semi-Binary Build - testing +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: iron + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper.iron.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/iron-source-build.yml b/.github/workflows/iron-source-build.yml new file mode 100644 index 0000000..350896d --- /dev/null +++ b/.github/workflows/iron-source-build.yml @@ -0,0 +1,19 @@ +name: Iron Source Build +on: + workflow_dispatch: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 3 * * *' + +jobs: + source: + uses: ./.github/workflows/reusable-ros-tooling-source-build.yml + with: + ros_distro: iron + ref: main + ros2_repo_branch: iron diff --git a/.github/workflows/prerelease-check.yml b/.github/workflows/prerelease-check.yml new file mode 100644 index 0000000..9052985 --- /dev/null +++ b/.github/workflows/prerelease-check.yml @@ -0,0 +1,41 @@ +name: Pre-Release Check + +on: + workflow_dispatch: + inputs: + ros_distro: + description: 'Chose ROS distribution' + required: true + default: 'rolling' + type: choice + options: + - foxy + - galactic + - humble + - iron + - rolling + branch: + description: 'Chose branch for distro' + required: true + default: 'master' + type: choice + options: + - foxy + - galactic + - humble + - iron + - master + +jobs: + pre_release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.branch }} + - name: industrial_ci + uses: ros-industrial/industrial_ci@master + env: + ROS_DISTRO: ${{ github.event.inputs.ros_distro }} + PRERELEASE: true + BASEDIR: ${{ github.workspace }}/.work diff --git a/.github/workflows/reusable-industrial-ci-with-cache.yml b/.github/workflows/reusable-industrial-ci-with-cache.yml new file mode 100644 index 0000000..490b680 --- /dev/null +++ b/.github/workflows/reusable-industrial-ci-with-cache.yml @@ -0,0 +1,96 @@ +name: Reusable industrial_ci Workflow with Cache +# Reusable action to simplify dealing with ROS/ROS2 industrial_ci builds with cache +# author: Denis Štogl + +on: + workflow_call: + inputs: + ref_for_scheduled_build: + description: 'Reference on which the repo should be checkout for scheduled build. Usually is this name of a branch or a tag.' + default: '' + required: false + type: string + + upstream_workspace: + description: 'UPSTREAM_WORKSPACE variable for industrial_ci. Usually path to local .repos file.' + required: true + type: string + ros_distro: + description: 'ROS_DISTRO variable for industrial_ci' + required: true + type: string + ros_repo: + description: 'ROS_REPO to run for industrial_ci. Possible values: "main", "testing"' + default: 'main' + required: false + type: string + os_code_name: + description: 'OS_CODE_NAME variable for industrial_ci' + default: '' + required: false + type: string + before_install_upstream_dependencies: + description: 'BEFORE_INSTALL_UPSTREAM_DEPENDENCIES variable for industrial_ci' + default: '' + required: false + type: string + + ccache_dir: + description: 'Local path to store cache (from "github.workspace"). For standard industrial_ci configuration do not have to be changed' + default: '.ccache' + required: false + type: string + basedir: + description: 'Local path to workspace base directory to cache (from "github.workspace"). For standard industrial_ci configuration do not have to be changed' + default: '.work' + required: false + type: string + + +jobs: + reusable_industrial_ci_with_cache: + name: ${{ inputs.ros_distro }} ${{ inputs.ros_repo }} ${{ inputs.os_code_name }} + runs-on: ubuntu-latest + env: + CCACHE_DIR: ${{ github.workspace }}/${{ inputs.ccache_dir }} + BASEDIR: ${{ github.workspace }}/${{ inputs.basedir }} + CACHE_PREFIX: ${{ inputs.ros_distro }}-${{ inputs.upstream_workspace }}-${{ inputs.ros_repo }}-${{ github.job }} + steps: + - name: Checkout ${{ inputs.ref }} when build is not scheduled + if: ${{ github.event_name != 'schedule' }} + uses: actions/checkout@v3 + - name: Checkout ${{ inputs.ref }} on scheduled build + if: ${{ github.event_name == 'schedule' }} + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref_for_scheduled_build }} + - name: cache target_ws + if: ${{ ! matrix.env.CCOV }} + uses: pat-s/always-upload-cache@v2.1.5 + with: + path: ${{ env.BASEDIR }}/target_ws + key: target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }}-${{ github.run_id }} + restore-keys: | + target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }} + - name: cache ccache + uses: pat-s/always-upload-cache@v2.1.5 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}-${{ github.run_id }} + restore-keys: | + ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }} + ccache-${{ env.CACHE_PREFIX }} + - uses: 'ros-industrial/industrial_ci@master' + env: + UPSTREAM_WORKSPACE: ${{ inputs.upstream_workspace }} + ROS_DISTRO: ${{ inputs.ros_distro }} + ROS_REPO: ${{ inputs.ros_repo }} + OS_CODE_NAME: ${{ inputs.os_code_name }} + BEFORE_INSTALL_UPSTREAM_DEPENDENCIES: ${{ inputs.before_install_upstream_dependencies }} + - name: prepare target_ws for cache + if: ${{ always() && ! matrix.env.CCOV }} + run: | + du -sh ${{ env.BASEDIR }}/target_ws + sudo find ${{ env.BASEDIR }}/target_ws -wholename '*/test_results/*' -delete + sudo rm -rf ${{ env.BASEDIR }}/target_ws/src + du -sh ${{ env.BASEDIR }}/target_ws diff --git a/.github/workflows/reusable-ros-tooling-source-build.yml b/.github/workflows/reusable-ros-tooling-source-build.yml new file mode 100644 index 0000000..584e816 --- /dev/null +++ b/.github/workflows/reusable-ros-tooling-source-build.yml @@ -0,0 +1,51 @@ +name: Reusable industrial_ci Workflow with Cache +# Reusable action to simplify dealing with ROS/ROS2 industrial_ci builds with cache +# author: Denis Štogl + +on: + workflow_call: + inputs: + ros_distro: + description: 'ROS2 distribution name' + required: true + type: string + ref: + description: 'Reference on which the repo should be checkout. Usually is this name of a branch or a tag.' + required: true + type: string + ros2_repo_branch: + description: 'Branch in the ros2/ros2 repository from which ".repos" should be used. Possible values: master (Rolling), humble, iron, galactic, foxy.' + default: 'master' + required: false + type: string + +jobs: + reusable_ros_tooling_source_build: + name: ${{ inputs.ros_distro }} ubuntu-22.04 + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + steps: + - uses: ros-tooling/setup-ros@0.3.4 + with: + required-ros-distributions: ${{ inputs.ros_distro }} + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + - uses: ros-tooling/action-ros-ci@0.2.6 + with: + target-ros2-distro: ${{ inputs.ros_distro }} + # build all packages listed in the meta package + package-name: + robotiq_driver + robotiq_controllers + robotiq_description + + vcs-repo-file-url: | + https://raw.githubusercontent.com/ros2/ros2/${{ inputs.ros2_repo_branch }}/ros2.repos + https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/ros2_robotiq_gripper.${{ inputs.ros_distro }}.repos?token=${{ secrets.GITHUB_TOKEN }} + colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml + - uses: actions/upload-artifact@v1 + with: + name: colcon-logs-ubuntu-22.04 + path: ros_ws/log diff --git a/.github/workflows/rolling-abi-compatibility.yml b/.github/workflows/rolling-abi-compatibility.yml new file mode 100644 index 0000000..8d0778d --- /dev/null +++ b/.github/workflows/rolling-abi-compatibility.yml @@ -0,0 +1,20 @@ +name: Rolling - ABI Compatibility Check +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + +jobs: + abi_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ros-industrial/industrial_ci@master + env: + ROS_DISTRO: rolling + ROS_REPO: main + ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} + NOT_TEST_BUILD: true diff --git a/.github/workflows/rolling-binary-build-main.yml b/.github/workflows/rolling-binary-build-main.yml new file mode 100644 index 0000000..a595a3f --- /dev/null +++ b/.github/workflows/rolling-binary-build-main.yml @@ -0,0 +1,26 @@ +name: Rolling Binary Build - main +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: rolling + ros_repo: main + upstream_workspace: ros2_robotiq_gripper-not-released.rolling.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/rolling-binary-build-testing.yml b/.github/workflows/rolling-binary-build-testing.yml new file mode 100644 index 0000000..6dde565 --- /dev/null +++ b/.github/workflows/rolling-binary-build-testing.yml @@ -0,0 +1,26 @@ +name: Rolling Binary Build - testing +# author: Denis Štogl +# description: 'Build & test all dependencies from released (binary) packages.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '03 1 * * *' + +jobs: + binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: rolling + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper-not-released.rolling.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/rolling-rhel-binary-build.yml b/.github/workflows/rolling-rhel-binary-build.yml new file mode 100644 index 0000000..f237cc4 --- /dev/null +++ b/.github/workflows/rolling-rhel-binary-build.yml @@ -0,0 +1,33 @@ +name: Rolling RHEL Binary Build +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 1 * * *' + + +jobs: + rolling_rhel_binary: + name: Rolling RHEL binary build + runs-on: ubuntu-latest + env: + ROS_DISTRO: rolling + container: ghcr.io/ros-controls/ros:rolling-rhel + steps: + - uses: actions/checkout@v3 + with: + path: src/ros2_robotiq_gripper + - run: | + rosdep update + rosdep install -iy --from-path src/ros2_robotiq_gripper + source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash + colcon build + colcon test diff --git a/.github/workflows/rolling-semi-binary-build-main.yml b/.github/workflows/rolling-semi-binary-build-main.yml new file mode 100644 index 0000000..cc51f94 --- /dev/null +++ b/.github/workflows/rolling-semi-binary-build-main.yml @@ -0,0 +1,25 @@ +name: Rolling Semi-Binary Build - main +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: rolling + ros_repo: main + upstream_workspace: ros2_robotiq_gripper.rolling.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/rolling-semi-binary-build-testing.yml b/.github/workflows/rolling-semi-binary-build-testing.yml new file mode 100644 index 0000000..185c981 --- /dev/null +++ b/.github/workflows/rolling-semi-binary-build-testing.yml @@ -0,0 +1,25 @@ +name: Rolling Semi-Binary Build - testing +# description: 'Build & test that compiles the main dependencies from source.' + +on: + workflow_dispatch: + branches: + - main + pull_request: + branches: + - main + push: + branches: + - main + schedule: + # Run every morning to detect flakiness and broken dependencies + - cron: '33 1 * * *' + +jobs: + semi_binary: + uses: ./.github/workflows/reusable-industrial-ci-with-cache.yml + with: + ros_distro: rolling + ros_repo: testing + upstream_workspace: ros2_robotiq_gripper.rolling.repos + ref_for_scheduled_build: main diff --git a/.github/workflows/rolling-source-build.yml b/.github/workflows/rolling-source-build.yml new file mode 100644 index 0000000..6306dc6 --- /dev/null +++ b/.github/workflows/rolling-source-build.yml @@ -0,0 +1,19 @@ +name: Rolling Source Build +on: + workflow_dispatch: + branches: + - main + push: + branches: + - main + schedule: + # Run every day to detect flakiness and broken dependencies + - cron: '03 3 * * *' + +jobs: + source: + uses: ./.github/workflows/reusable-ros-tooling-source-build.yml + with: + ros_distro: rolling + ref: main + ros2_repo_branch: rolling diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8ce1d0..ec4437d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.4.0 hooks: - id: check-added-large-files exclude: \.(stl|dae)$ @@ -32,19 +32,19 @@ repos: - id: fix-byte-order-marker - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/codespell-project/codespell - rev: v2.0.0 + rev: v2.2.5 hooks: - id: codespell args: ['--write-changes', '-L', 'atleast'] # Provide a comma-separated list of misspelled words that codespell should ignore (for example: '-L', 'word1,word2,word3'). exclude: \.(svg|pyc|stl|dae|lock)$ - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v14.0.6 + rev: v16.0.6 hooks: - id: clang-format files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|m|proto|vert)$ diff --git a/README.md b/README.md index b38c769..bde3028 100644 --- a/README.md +++ b/README.md @@ -1 +1,38 @@ + + # ros2_robotiq_gripper + +## Build status + + + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Rolling** | [`rolling`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/rolling) | [![Rolling Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-binary-build-main.yml?branch=main)
[![Rolling Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/rolling-semi-binary-build-main.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/rolling/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#rolling) + + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Humble** | [`humble`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/humble) | [![Humble Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-binary-build-main.yml?branch=main)
[![Humble Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/humble-semi-binary-build-main.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/humble/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#humble) + + +ROS2 Distro | Branch | Build status | Documentation | Released packages +:---------: | :----: | :----------: | :-----------: | :---------------: +**Iron** | [`iron`](https://github.com/PickNikRobotics/ros2_robotiq_gripper/tree/iron) | [![Iron Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-binary-build-main.yml?branch=main)
[![Iron Semi-Binary Build](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-main.yml/badge.svg?branch=main)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/iron-semi-binary-build-main.yml?branch=main) | [![Doxygen Doc Deployment](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml/badge.svg)](https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/workflows/doxygen-deploy.yml)
[Generated Doc](https://PickNikRobotics.github.io/ros2_robotiq_gripper_Documentation/iron/html/index.html) | [ros2_robotiq_gripper](https://index.ros.org/p/ros2_robotiq_gripper/#iron) + +### Explanation of different build types + +**NOTE**: There are three build stages checking current and future compatibility of the package. + +[Detailed build status](.github/workflows/README.md) + +1. Binary builds - against released packages (main and testing) in ROS distributions. Shows that direct local build is possible. + + Uses repos file: `$NAME$-not-released..repos` + +1. Semi-binary builds - against released core ROS packages (main and testing), but the immediate dependencies are pulled from source. + Shows that local build with dependencies is possible and if fails there we can expect that after the next package sync we will not be able to build. + + Uses repos file: `$NAME$.repos` + +1. Source build - also core ROS packages are build from source. It shows potential issues in the mid future. diff --git a/robotiq_description/launch/view_gripper.launch.py b/robotiq_description/launch/view_gripper.launch.py index 6fc9038..776ddd9 100644 --- a/robotiq_description/launch/view_gripper.launch.py +++ b/robotiq_description/launch/view_gripper.launch.py @@ -41,7 +41,9 @@ def generate_launch_description(): pkg_share = launch_ros.substitutions.FindPackageShare( package="robotiq_description" ).find("robotiq_description") - default_model_path = os.path.join(pkg_share, "urdf", "robotiq_2f_85_gripper.urdf.xacro") + default_model_path = os.path.join( + pkg_share, "urdf", "robotiq_2f_85_gripper.urdf.xacro" + ) default_rviz_config_path = os.path.join(pkg_share, "rviz", "view_urdf.rviz") args = [] diff --git a/robotiq_driver/src/robotiq_gripper_interface.cpp b/robotiq_driver/src/robotiq_gripper_interface.cpp index ab26df8..0cf7157 100644 --- a/robotiq_driver/src/robotiq_gripper_interface.cpp +++ b/robotiq_driver/src/robotiq_gripper_interface.cpp @@ -154,7 +154,9 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) std::cerr << "Failed to set gripper position\n"; if (port_.isOpen()) { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt communication with gripper.\n ERROR: " << e.what(); + std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " + << e.what(); return; } throw; @@ -327,7 +329,9 @@ void RobotiqGripperInterface::updateStatus() std::cerr << "Failed to update gripper status.\n"; if (port_.isOpen()) { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt communication with gripper.\n ERROR: " << e.what(); + std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " + << e.what(); return; } throw; diff --git a/ros2_robotiq_gripper-not-released.humble.repos b/ros2_robotiq_gripper-not-released.humble.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper-not-released.humble.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master diff --git a/ros2_robotiq_gripper-not-released.iron.repos b/ros2_robotiq_gripper-not-released.iron.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper-not-released.iron.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master diff --git a/ros2_robotiq_gripper-not-released.rolling.repos b/ros2_robotiq_gripper-not-released.rolling.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper-not-released.rolling.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master diff --git a/ros2_robotiq_gripper.humble.repos b/ros2_robotiq_gripper.humble.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper.humble.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master diff --git a/ros2_robotiq_gripper.iron.repos b/ros2_robotiq_gripper.iron.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper.iron.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master diff --git a/ros2_robotiq_gripper.rolling.repos b/ros2_robotiq_gripper.rolling.repos new file mode 100644 index 0000000..1b3910e --- /dev/null +++ b/ros2_robotiq_gripper.rolling.repos @@ -0,0 +1,6 @@ +repositories: + ## EXAMPLE DEPENDENCY +# : +# type: git +# url: git@github.com:/.git +# version: master From 4722c30b954a5e1a88f4b8920ca2843542ac8a5b Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Tue, 20 Jun 2023 21:46:43 -0300 Subject: [PATCH 02/19] serial: Add serial from tylerjw fork - we would prefer not to use the fork but we need to turn on CI - when https://github.com/wjwwood/serial/issues/204 or https://github.com/wjwwood/serial/issues/283 are closed we can switch - related to https://github.com/PickNikRobotics/ros2_robotiq_gripper/issues/21 Signed-off-by: Alex Moriarty --- ros2_robotiq_gripper-not-released.humble.repos | 9 ++++----- ros2_robotiq_gripper-not-released.iron.repos | 9 ++++----- ros2_robotiq_gripper-not-released.rolling.repos | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ros2_robotiq_gripper-not-released.humble.repos b/ros2_robotiq_gripper-not-released.humble.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper-not-released.humble.repos +++ b/ros2_robotiq_gripper-not-released.humble.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 diff --git a/ros2_robotiq_gripper-not-released.iron.repos b/ros2_robotiq_gripper-not-released.iron.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper-not-released.iron.repos +++ b/ros2_robotiq_gripper-not-released.iron.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 diff --git a/ros2_robotiq_gripper-not-released.rolling.repos b/ros2_robotiq_gripper-not-released.rolling.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper-not-released.rolling.repos +++ b/ros2_robotiq_gripper-not-released.rolling.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 From 90ea352e7460293d20da2ae3bcbef2078cf01347 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 26 Jun 2023 15:10:43 -0600 Subject: [PATCH 03/19] run ament_uncrustify This is a formatting autofix Signed-off-by: Alex Moriarty --- .../robotiq_activation_controller.hpp | 13 +- .../src/robotiq_activation_controller.cpp | 61 +++--- robotiq_driver/include/robotiq_driver/crc.hpp | 2 +- .../robotiq_driver/hardware_interface.hpp | 14 +- .../robotiq_gripper_interface.hpp | 8 +- robotiq_driver/src/crc.cpp | 83 +++++--- robotiq_driver/src/gripper_interface_test.cpp | 25 +-- robotiq_driver/src/hardware_interface.cpp | 187 +++++++++--------- .../src/robotiq_gripper_interface.cpp | 149 +++++++------- 9 files changed, 276 insertions(+), 266 deletions(-) diff --git a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp index 20126ea..a9ea994 100644 --- a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp +++ b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp @@ -41,17 +41,20 @@ class RobotiqActivationController : public controller_interface::ControllerInter controller_interface::InterfaceConfiguration state_interface_configuration() const override; - controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override; + controller_interface::return_type update( + const rclcpp::Time & time, + const rclcpp::Duration & period) override; - CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; - CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; CallbackReturn on_init() override; private: - bool reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr req, - std_srvs::srv::Trigger::Response::SharedPtr resp); + bool reactivateGripper( + std_srvs::srv::Trigger::Request::SharedPtr req, + std_srvs::srv::Trigger::Response::SharedPtr resp); static constexpr double ASYNC_WAITING = 2.0; enum CommandInterfaces diff --git a/robotiq_controllers/src/robotiq_activation_controller.cpp b/robotiq_controllers/src/robotiq_activation_controller.cpp index aa63d21..6685c45 100644 --- a/robotiq_controllers/src/robotiq_activation_controller.cpp +++ b/robotiq_controllers/src/robotiq_activation_controller.cpp @@ -30,7 +30,8 @@ namespace robotiq_controllers { -controller_interface::InterfaceConfiguration RobotiqActivationController::command_interface_configuration() const +controller_interface::InterfaceConfiguration RobotiqActivationController:: +command_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -41,7 +42,8 @@ controller_interface::InterfaceConfiguration RobotiqActivationController::comman return config; } -controller_interface::InterfaceConfiguration RobotiqActivationController::state_interface_configuration() const +controller_interface::InterfaceConfiguration RobotiqActivationController:: +state_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -49,67 +51,64 @@ controller_interface::InterfaceConfiguration RobotiqActivationController::state_ return config; } -controller_interface::return_type RobotiqActivationController::update(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +controller_interface::return_type RobotiqActivationController::update( + const rclcpp::Time & /*time*/, + const rclcpp::Duration & /*period*/) { return controller_interface::return_type::OK; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqActivationController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) { // Check command interfaces. - if (command_interfaces_.size() != 2) - { - RCLCPP_ERROR(get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, - command_interfaces_.size()); + if (command_interfaces_.size() != 2) { + RCLCPP_ERROR( + get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, + command_interfaces_.size()); return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR; } - try - { + try { // Create service for re-activating the gripper. reactivate_gripper_srv_ = get_node()->create_service( - "~/reactivate_gripper", - [this](std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr resp) { - this->reactivateGripper(req, resp); - }); - } - catch (...) - { + "~/reactivate_gripper", + [this](std_srvs::srv::Trigger::Request::SharedPtr req, + std_srvs::srv::Trigger::Response::SharedPtr resp) { + this->reactivateGripper(req, resp); + }); + } catch (...) { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) { - try - { + try { reactivate_gripper_srv_.reset(); - } - catch (...) - { + } catch (...) { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn RobotiqActivationController::on_init() +rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn +RobotiqActivationController::on_init() { return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr /*req*/, - std_srvs::srv::Trigger::Response::SharedPtr resp) +bool RobotiqActivationController::reactivateGripper( + std_srvs::srv::Trigger::Request::SharedPtr /*req*/, + std_srvs::srv::Trigger::Response::SharedPtr resp) { command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].set_value(ASYNC_WAITING); command_interfaces_[REACTIVATE_GRIPPER_CMD].set_value(1.0); - while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) - { + while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } resp->success = command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value(); @@ -120,4 +119,6 @@ bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Requ #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS(robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface) +PLUGINLIB_EXPORT_CLASS( + robotiq_controllers::RobotiqActivationController, + controller_interface::ControllerInterface) diff --git a/robotiq_driver/include/robotiq_driver/crc.hpp b/robotiq_driver/include/robotiq_driver/crc.hpp index 45b0507..869fcae 100644 --- a/robotiq_driver/include/robotiq_driver/crc.hpp +++ b/robotiq_driver/include/robotiq_driver/crc.hpp @@ -3,4 +3,4 @@ #include #include -uint16_t computeCRC(const std::vector& cmd); +uint16_t computeCRC(const std::vector & cmd); diff --git a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp index 5f52b75..4f09c6d 100644 --- a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp @@ -54,7 +54,7 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa RobotiqGripperHardwareInterface(); ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_init(const hardware_interface::HardwareInfo& info) override; + CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override; ROBOTIQ_DRIVER_PUBLIC std::vector export_state_interfaces() override; @@ -63,16 +63,20 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa std::vector export_command_interfaces() override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override; + hardware_interface::return_type read( + const rclcpp::Time & time, + const rclcpp::Duration & period) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type write(const rclcpp::Time& time, const rclcpp::Duration& period) override; + hardware_interface::return_type write( + const rclcpp::Time & time, + const rclcpp::Duration & period) override; private: static constexpr double NO_NEW_CMD_ = std::numeric_limits::quiet_NaN(); diff --git a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp index 8fef23c..4c7c898 100644 --- a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp @@ -41,7 +41,7 @@ class RobotiqGripperInterface { public: - RobotiqGripperInterface(const std::string& com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); + RobotiqGripperInterface(const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); /** * @brief Activates the gripper. @@ -122,7 +122,9 @@ class RobotiqGripperInterface private: std::vector createReadCommand(uint16_t first_register, uint8_t num_registers); - std::vector createWriteCommand(uint16_t first_register, const std::vector& data); + std::vector createWriteCommand( + uint16_t first_register, + const std::vector & data); /** * @brief read response from the gripper. @@ -138,7 +140,7 @@ class RobotiqGripperInterface * @param cmd The command. * @throw serial::IOException on failure to successfully communicate with gripper port */ - void sendCommand(const std::vector& cmd); + void sendCommand(const std::vector & cmd); /** * @brief Read the current status of the gripper, and update member variables as appropriate. diff --git a/robotiq_driver/src/crc.cpp b/robotiq_driver/src/crc.cpp index db69d3c..6ae6bf6 100644 --- a/robotiq_driver/src/crc.cpp +++ b/robotiq_driver/src/crc.cpp @@ -2,47 +2,72 @@ /* Table of CRC values for high–order byte */ static unsigned char kCRCHiTable[] = { - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, - 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, - 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, + 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, + 0x41, 0x00, 0xC1, + 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, + 0x80, 0x41, 0x01, + 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, + 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, + 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, + 0x40, 0x01, 0xC0, + 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, + 0x80, 0x41, 0x00, + 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, + 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, + 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, + 0x40, 0x01, 0xC0, + 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, + 0x81, 0x40, 0x01, + 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, + 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 }; /* Table of CRC values for low–order byte */ static unsigned char kCRCLoTable[] = { - 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, - 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, - 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, - 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, - 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, - 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, - 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, - 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, - 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, - 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, - 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, - 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, - 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, + 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, + 0xCC, 0x0C, 0x0D, + 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, + 0xD9, 0x1B, 0xDB, + 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, + 0x16, 0xD6, 0xD2, + 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, + 0xF6, 0xF7, 0x37, + 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, + 0x39, 0xF9, 0xF8, + 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, + 0x2C, 0xE4, 0x24, + 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, + 0x61, 0xA1, 0x63, + 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, + 0x6F, 0x6E, 0xAE, + 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, + 0xBE, 0x7E, 0x7F, + 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, + 0x73, 0xB1, 0x71, + 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, + 0x94, 0x54, 0x9C, + 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, + 0x48, 0x49, 0x89, + 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, + 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 }; -uint16_t computeCRC(const std::vector& cmd) +uint16_t computeCRC(const std::vector & cmd) { uint16_t crc_hi = 0x00FF; uint16_t crc_lo = 0x00FF; - for (auto byte : cmd) - { + for (auto byte : cmd) { std::size_t index = crc_lo ^ byte; crc_lo = crc_hi ^ kCRCHiTable[index]; crc_hi = kCRCLoTable[index]; diff --git a/robotiq_driver/src/gripper_interface_test.cpp b/robotiq_driver/src/gripper_interface_test.cpp index f28ccc9..b77dc32 100644 --- a/robotiq_driver/src/gripper_interface_test.cpp +++ b/robotiq_driver/src/gripper_interface_test.cpp @@ -36,8 +36,7 @@ constexpr auto kSlaveID = 0x09; int main() { - try - { + try { RobotiqGripperInterface gripper(kComPort, kSlaveID); std::cout << "Deactivating gripper...\n"; @@ -50,29 +49,25 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Half closing gripper...\n"; gripper.setGripperPosition(0x80); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -81,8 +76,7 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -91,13 +85,10 @@ int main() std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { std::cout << "Failed to communicating with the Gripper. Please check the Gripper connection"; return 1; } diff --git a/robotiq_driver/src/hardware_interface.cpp b/robotiq_driver/src/hardware_interface.cpp index 60baa70..35ffbba 100644 --- a/robotiq_driver/src/hardware_interface.cpp +++ b/robotiq_driver/src/hardware_interface.cpp @@ -51,10 +51,10 @@ RobotiqGripperHardwareInterface::RobotiqGripperHardwareInterface() { } -hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(const hardware_interface::HardwareInfo& info) +hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init( + const hardware_interface::HardwareInfo & info) { - if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) - { + if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) { return CallbackReturn::ERROR; } @@ -74,52 +74,49 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(cons reactivate_gripper_cmd_ = NO_NEW_CMD_; reactivate_gripper_async_cmd_.store(false); - const hardware_interface::ComponentInfo& joint = info_.joints[0]; + const hardware_interface::ComponentInfo & joint = info_.joints[0]; // There is one command interface: position. - if (joint.command_interfaces.size() != 1) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), - joint.command_interfaces.size()); + if (joint.command_interfaces.size() != 1) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), + joint.command_interfaces.size()); return CallbackReturn::ERROR; } - if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), - joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); + if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), + joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); return CallbackReturn::ERROR; } // There are two state interfaces: position and velocity. - if (joint.state_interfaces.size() != 2) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), - joint.state_interfaces.size()); + if (joint.state_interfaces.size() != 2) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), + joint.state_interfaces.size()); return CallbackReturn::ERROR; } - for (int i = 0; i < 2; ++i) - { + for (int i = 0; i < 2; ++i) { if (!(joint.state_interfaces[i].name == hardware_interface::HW_IF_POSITION || - joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) + joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) { - RCLCPP_FATAL(kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), - joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, - hardware_interface::HW_IF_VELOCITY); + RCLCPP_FATAL( + kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), + joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, + hardware_interface::HW_IF_VELOCITY); return CallbackReturn::ERROR; } } - try - { + try { // Create the interface to the gripper. gripper_interface_ = std::make_unique(com_port_); gripper_interface_->setSpeed(gripper_speed * 0xFF); gripper_interface_->setForce(gripper_force * 0xFF); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { RCLCPP_FATAL(kLogger, "Failed to open gripper port."); return CallbackReturn::ERROR; } @@ -127,51 +124,57 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(cons return CallbackReturn::SUCCESS; } -std::vector RobotiqGripperHardwareInterface::export_state_interfaces() +std::vector RobotiqGripperHardwareInterface:: +export_state_interfaces() { std::vector state_interfaces; state_interfaces.emplace_back( - hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_)); + hardware_interface::StateInterface( + info_.joints[0].name, hardware_interface::HW_IF_POSITION, + &gripper_position_)); state_interfaces.emplace_back( - hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, &gripper_velocity_)); + hardware_interface::StateInterface( + info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, + &gripper_velocity_)); return state_interfaces; } -std::vector RobotiqGripperHardwareInterface::export_command_interfaces() +std::vector RobotiqGripperHardwareInterface:: +export_command_interfaces() { std::vector command_interfaces; - command_interfaces.emplace_back(hardware_interface::CommandInterface( + command_interfaces.emplace_back( + hardware_interface::CommandInterface( info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_command_)); command_interfaces.emplace_back( - hardware_interface::CommandInterface("reactivate_gripper", "reactivate_gripper_cmd", &reactivate_gripper_cmd_)); - command_interfaces.emplace_back(hardware_interface::CommandInterface( + hardware_interface::CommandInterface( + "reactivate_gripper", "reactivate_gripper_cmd", + &reactivate_gripper_cmd_)); + command_interfaces.emplace_back( + hardware_interface::CommandInterface( "reactivate_gripper", "reactivate_gripper_response", &reactivate_gripper_response_)); return command_interfaces; } hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) { // set some default values for joints - if (std::isnan(gripper_position_)) - { + if (std::isnan(gripper_position_)) { gripper_position_ = 0; gripper_velocity_ = 0; gripper_position_command_ = 0; } // Activate the gripper. - try - { + try { gripper_interface_->deactivateGripper(); gripper_interface_->activateGripper(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { RCLCPP_FATAL(kLogger, "Failed to communicate with Gripper. Check Gripper connection."); return CallbackReturn::ERROR; } @@ -180,59 +183,53 @@ RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*pr command_interface_is_running_.store(true); - command_interface_ = std::thread([this] { - // Read from and write to the gripper at 100 Hz. - const auto io_interval = std::chrono::milliseconds(10); - auto last_io = std::chrono::high_resolution_clock::now(); - - while (command_interface_is_running_.load()) - { - const auto now = std::chrono::high_resolution_clock::now(); - if (now - last_io > io_interval) - { - try - { - // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). - if (reactivate_gripper_async_cmd_.load()) - { - this->gripper_interface_->deactivateGripper(); - this->gripper_interface_->activateGripper(); - reactivate_gripper_async_cmd_.store(false); - reactivate_gripper_async_response_.store(true); + command_interface_ = std::thread( + [this] { + // Read from and write to the gripper at 100 Hz. + const auto io_interval = std::chrono::milliseconds(10); + auto last_io = std::chrono::high_resolution_clock::now(); + + while (command_interface_is_running_.load()) { + const auto now = std::chrono::high_resolution_clock::now(); + if (now - last_io > io_interval) { + try { + // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). + if (reactivate_gripper_async_cmd_.load()) { + this->gripper_interface_->deactivateGripper(); + this->gripper_interface_->activateGripper(); + reactivate_gripper_async_cmd_.store(false); + reactivate_gripper_async_response_.store(true); + } + + // Write the latest command to the gripper. + this->gripper_interface_->setGripperPosition(write_command_.load()); + + // Read the state of the gripper. + gripper_current_state_.store(this->gripper_interface_->getGripperPosition()); + + last_io = now; + } catch (serial::IOException & e) { + RCLCPP_ERROR( + kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", + e.what()); + command_interface_is_running_.store(false); } - - // Write the latest command to the gripper. - this->gripper_interface_->setGripperPosition(write_command_.load()); - - // Read the state of the gripper. - gripper_current_state_.store(this->gripper_interface_->getGripperPosition()); - - last_io = now; - } - catch (serial::IOException& e) - { - RCLCPP_ERROR(kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", e.what()); - command_interface_is_running_.store(false); } } - } - }); + }); return CallbackReturn::SUCCESS; } hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) { command_interface_is_running_.store(false); command_interface_.join(); - try - { + try { gripper_interface_->deactivateGripper(); - } - catch (const std::exception& e) - { + } catch (const std::exception & e) { RCLCPP_ERROR(kLogger, "Failed to deactivate gripper. Check Gripper connection"); return CallbackReturn::ERROR; } @@ -240,20 +237,20 @@ RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State& /* return CallbackReturn::SUCCESS; } -hardware_interface::return_type RobotiqGripperHardwareInterface::read(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::read( + const rclcpp::Time & /*time*/, + const rclcpp::Duration & /*period*/) { - gripper_position_ = gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / kGripperRange; + gripper_position_ = gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / + kGripperRange; - if (!std::isnan(reactivate_gripper_cmd_)) - { + if (!std::isnan(reactivate_gripper_cmd_)) { RCLCPP_INFO(kLogger, "Sending gripper reactivation request."); reactivate_gripper_async_cmd_.store(true); reactivate_gripper_cmd_ = NO_NEW_CMD_; } - if (reactivate_gripper_async_response_.load().has_value()) - { + if (reactivate_gripper_async_response_.load().has_value()) { reactivate_gripper_response_ = reactivate_gripper_async_response_.load().value(); reactivate_gripper_async_response_.store(std::nullopt); } @@ -261,10 +258,12 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::read(const rclc return hardware_interface::return_type::OK; } -hardware_interface::return_type RobotiqGripperHardwareInterface::write(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::write( + const rclcpp::Time & /*time*/, + const rclcpp::Duration & /*period*/) { - double gripper_pos = (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + kGripperMinPos; + double gripper_pos = (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + + kGripperMinPos; gripper_pos = std::max(std::min(gripper_pos, 255.0), 0.0); write_command_.store(uint8_t(gripper_pos)); @@ -275,4 +274,6 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::write(const rcl #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS(robotiq_driver::RobotiqGripperHardwareInterface, hardware_interface::SystemInterface) +PLUGINLIB_EXPORT_CLASS( + robotiq_driver::RobotiqGripperHardwareInterface, + hardware_interface::SystemInterface) diff --git a/robotiq_driver/src/robotiq_gripper_interface.cpp b/robotiq_driver/src/robotiq_gripper_interface.cpp index 0cf7157..410d876 100644 --- a/robotiq_driver/src/robotiq_gripper_interface.cpp +++ b/robotiq_driver/src/robotiq_gripper_interface.cpp @@ -72,45 +72,40 @@ static uint8_t getSecondByte(uint16_t val) return val & 0x00FF; } -RobotiqGripperInterface::RobotiqGripperInterface(const std::string& com_port, uint8_t slave_id) - : port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)) +RobotiqGripperInterface::RobotiqGripperInterface(const std::string & com_port, uint8_t slave_id) +: port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)) , slave_id_(slave_id) , read_command_(createReadCommand(kFirstOutputRegister, kNumOutputRegisters)) , commanded_gripper_speed_(0x80) , commanded_gripper_force_(0x80) { - if (!port_.isOpen()) - { + if (!port_.isOpen()) { THROW(serial::IOException, "Failed to open gripper port."); } } void RobotiqGripperInterface::activateGripper() { - const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0100, 0x0000, 0x0000 } // set rACT to 1, clear all + const auto cmd = createWriteCommand( + kActionRequestRegister, {0x0100, 0x0000, 0x0000} // set rACT to 1, clear all // other registers. ); - try - { + try { sendCommand(cmd); readResponse(kWriteResponseSize); updateStatus(); - if (gripper_status_ == GripperStatus::COMPLETED) - { + if (gripper_status_ == GripperStatus::COMPLETED) { return; } - while (gripper_status_ == GripperStatus::IN_PROGRESS) - { + while (gripper_status_ == GripperStatus::IN_PROGRESS) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); updateStatus(); } - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -119,14 +114,11 @@ void RobotiqGripperInterface::activateGripper() void RobotiqGripperInterface::deactivateGripper() { - const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0000, 0x0000, 0x0000 }); - try - { + const auto cmd = createWriteCommand(kActionRequestRegister, {0x0000, 0x0000, 0x0000}); + try { sendCommand(cmd); readResponse(kWriteResponseSize); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -140,22 +132,20 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t gripper_options_2 = 0x00; const auto cmd = - createWriteCommand(kActionRequestRegister, - { uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), - uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_) }); - try - { + createWriteCommand( + kActionRequestRegister, + {uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), + uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_)}); + try { sendCommand(cmd); readResponse(kWriteResponseSize); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to set gripper position\n"; - if (port_.isOpen()) - { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " - "communication with gripper.\n ERROR: " + if (port_.isOpen()) { + std::cerr << + "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " << e.what(); return; } @@ -165,12 +155,9 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t RobotiqGripperInterface::getGripperPosition() { - try - { + try { updateStatus(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -181,12 +168,9 @@ uint8_t RobotiqGripperInterface::getGripperPosition() bool RobotiqGripperInterface::gripperIsMoving() { - try - { + try { updateStatus(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -195,14 +179,16 @@ bool RobotiqGripperInterface::gripperIsMoving() return object_detection_status_ == ObjectDetectionStatus::MOVING; } -std::vector RobotiqGripperInterface::createReadCommand(uint16_t first_register, uint8_t num_registers) +std::vector RobotiqGripperInterface::createReadCommand( + uint16_t first_register, + uint8_t num_registers) { - std::vector cmd = { slave_id_, - kReadFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers) }; + std::vector cmd = {slave_id_, + kReadFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers)}; auto crc = computeCRC(cmd); cmd.push_back(getFirstByte(crc)); cmd.push_back(getSecondByte(crc)); @@ -219,21 +205,21 @@ void RobotiqGripperInterface::setForce(uint8_t force) commanded_gripper_force_ = force; } -std::vector RobotiqGripperInterface::createWriteCommand(uint16_t first_register, - const std::vector& data) +std::vector RobotiqGripperInterface::createWriteCommand( + uint16_t first_register, + const std::vector & data) { uint16_t num_registers = data.size(); uint8_t num_bytes = 2 * num_registers; - std::vector cmd = { slave_id_, - kWriteFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers), - num_bytes }; - for (auto d : data) - { + std::vector cmd = {slave_id_, + kWriteFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers), + num_bytes}; + for (auto d : data) { cmd.push_back(getFirstByte(d)); cmd.push_back(getSecondByte(d)); } @@ -250,24 +236,24 @@ std::vector RobotiqGripperInterface::readResponse(size_t num_bytes_requ std::vector response; size_t num_bytes_read = port_.read(response, num_bytes_requested); - if (num_bytes_read != num_bytes_requested) - { + if (num_bytes_read != num_bytes_requested) { const auto error_msg = - "Requested " + std::to_string(num_bytes_requested) + " bytes, but only got " + std::to_string(num_bytes_read); + "Requested " + std::to_string(num_bytes_requested) + " bytes, but only got " + std::to_string( + num_bytes_read); THROW(serial::IOException, error_msg.c_str()); } return response; } -void RobotiqGripperInterface::sendCommand(const std::vector& cmd) +void RobotiqGripperInterface::sendCommand(const std::vector & cmd) { size_t num_bytes_written = port_.write(cmd); port_.flush(); - if (num_bytes_written != cmd.size()) - { - const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + " bytes, but only wrote " + - std::to_string(num_bytes_written); + if (num_bytes_written != cmd.size()) { + const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + + " bytes, but only wrote " + + std::to_string(num_bytes_written); THROW(serial::IOException, error_msg.c_str()); } } @@ -275,8 +261,7 @@ void RobotiqGripperInterface::sendCommand(const std::vector& cmd) void RobotiqGripperInterface::updateStatus() { // Tell the gripper that we want to read its status. - try - { + try { sendCommand(read_command_); const auto response = readResponse(kReadResponseSize); @@ -285,14 +270,15 @@ void RobotiqGripperInterface::updateStatus() uint8_t gripper_status_byte = response[kResponseHeaderSize + kGripperStatusIndex]; // Activation status. - activation_status_ = ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; + activation_status_ = + ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; // Action status. - action_status_ = ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; + action_status_ = + ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; // Gripper status. - switch ((gripper_status_byte & 0x30) >> 4) - { + switch ((gripper_status_byte & 0x30) >> 4) { case 0x00: gripper_status_ = GripperStatus::RESET; break; @@ -305,8 +291,7 @@ void RobotiqGripperInterface::updateStatus() } // Object detection status. - switch ((gripper_status_byte & 0xC0) >> 6) - { + switch ((gripper_status_byte & 0xC0) >> 6) { case 0x00: object_detection_status_ = ObjectDetectionStatus::MOVING; break; @@ -323,14 +308,12 @@ void RobotiqGripperInterface::updateStatus() // Read the current gripper position. gripper_position_ = response[kResponseHeaderSize + kPositionIndex]; - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { std::cerr << "Failed to update gripper status.\n"; - if (port_.isOpen()) - { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " - "communication with gripper.\n ERROR: " + if (port_.isOpen()) { + std::cerr << + "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " << e.what(); return; } From 3dce97aae1d4fad2426b55d0c275118b0deb735a Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 26 Jun 2023 15:26:22 -0600 Subject: [PATCH 04/19] reorder package.xml for validation move author to after maintainer Signed-off-by: Alex Moriarty --- robotiq_controllers/package.xml | 2 +- robotiq_driver/package.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/robotiq_controllers/package.xml b/robotiq_controllers/package.xml index 51d9170..56525ad 100644 --- a/robotiq_controllers/package.xml +++ b/robotiq_controllers/package.xml @@ -4,10 +4,10 @@ robotiq_controllers 0.0.0 Controllers for the Robotiq gripper. - Cory Crean Alex Moriarty Marq Rasumessen BSD-3-Clause + Cory Crean ament_cmake diff --git a/robotiq_driver/package.xml b/robotiq_driver/package.xml index bb0f7cf..99f3752 100644 --- a/robotiq_driver/package.xml +++ b/robotiq_driver/package.xml @@ -4,10 +4,10 @@ robotiq_driver 0.0.0 ROS2 driver package for the Robotiq gripper. - Cory Crean Alex Moriarty Marq Rasumessen BSD + Cory Crean ament_cmake From 7c1b5502edf592b929b83ae205c80c8b5b0ca77e Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 26 Jun 2023 15:44:14 -0600 Subject: [PATCH 05/19] add serial fork & branch to all .repos files serial is not yet release in ros2 so it is needed here for CI jobs Signed-off-by: Alex Moriarty --- ros2_robotiq_gripper.humble.repos | 9 ++++----- ros2_robotiq_gripper.iron.repos | 9 ++++----- ros2_robotiq_gripper.rolling.repos | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ros2_robotiq_gripper.humble.repos b/ros2_robotiq_gripper.humble.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper.humble.repos +++ b/ros2_robotiq_gripper.humble.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 diff --git a/ros2_robotiq_gripper.iron.repos b/ros2_robotiq_gripper.iron.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper.iron.repos +++ b/ros2_robotiq_gripper.iron.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 diff --git a/ros2_robotiq_gripper.rolling.repos b/ros2_robotiq_gripper.rolling.repos index 1b3910e..510d9bc 100644 --- a/ros2_robotiq_gripper.rolling.repos +++ b/ros2_robotiq_gripper.rolling.repos @@ -1,6 +1,5 @@ repositories: - ## EXAMPLE DEPENDENCY -# : -# type: git -# url: git@github.com:/.git -# version: master + serial: + type: git + url: https://github.com/tylerjw/serial.git + version: ros2 From 2e56e0eb4a36057de379ef1b0be92f26ccbf29e6 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 26 Jun 2023 15:55:07 -0600 Subject: [PATCH 06/19] ci: remove rhel github jobs Removing RHEL jobs for now will first focus on releasing for Ubuntu Signed-off-by: Alex Moriarty --- .../workflows/humble-rhel-binary-build.yml | 33 ------------------- .github/workflows/iron-rhel-binary-build.yml | 33 ------------------- .../workflows/rolling-rhel-binary-build.yml | 33 ------------------- 3 files changed, 99 deletions(-) delete mode 100644 .github/workflows/humble-rhel-binary-build.yml delete mode 100644 .github/workflows/iron-rhel-binary-build.yml delete mode 100644 .github/workflows/rolling-rhel-binary-build.yml diff --git a/.github/workflows/humble-rhel-binary-build.yml b/.github/workflows/humble-rhel-binary-build.yml deleted file mode 100644 index 25e9883..0000000 --- a/.github/workflows/humble-rhel-binary-build.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Humble RHEL Binary Build -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - push: - branches: - - main - schedule: - # Run every day to detect flakiness and broken dependencies - - cron: '03 1 * * *' - - -jobs: - humble_rhel_binary: - name: Humble RHEL binary build - runs-on: ubuntu-latest - env: - ROS_DISTRO: humble - container: ghcr.io/ros-controls/ros:humble-rhel - steps: - - uses: actions/checkout@v3 - with: - path: src/ros2_robotiq_gripper - - run: | - rosdep update - rosdep install -iy --from-path src/ros2_robotiq_gripper - source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash - colcon build - colcon test diff --git a/.github/workflows/iron-rhel-binary-build.yml b/.github/workflows/iron-rhel-binary-build.yml deleted file mode 100644 index b4c175e..0000000 --- a/.github/workflows/iron-rhel-binary-build.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Iron RHEL Binary Build -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - push: - branches: - - main - schedule: - # Run every day to detect flakiness and broken dependencies - - cron: '03 1 * * *' - - -jobs: - iron_rhel_binary: - name: Iron RHEL binary build - runs-on: ubuntu-latest - env: - ROS_DISTRO: iron - container: ghcr.io/ros-controls/ros:iron-rhel - steps: - - uses: actions/checkout@v3 - with: - path: src/ros2_robotiq_gripper - - run: | - rosdep update - rosdep install -iy --from-path src/ros2_robotiq_gripper - source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash - colcon build - colcon test diff --git a/.github/workflows/rolling-rhel-binary-build.yml b/.github/workflows/rolling-rhel-binary-build.yml deleted file mode 100644 index f237cc4..0000000 --- a/.github/workflows/rolling-rhel-binary-build.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Rolling RHEL Binary Build -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - push: - branches: - - main - schedule: - # Run every day to detect flakiness and broken dependencies - - cron: '03 1 * * *' - - -jobs: - rolling_rhel_binary: - name: Rolling RHEL binary build - runs-on: ubuntu-latest - env: - ROS_DISTRO: rolling - container: ghcr.io/ros-controls/ros:rolling-rhel - steps: - - uses: actions/checkout@v3 - with: - path: src/ros2_robotiq_gripper - - run: | - rosdep update - rosdep install -iy --from-path src/ros2_robotiq_gripper - source /opt/ros/${{ env.ROS_DISTRO }}/setup.bash - colcon build - colcon test From 1d95302ae9f8b6e428aef007b0ba6f660c2692e6 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 26 Jun 2023 15:56:00 -0600 Subject: [PATCH 07/19] ci: remove abi compatibility jobs Removing these jobs for now until we have finished release Signed-off-by: Alex Moriarty --- .../workflows/humble-abi-compatibility.yml | 20 ------------------- .github/workflows/iron-abi-compatibility.yml | 20 ------------------- .../workflows/rolling-abi-compatibility.yml | 20 ------------------- 3 files changed, 60 deletions(-) delete mode 100644 .github/workflows/humble-abi-compatibility.yml delete mode 100644 .github/workflows/iron-abi-compatibility.yml delete mode 100644 .github/workflows/rolling-abi-compatibility.yml diff --git a/.github/workflows/humble-abi-compatibility.yml b/.github/workflows/humble-abi-compatibility.yml deleted file mode 100644 index 4df57dc..0000000 --- a/.github/workflows/humble-abi-compatibility.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Humble - ABI Compatibility Check -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - -jobs: - abi_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: ros-industrial/industrial_ci@master - env: - ROS_DISTRO: humble - ROS_REPO: main - ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} - NOT_TEST_BUILD: true diff --git a/.github/workflows/iron-abi-compatibility.yml b/.github/workflows/iron-abi-compatibility.yml deleted file mode 100644 index 22dc31d..0000000 --- a/.github/workflows/iron-abi-compatibility.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Iron - ABI Compatibility Check -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - -jobs: - abi_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: ros-industrial/industrial_ci@master - env: - ROS_DISTRO: iron - ROS_REPO: main - ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} - NOT_TEST_BUILD: true diff --git a/.github/workflows/rolling-abi-compatibility.yml b/.github/workflows/rolling-abi-compatibility.yml deleted file mode 100644 index 8d0778d..0000000 --- a/.github/workflows/rolling-abi-compatibility.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Rolling - ABI Compatibility Check -on: - workflow_dispatch: - branches: - - main - pull_request: - branches: - - main - -jobs: - abi_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: ros-industrial/industrial_ci@master - env: - ROS_DISTRO: rolling - ROS_REPO: main - ABICHECK_URL: github:${{ github.repository }}#${{ github.base_ref }} - NOT_TEST_BUILD: true From 7565379d4e02dc1bfd43fba0f10818cc3a84fd0c Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Tue, 27 Jun 2023 13:25:21 -0600 Subject: [PATCH 08/19] pre-commit run --all-files Run pre-commit Signed-off-by: Alex Moriarty --- .../robotiq_activation_controller.hpp | 13 +- .../src/robotiq_activation_controller.cpp | 61 +++--- robotiq_driver/include/robotiq_driver/crc.hpp | 2 +- .../robotiq_driver/hardware_interface.hpp | 14 +- .../robotiq_gripper_interface.hpp | 8 +- robotiq_driver/src/crc.cpp | 83 +++----- robotiq_driver/src/gripper_interface_test.cpp | 25 ++- robotiq_driver/src/hardware_interface.cpp | 187 +++++++++--------- .../src/robotiq_gripper_interface.cpp | 149 +++++++------- 9 files changed, 266 insertions(+), 276 deletions(-) diff --git a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp index a9ea994..20126ea 100644 --- a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp +++ b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp @@ -41,20 +41,17 @@ class RobotiqActivationController : public controller_interface::ControllerInter controller_interface::InterfaceConfiguration state_interface_configuration() const override; - controller_interface::return_type update( - const rclcpp::Time & time, - const rclcpp::Duration & period) override; + controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override; - CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; - CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; CallbackReturn on_init() override; private: - bool reactivateGripper( - std_srvs::srv::Trigger::Request::SharedPtr req, - std_srvs::srv::Trigger::Response::SharedPtr resp); + bool reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr req, + std_srvs::srv::Trigger::Response::SharedPtr resp); static constexpr double ASYNC_WAITING = 2.0; enum CommandInterfaces diff --git a/robotiq_controllers/src/robotiq_activation_controller.cpp b/robotiq_controllers/src/robotiq_activation_controller.cpp index 6685c45..aa63d21 100644 --- a/robotiq_controllers/src/robotiq_activation_controller.cpp +++ b/robotiq_controllers/src/robotiq_activation_controller.cpp @@ -30,8 +30,7 @@ namespace robotiq_controllers { -controller_interface::InterfaceConfiguration RobotiqActivationController:: -command_interface_configuration() const +controller_interface::InterfaceConfiguration RobotiqActivationController::command_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -42,8 +41,7 @@ command_interface_configuration() const return config; } -controller_interface::InterfaceConfiguration RobotiqActivationController:: -state_interface_configuration() const +controller_interface::InterfaceConfiguration RobotiqActivationController::state_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -51,64 +49,67 @@ state_interface_configuration() const return config; } -controller_interface::return_type RobotiqActivationController::update( - const rclcpp::Time & /*time*/, - const rclcpp::Duration & /*period*/) +controller_interface::return_type RobotiqActivationController::update(const rclcpp::Time& /*time*/, + const rclcpp::Duration& /*period*/) { return controller_interface::return_type::OK; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) +RobotiqActivationController::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) { // Check command interfaces. - if (command_interfaces_.size() != 2) { - RCLCPP_ERROR( - get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, - command_interfaces_.size()); + if (command_interfaces_.size() != 2) + { + RCLCPP_ERROR(get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, + command_interfaces_.size()); return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR; } - try { + try + { // Create service for re-activating the gripper. reactivate_gripper_srv_ = get_node()->create_service( - "~/reactivate_gripper", - [this](std_srvs::srv::Trigger::Request::SharedPtr req, - std_srvs::srv::Trigger::Response::SharedPtr resp) { - this->reactivateGripper(req, resp); - }); - } catch (...) { + "~/reactivate_gripper", + [this](std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr resp) { + this->reactivateGripper(req, resp); + }); + } + catch (...) + { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) +RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) { - try { + try + { reactivate_gripper_srv_.reset(); - } catch (...) { + } + catch (...) + { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_init() +rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn RobotiqActivationController::on_init() { return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -bool RobotiqActivationController::reactivateGripper( - std_srvs::srv::Trigger::Request::SharedPtr /*req*/, - std_srvs::srv::Trigger::Response::SharedPtr resp) +bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr /*req*/, + std_srvs::srv::Trigger::Response::SharedPtr resp) { command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].set_value(ASYNC_WAITING); command_interfaces_[REACTIVATE_GRIPPER_CMD].set_value(1.0); - while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) { + while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) + { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } resp->success = command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value(); @@ -119,6 +120,4 @@ bool RobotiqActivationController::reactivateGripper( #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robotiq_controllers::RobotiqActivationController, - controller_interface::ControllerInterface) +PLUGINLIB_EXPORT_CLASS(robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface) diff --git a/robotiq_driver/include/robotiq_driver/crc.hpp b/robotiq_driver/include/robotiq_driver/crc.hpp index 869fcae..45b0507 100644 --- a/robotiq_driver/include/robotiq_driver/crc.hpp +++ b/robotiq_driver/include/robotiq_driver/crc.hpp @@ -3,4 +3,4 @@ #include #include -uint16_t computeCRC(const std::vector & cmd); +uint16_t computeCRC(const std::vector& cmd); diff --git a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp index 4f09c6d..5f52b75 100644 --- a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp @@ -54,7 +54,7 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa RobotiqGripperHardwareInterface(); ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override; + CallbackReturn on_init(const hardware_interface::HardwareInfo& info) override; ROBOTIQ_DRIVER_PUBLIC std::vector export_state_interfaces() override; @@ -63,20 +63,16 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa std::vector export_command_interfaces() override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type read( - const rclcpp::Time & time, - const rclcpp::Duration & period) override; + hardware_interface::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type write( - const rclcpp::Time & time, - const rclcpp::Duration & period) override; + hardware_interface::return_type write(const rclcpp::Time& time, const rclcpp::Duration& period) override; private: static constexpr double NO_NEW_CMD_ = std::numeric_limits::quiet_NaN(); diff --git a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp index 4c7c898..8fef23c 100644 --- a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp @@ -41,7 +41,7 @@ class RobotiqGripperInterface { public: - RobotiqGripperInterface(const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); + RobotiqGripperInterface(const std::string& com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); /** * @brief Activates the gripper. @@ -122,9 +122,7 @@ class RobotiqGripperInterface private: std::vector createReadCommand(uint16_t first_register, uint8_t num_registers); - std::vector createWriteCommand( - uint16_t first_register, - const std::vector & data); + std::vector createWriteCommand(uint16_t first_register, const std::vector& data); /** * @brief read response from the gripper. @@ -140,7 +138,7 @@ class RobotiqGripperInterface * @param cmd The command. * @throw serial::IOException on failure to successfully communicate with gripper port */ - void sendCommand(const std::vector & cmd); + void sendCommand(const std::vector& cmd); /** * @brief Read the current status of the gripper, and update member variables as appropriate. diff --git a/robotiq_driver/src/crc.cpp b/robotiq_driver/src/crc.cpp index 6ae6bf6..db69d3c 100644 --- a/robotiq_driver/src/crc.cpp +++ b/robotiq_driver/src/crc.cpp @@ -2,72 +2,47 @@ /* Table of CRC values for high–order byte */ static unsigned char kCRCHiTable[] = { - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, - 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, - 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, - 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, - 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, - 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, - 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, - 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, + 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, + 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, + 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, + 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, + 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, + 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, + 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, + 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, + 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 }; /* Table of CRC values for low–order byte */ static unsigned char kCRCLoTable[] = { - 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, - 0xCC, 0x0C, 0x0D, - 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, - 0xD9, 0x1B, 0xDB, - 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, - 0x16, 0xD6, 0xD2, - 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, - 0xF6, 0xF7, 0x37, - 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, - 0x39, 0xF9, 0xF8, - 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, - 0x2C, 0xE4, 0x24, - 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, - 0x61, 0xA1, 0x63, - 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, - 0x6F, 0x6E, 0xAE, - 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, - 0xBE, 0x7E, 0x7F, - 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, - 0x73, 0xB1, 0x71, - 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, - 0x94, 0x54, 0x9C, - 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, - 0x48, 0x49, 0x89, - 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, - 0x87, 0x47, 0x46, + 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, + 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, + 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, + 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, + 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, + 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, + 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, + 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, + 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, + 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, + 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, + 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, + 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 }; -uint16_t computeCRC(const std::vector & cmd) +uint16_t computeCRC(const std::vector& cmd) { uint16_t crc_hi = 0x00FF; uint16_t crc_lo = 0x00FF; - for (auto byte : cmd) { + for (auto byte : cmd) + { std::size_t index = crc_lo ^ byte; crc_lo = crc_hi ^ kCRCHiTable[index]; crc_hi = kCRCLoTable[index]; diff --git a/robotiq_driver/src/gripper_interface_test.cpp b/robotiq_driver/src/gripper_interface_test.cpp index b77dc32..f28ccc9 100644 --- a/robotiq_driver/src/gripper_interface_test.cpp +++ b/robotiq_driver/src/gripper_interface_test.cpp @@ -36,7 +36,8 @@ constexpr auto kSlaveID = 0x09; int main() { - try { + try + { RobotiqGripperInterface gripper(kComPort, kSlaveID); std::cout << "Deactivating gripper...\n"; @@ -49,25 +50,29 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Half closing gripper...\n"; gripper.setGripperPosition(0x80); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -76,7 +81,8 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -85,10 +91,13 @@ int main() std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) { + while (gripper.gripperIsMoving()) + { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { std::cout << "Failed to communicating with the Gripper. Please check the Gripper connection"; return 1; } diff --git a/robotiq_driver/src/hardware_interface.cpp b/robotiq_driver/src/hardware_interface.cpp index 35ffbba..60baa70 100644 --- a/robotiq_driver/src/hardware_interface.cpp +++ b/robotiq_driver/src/hardware_interface.cpp @@ -51,10 +51,10 @@ RobotiqGripperHardwareInterface::RobotiqGripperHardwareInterface() { } -hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init( - const hardware_interface::HardwareInfo & info) +hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(const hardware_interface::HardwareInfo& info) { - if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) { + if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) + { return CallbackReturn::ERROR; } @@ -74,49 +74,52 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init( reactivate_gripper_cmd_ = NO_NEW_CMD_; reactivate_gripper_async_cmd_.store(false); - const hardware_interface::ComponentInfo & joint = info_.joints[0]; + const hardware_interface::ComponentInfo& joint = info_.joints[0]; // There is one command interface: position. - if (joint.command_interfaces.size() != 1) { - RCLCPP_FATAL( - kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), - joint.command_interfaces.size()); + if (joint.command_interfaces.size() != 1) + { + RCLCPP_FATAL(kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), + joint.command_interfaces.size()); return CallbackReturn::ERROR; } - if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) { - RCLCPP_FATAL( - kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), - joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); + if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) + { + RCLCPP_FATAL(kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), + joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); return CallbackReturn::ERROR; } // There are two state interfaces: position and velocity. - if (joint.state_interfaces.size() != 2) { - RCLCPP_FATAL( - kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), - joint.state_interfaces.size()); + if (joint.state_interfaces.size() != 2) + { + RCLCPP_FATAL(kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), + joint.state_interfaces.size()); return CallbackReturn::ERROR; } - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) + { if (!(joint.state_interfaces[i].name == hardware_interface::HW_IF_POSITION || - joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) + joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) { - RCLCPP_FATAL( - kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), - joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, - hardware_interface::HW_IF_VELOCITY); + RCLCPP_FATAL(kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), + joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, + hardware_interface::HW_IF_VELOCITY); return CallbackReturn::ERROR; } } - try { + try + { // Create the interface to the gripper. gripper_interface_ = std::make_unique(com_port_); gripper_interface_->setSpeed(gripper_speed * 0xFF); gripper_interface_->setForce(gripper_force * 0xFF); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { RCLCPP_FATAL(kLogger, "Failed to open gripper port."); return CallbackReturn::ERROR; } @@ -124,57 +127,51 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init( return CallbackReturn::SUCCESS; } -std::vector RobotiqGripperHardwareInterface:: -export_state_interfaces() +std::vector RobotiqGripperHardwareInterface::export_state_interfaces() { std::vector state_interfaces; state_interfaces.emplace_back( - hardware_interface::StateInterface( - info_.joints[0].name, hardware_interface::HW_IF_POSITION, - &gripper_position_)); + hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_)); state_interfaces.emplace_back( - hardware_interface::StateInterface( - info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, - &gripper_velocity_)); + hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, &gripper_velocity_)); return state_interfaces; } -std::vector RobotiqGripperHardwareInterface:: -export_command_interfaces() +std::vector RobotiqGripperHardwareInterface::export_command_interfaces() { std::vector command_interfaces; - command_interfaces.emplace_back( - hardware_interface::CommandInterface( + command_interfaces.emplace_back(hardware_interface::CommandInterface( info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_command_)); command_interfaces.emplace_back( - hardware_interface::CommandInterface( - "reactivate_gripper", "reactivate_gripper_cmd", - &reactivate_gripper_cmd_)); - command_interfaces.emplace_back( - hardware_interface::CommandInterface( + hardware_interface::CommandInterface("reactivate_gripper", "reactivate_gripper_cmd", &reactivate_gripper_cmd_)); + command_interfaces.emplace_back(hardware_interface::CommandInterface( "reactivate_gripper", "reactivate_gripper_response", &reactivate_gripper_response_)); return command_interfaces; } hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) +RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) { // set some default values for joints - if (std::isnan(gripper_position_)) { + if (std::isnan(gripper_position_)) + { gripper_position_ = 0; gripper_velocity_ = 0; gripper_position_command_ = 0; } // Activate the gripper. - try { + try + { gripper_interface_->deactivateGripper(); gripper_interface_->activateGripper(); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { RCLCPP_FATAL(kLogger, "Failed to communicate with Gripper. Check Gripper connection."); return CallbackReturn::ERROR; } @@ -183,53 +180,59 @@ RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State & /*p command_interface_is_running_.store(true); - command_interface_ = std::thread( - [this] { - // Read from and write to the gripper at 100 Hz. - const auto io_interval = std::chrono::milliseconds(10); - auto last_io = std::chrono::high_resolution_clock::now(); - - while (command_interface_is_running_.load()) { - const auto now = std::chrono::high_resolution_clock::now(); - if (now - last_io > io_interval) { - try { - // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). - if (reactivate_gripper_async_cmd_.load()) { - this->gripper_interface_->deactivateGripper(); - this->gripper_interface_->activateGripper(); - reactivate_gripper_async_cmd_.store(false); - reactivate_gripper_async_response_.store(true); - } - - // Write the latest command to the gripper. - this->gripper_interface_->setGripperPosition(write_command_.load()); - - // Read the state of the gripper. - gripper_current_state_.store(this->gripper_interface_->getGripperPosition()); - - last_io = now; - } catch (serial::IOException & e) { - RCLCPP_ERROR( - kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", - e.what()); - command_interface_is_running_.store(false); + command_interface_ = std::thread([this] { + // Read from and write to the gripper at 100 Hz. + const auto io_interval = std::chrono::milliseconds(10); + auto last_io = std::chrono::high_resolution_clock::now(); + + while (command_interface_is_running_.load()) + { + const auto now = std::chrono::high_resolution_clock::now(); + if (now - last_io > io_interval) + { + try + { + // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). + if (reactivate_gripper_async_cmd_.load()) + { + this->gripper_interface_->deactivateGripper(); + this->gripper_interface_->activateGripper(); + reactivate_gripper_async_cmd_.store(false); + reactivate_gripper_async_response_.store(true); } + + // Write the latest command to the gripper. + this->gripper_interface_->setGripperPosition(write_command_.load()); + + // Read the state of the gripper. + gripper_current_state_.store(this->gripper_interface_->getGripperPosition()); + + last_io = now; + } + catch (serial::IOException& e) + { + RCLCPP_ERROR(kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", e.what()); + command_interface_is_running_.store(false); } } - }); + } + }); return CallbackReturn::SUCCESS; } hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) +RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) { command_interface_is_running_.store(false); command_interface_.join(); - try { + try + { gripper_interface_->deactivateGripper(); - } catch (const std::exception & e) { + } + catch (const std::exception& e) + { RCLCPP_ERROR(kLogger, "Failed to deactivate gripper. Check Gripper connection"); return CallbackReturn::ERROR; } @@ -237,20 +240,20 @@ RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State & / return CallbackReturn::SUCCESS; } -hardware_interface::return_type RobotiqGripperHardwareInterface::read( - const rclcpp::Time & /*time*/, - const rclcpp::Duration & /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::read(const rclcpp::Time& /*time*/, + const rclcpp::Duration& /*period*/) { - gripper_position_ = gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / - kGripperRange; + gripper_position_ = gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / kGripperRange; - if (!std::isnan(reactivate_gripper_cmd_)) { + if (!std::isnan(reactivate_gripper_cmd_)) + { RCLCPP_INFO(kLogger, "Sending gripper reactivation request."); reactivate_gripper_async_cmd_.store(true); reactivate_gripper_cmd_ = NO_NEW_CMD_; } - if (reactivate_gripper_async_response_.load().has_value()) { + if (reactivate_gripper_async_response_.load().has_value()) + { reactivate_gripper_response_ = reactivate_gripper_async_response_.load().value(); reactivate_gripper_async_response_.store(std::nullopt); } @@ -258,12 +261,10 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::read( return hardware_interface::return_type::OK; } -hardware_interface::return_type RobotiqGripperHardwareInterface::write( - const rclcpp::Time & /*time*/, - const rclcpp::Duration & /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::write(const rclcpp::Time& /*time*/, + const rclcpp::Duration& /*period*/) { - double gripper_pos = (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + - kGripperMinPos; + double gripper_pos = (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + kGripperMinPos; gripper_pos = std::max(std::min(gripper_pos, 255.0), 0.0); write_command_.store(uint8_t(gripper_pos)); @@ -274,6 +275,4 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::write( #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robotiq_driver::RobotiqGripperHardwareInterface, - hardware_interface::SystemInterface) +PLUGINLIB_EXPORT_CLASS(robotiq_driver::RobotiqGripperHardwareInterface, hardware_interface::SystemInterface) diff --git a/robotiq_driver/src/robotiq_gripper_interface.cpp b/robotiq_driver/src/robotiq_gripper_interface.cpp index 410d876..0cf7157 100644 --- a/robotiq_driver/src/robotiq_gripper_interface.cpp +++ b/robotiq_driver/src/robotiq_gripper_interface.cpp @@ -72,40 +72,45 @@ static uint8_t getSecondByte(uint16_t val) return val & 0x00FF; } -RobotiqGripperInterface::RobotiqGripperInterface(const std::string & com_port, uint8_t slave_id) -: port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)) +RobotiqGripperInterface::RobotiqGripperInterface(const std::string& com_port, uint8_t slave_id) + : port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)) , slave_id_(slave_id) , read_command_(createReadCommand(kFirstOutputRegister, kNumOutputRegisters)) , commanded_gripper_speed_(0x80) , commanded_gripper_force_(0x80) { - if (!port_.isOpen()) { + if (!port_.isOpen()) + { THROW(serial::IOException, "Failed to open gripper port."); } } void RobotiqGripperInterface::activateGripper() { - const auto cmd = createWriteCommand( - kActionRequestRegister, {0x0100, 0x0000, 0x0000} // set rACT to 1, clear all + const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0100, 0x0000, 0x0000 } // set rACT to 1, clear all // other registers. ); - try { + try + { sendCommand(cmd); readResponse(kWriteResponseSize); updateStatus(); - if (gripper_status_ == GripperStatus::COMPLETED) { + if (gripper_status_ == GripperStatus::COMPLETED) + { return; } - while (gripper_status_ == GripperStatus::IN_PROGRESS) { + while (gripper_status_ == GripperStatus::IN_PROGRESS) + { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); updateStatus(); } - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -114,11 +119,14 @@ void RobotiqGripperInterface::activateGripper() void RobotiqGripperInterface::deactivateGripper() { - const auto cmd = createWriteCommand(kActionRequestRegister, {0x0000, 0x0000, 0x0000}); - try { + const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0000, 0x0000, 0x0000 }); + try + { sendCommand(cmd); readResponse(kWriteResponseSize); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -132,20 +140,22 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t gripper_options_2 = 0x00; const auto cmd = - createWriteCommand( - kActionRequestRegister, - {uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), - uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_)}); - try { + createWriteCommand(kActionRequestRegister, + { uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), + uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_) }); + try + { sendCommand(cmd); readResponse(kWriteResponseSize); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { // catch connection error and rethrow std::cerr << "Failed to set gripper position\n"; - if (port_.isOpen()) { - std::cerr << - "Error caught while reading or writing to device. Connection is open, continuing to attempt " - "communication with gripper.\n ERROR: " + if (port_.isOpen()) + { + std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " << e.what(); return; } @@ -155,9 +165,12 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t RobotiqGripperInterface::getGripperPosition() { - try { + try + { updateStatus(); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -168,9 +181,12 @@ uint8_t RobotiqGripperInterface::getGripperPosition() bool RobotiqGripperInterface::gripperIsMoving() { - try { + try + { updateStatus(); - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -179,16 +195,14 @@ bool RobotiqGripperInterface::gripperIsMoving() return object_detection_status_ == ObjectDetectionStatus::MOVING; } -std::vector RobotiqGripperInterface::createReadCommand( - uint16_t first_register, - uint8_t num_registers) +std::vector RobotiqGripperInterface::createReadCommand(uint16_t first_register, uint8_t num_registers) { - std::vector cmd = {slave_id_, - kReadFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers)}; + std::vector cmd = { slave_id_, + kReadFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers) }; auto crc = computeCRC(cmd); cmd.push_back(getFirstByte(crc)); cmd.push_back(getSecondByte(crc)); @@ -205,21 +219,21 @@ void RobotiqGripperInterface::setForce(uint8_t force) commanded_gripper_force_ = force; } -std::vector RobotiqGripperInterface::createWriteCommand( - uint16_t first_register, - const std::vector & data) +std::vector RobotiqGripperInterface::createWriteCommand(uint16_t first_register, + const std::vector& data) { uint16_t num_registers = data.size(); uint8_t num_bytes = 2 * num_registers; - std::vector cmd = {slave_id_, - kWriteFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers), - num_bytes}; - for (auto d : data) { + std::vector cmd = { slave_id_, + kWriteFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers), + num_bytes }; + for (auto d : data) + { cmd.push_back(getFirstByte(d)); cmd.push_back(getSecondByte(d)); } @@ -236,24 +250,24 @@ std::vector RobotiqGripperInterface::readResponse(size_t num_bytes_requ std::vector response; size_t num_bytes_read = port_.read(response, num_bytes_requested); - if (num_bytes_read != num_bytes_requested) { + if (num_bytes_read != num_bytes_requested) + { const auto error_msg = - "Requested " + std::to_string(num_bytes_requested) + " bytes, but only got " + std::to_string( - num_bytes_read); + "Requested " + std::to_string(num_bytes_requested) + " bytes, but only got " + std::to_string(num_bytes_read); THROW(serial::IOException, error_msg.c_str()); } return response; } -void RobotiqGripperInterface::sendCommand(const std::vector & cmd) +void RobotiqGripperInterface::sendCommand(const std::vector& cmd) { size_t num_bytes_written = port_.write(cmd); port_.flush(); - if (num_bytes_written != cmd.size()) { - const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + - " bytes, but only wrote " + - std::to_string(num_bytes_written); + if (num_bytes_written != cmd.size()) + { + const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + " bytes, but only wrote " + + std::to_string(num_bytes_written); THROW(serial::IOException, error_msg.c_str()); } } @@ -261,7 +275,8 @@ void RobotiqGripperInterface::sendCommand(const std::vector & cmd) void RobotiqGripperInterface::updateStatus() { // Tell the gripper that we want to read its status. - try { + try + { sendCommand(read_command_); const auto response = readResponse(kReadResponseSize); @@ -270,15 +285,14 @@ void RobotiqGripperInterface::updateStatus() uint8_t gripper_status_byte = response[kResponseHeaderSize + kGripperStatusIndex]; // Activation status. - activation_status_ = - ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; + activation_status_ = ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; // Action status. - action_status_ = - ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; + action_status_ = ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; // Gripper status. - switch ((gripper_status_byte & 0x30) >> 4) { + switch ((gripper_status_byte & 0x30) >> 4) + { case 0x00: gripper_status_ = GripperStatus::RESET; break; @@ -291,7 +305,8 @@ void RobotiqGripperInterface::updateStatus() } // Object detection status. - switch ((gripper_status_byte & 0xC0) >> 6) { + switch ((gripper_status_byte & 0xC0) >> 6) + { case 0x00: object_detection_status_ = ObjectDetectionStatus::MOVING; break; @@ -308,12 +323,14 @@ void RobotiqGripperInterface::updateStatus() // Read the current gripper position. gripper_position_ = response[kResponseHeaderSize + kPositionIndex]; - } catch (const serial::IOException & e) { + } + catch (const serial::IOException& e) + { std::cerr << "Failed to update gripper status.\n"; - if (port_.isOpen()) { - std::cerr << - "Error caught while reading or writing to device. Connection is open, continuing to attempt " - "communication with gripper.\n ERROR: " + if (port_.isOpen()) + { + std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + "communication with gripper.\n ERROR: " << e.what(); return; } From c7a2de7957c33760ec846a13782e9ab67ece00da Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 30 Jun 2023 10:54:04 -0600 Subject: [PATCH 09/19] Sync .clang-format with ament_lint and run pre-commit all files Signed-off-by: Alex Moriarty --- .clang-format | 85 ++------ README.md | 3 +- .../robotiq_activation_controller.hpp | 13 +- .../src/robotiq_activation_controller.cpp | 58 +++--- robotiq_driver/include/robotiq_driver/crc.hpp | 4 +- .../robotiq_driver/hardware_interface.hpp | 15 +- .../robotiq_gripper_interface.hpp | 11 +- robotiq_driver/src/crc.cpp | 67 +++---- robotiq_driver/src/gripper_interface_test.cpp | 28 +-- robotiq_driver/src/hardware_interface.cpp | 148 +++++++------- .../src/robotiq_gripper_interface.cpp | 181 ++++++++---------- 11 files changed, 253 insertions(+), 360 deletions(-) diff --git a/.clang-format b/.clang-format index 9a6ec50..4a79087 100644 --- a/.clang-format +++ b/.clang-format @@ -1,75 +1,20 @@ --- -BasedOnStyle: Google -ColumnLimit: 120 -MaxEmptyLinesToKeep: 1 -SortIncludes: false +Language: Cpp +BasedOnStyle: Google -Standard: Auto -IndentWidth: 2 -TabWidth: 2 -UseTab: Never AccessModifierOffset: -2 -ConstructorInitializerIndentWidth: 2 -NamespaceIndentation: None -ContinuationIndentWidth: 4 -IndentCaseLabels: true -IndentFunctionDeclarationAfterType: false - -AlignEscapedNewlinesLeft: false -AlignTrailingComments: true - -AllowAllParametersOfDeclarationOnNextLine: false -ExperimentalAutoDetectBinPacking: false -ObjCSpaceBeforeProtocolList: true -Cpp11BracedListStyle: false - -AllowShortBlocksOnASingleLine: true -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortCaseLabelsOnASingleLine: false - -AlwaysBreakTemplateDeclarations: true -AlwaysBreakBeforeMultilineStrings: false -BreakBeforeBinaryOperators: false -BreakBeforeTernaryOperators: false -BreakConstructorInitializersBeforeComma: true - -BinPackParameters: true -ConstructorInitializerAllOnOneLineOrOnePerLine: true -DerivePointerBinding: false -PointerBindsToType: true - -PenaltyExcessCharacter: 50 -PenaltyBreakBeforeFirstCallParameter: 30 -PenaltyBreakComment: 1000 -PenaltyBreakFirstLessLess: 10 -PenaltyBreakString: 100 -PenaltyReturnTypeOnItsOwnLine: 50 - -SpacesBeforeTrailingComments: 2 -SpacesInParentheses: false -SpacesInAngles: false -SpaceInEmptyParentheses: false -SpacesInCStyleCastParentheses: false -SpaceAfterCStyleCast: false -SpaceAfterControlStatementKeyword: true -SpaceBeforeAssignmentOperators: true - -# Configure each individual brace in BraceWrapping -BreakBeforeBraces: Custom - -# Control of individual brace wrapping cases +AlignAfterOpenBracket: AlwaysBreak BraceWrapping: - AfterCaseLabel: true - AfterClass: true - AfterControlStatement: true - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterStruct: true - AfterUnion: true - BeforeCatch: true - BeforeElse: true - IndentBraces: false + AfterClass: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterEnum: true +BreakBeforeBraces: Custom +ColumnLimit: 100 +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 2 +DerivePointerAlignment: false +PointerAlignment: Middle +ReflowComments: false ... diff --git a/README.md b/README.md index bde3028..0f74c7a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ +# ros2_robotiq_gripper +This repository contains the ROS 2 driver, controller and description packages for working with a Robotiq Gripper. -# ros2_robotiq_gripper ## Build status diff --git a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp index 20126ea..f922400 100644 --- a/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp +++ b/robotiq_controllers/include/robotiq_controllers/robotiq_activation_controller.hpp @@ -29,7 +29,6 @@ #pragma once #include "controller_interface/controller_interface.hpp" - #include "std_srvs/srv/trigger.hpp" namespace robotiq_controllers @@ -41,17 +40,19 @@ class RobotiqActivationController : public controller_interface::ControllerInter controller_interface::InterfaceConfiguration state_interface_configuration() const override; - controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override; + controller_interface::return_type update( + const rclcpp::Time & time, const rclcpp::Duration & period) override; - CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; - CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; CallbackReturn on_init() override; private: - bool reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr req, - std_srvs::srv::Trigger::Response::SharedPtr resp); + bool reactivateGripper( + std_srvs::srv::Trigger::Request::SharedPtr req, + std_srvs::srv::Trigger::Response::SharedPtr resp); static constexpr double ASYNC_WAITING = 2.0; enum CommandInterfaces diff --git a/robotiq_controllers/src/robotiq_activation_controller.cpp b/robotiq_controllers/src/robotiq_activation_controller.cpp index aa63d21..03c4fa8 100644 --- a/robotiq_controllers/src/robotiq_activation_controller.cpp +++ b/robotiq_controllers/src/robotiq_activation_controller.cpp @@ -30,7 +30,8 @@ namespace robotiq_controllers { -controller_interface::InterfaceConfiguration RobotiqActivationController::command_interface_configuration() const +controller_interface::InterfaceConfiguration +RobotiqActivationController::command_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -41,7 +42,8 @@ controller_interface::InterfaceConfiguration RobotiqActivationController::comman return config; } -controller_interface::InterfaceConfiguration RobotiqActivationController::state_interface_configuration() const +controller_interface::InterfaceConfiguration +RobotiqActivationController::state_interface_configuration() const { controller_interface::InterfaceConfiguration config; config.type = controller_interface::interface_configuration_type::INDIVIDUAL; @@ -49,67 +51,62 @@ controller_interface::InterfaceConfiguration RobotiqActivationController::state_ return config; } -controller_interface::return_type RobotiqActivationController::update(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +controller_interface::return_type RobotiqActivationController::update( + const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) { return controller_interface::return_type::OK; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqActivationController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) { // Check command interfaces. - if (command_interfaces_.size() != 2) - { - RCLCPP_ERROR(get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, - command_interfaces_.size()); + if (command_interfaces_.size() != 2) { + RCLCPP_ERROR( + get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2, + command_interfaces_.size()); return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR; } - try - { + try { // Create service for re-activating the gripper. reactivate_gripper_srv_ = get_node()->create_service( - "~/reactivate_gripper", - [this](std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr resp) { - this->reactivateGripper(req, resp); - }); - } - catch (...) - { + "~/reactivate_gripper", + [this]( + std_srvs::srv::Trigger::Request::SharedPtr req, + std_srvs::srv::Trigger::Response::SharedPtr resp) { this->reactivateGripper(req, resp); }); + } catch (...) { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn -RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) +RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/) { - try - { + try { reactivate_gripper_srv_.reset(); - } - catch (...) - { + } catch (...) { return LifecycleNodeInterface::CallbackReturn::ERROR; } return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn RobotiqActivationController::on_init() +rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn +RobotiqActivationController::on_init() { return LifecycleNodeInterface::CallbackReturn::SUCCESS; } -bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr /*req*/, - std_srvs::srv::Trigger::Response::SharedPtr resp) +bool RobotiqActivationController::reactivateGripper( + std_srvs::srv::Trigger::Request::SharedPtr /*req*/, + std_srvs::srv::Trigger::Response::SharedPtr resp) { command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].set_value(ASYNC_WAITING); command_interfaces_[REACTIVATE_GRIPPER_CMD].set_value(1.0); - while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) - { + while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } resp->success = command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value(); @@ -120,4 +117,5 @@ bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Requ #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS(robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface) +PLUGINLIB_EXPORT_CLASS( + robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface) diff --git a/robotiq_driver/include/robotiq_driver/crc.hpp b/robotiq_driver/include/robotiq_driver/crc.hpp index 45b0507..f88617c 100644 --- a/robotiq_driver/include/robotiq_driver/crc.hpp +++ b/robotiq_driver/include/robotiq_driver/crc.hpp @@ -1,6 +1,6 @@ #pragma once -#include #include +#include -uint16_t computeCRC(const std::vector& cmd); +uint16_t computeCRC(const std::vector & cmd); diff --git a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp index 5f52b75..d763e40 100644 --- a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp @@ -39,9 +39,8 @@ #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "rclcpp/macros.hpp" #include "rclcpp/rclcpp.hpp" - -#include "robotiq_driver/visibility_control.h" #include "robotiq_driver/robotiq_gripper_interface.hpp" +#include "robotiq_driver/visibility_control.h" namespace robotiq_driver { @@ -54,7 +53,7 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa RobotiqGripperHardwareInterface(); ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_init(const hardware_interface::HardwareInfo& info) override; + CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override; ROBOTIQ_DRIVER_PUBLIC std::vector export_state_interfaces() override; @@ -63,16 +62,18 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa std::vector export_command_interfaces() override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override; ROBOTIQ_DRIVER_PUBLIC - CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; + CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override; + hardware_interface::return_type read( + const rclcpp::Time & time, const rclcpp::Duration & period) override; ROBOTIQ_DRIVER_PUBLIC - hardware_interface::return_type write(const rclcpp::Time& time, const rclcpp::Duration& period) override; + hardware_interface::return_type write( + const rclcpp::Time & time, const rclcpp::Duration & period) override; private: static constexpr double NO_NEW_CMD_ = std::numeric_limits::quiet_NaN(); diff --git a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp index 8fef23c..8389688 100644 --- a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp @@ -28,11 +28,11 @@ #pragma once +#include + #include #include -#include - /** * @brief This class is responsible for communicating with the gripper via a serial port, and maintaining a record of * the gripper's current state. @@ -41,7 +41,7 @@ class RobotiqGripperInterface { public: - RobotiqGripperInterface(const std::string& com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); + RobotiqGripperInterface(const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); /** * @brief Activates the gripper. @@ -122,7 +122,8 @@ class RobotiqGripperInterface private: std::vector createReadCommand(uint16_t first_register, uint8_t num_registers); - std::vector createWriteCommand(uint16_t first_register, const std::vector& data); + std::vector createWriteCommand( + uint16_t first_register, const std::vector & data); /** * @brief read response from the gripper. @@ -138,7 +139,7 @@ class RobotiqGripperInterface * @param cmd The command. * @throw serial::IOException on failure to successfully communicate with gripper port */ - void sendCommand(const std::vector& cmd); + void sendCommand(const std::vector & cmd); /** * @brief Read the current status of the gripper, and update member variables as appropriate. diff --git a/robotiq_driver/src/crc.cpp b/robotiq_driver/src/crc.cpp index db69d3c..09b855d 100644 --- a/robotiq_driver/src/crc.cpp +++ b/robotiq_driver/src/crc.cpp @@ -2,47 +2,48 @@ /* Table of CRC values for high–order byte */ static unsigned char kCRCHiTable[] = { - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, - 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, - 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, - 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, - 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, - 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 -}; + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, + 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40}; /* Table of CRC values for low–order byte */ static unsigned char kCRCLoTable[] = { - 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, - 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, - 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, - 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, - 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, - 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, - 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, - 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, - 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, - 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, - 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, - 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, - 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, - 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 -}; + 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, + 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, + 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, + 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, + 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, + 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, + 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, + 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, + 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, + 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, + 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, + 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, + 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, + 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, + 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, + 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40}; -uint16_t computeCRC(const std::vector& cmd) +uint16_t computeCRC(const std::vector & cmd) { uint16_t crc_hi = 0x00FF; uint16_t crc_lo = 0x00FF; - for (auto byte : cmd) - { + for (auto byte : cmd) { std::size_t index = crc_lo ^ byte; crc_lo = crc_hi ^ kCRCHiTable[index]; crc_hi = kCRCLoTable[index]; diff --git a/robotiq_driver/src/gripper_interface_test.cpp b/robotiq_driver/src/gripper_interface_test.cpp index f28ccc9..3c1c382 100644 --- a/robotiq_driver/src/gripper_interface_test.cpp +++ b/robotiq_driver/src/gripper_interface_test.cpp @@ -27,17 +27,15 @@ // POSSIBILITY OF SUCH DAMAGE. #include -#include - #include +#include constexpr auto kComPort = "/dev/ttyUSB0"; constexpr auto kSlaveID = 0x09; int main() { - try - { + try { RobotiqGripperInterface gripper(kComPort, kSlaveID); std::cout << "Deactivating gripper...\n"; @@ -50,29 +48,25 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Half closing gripper...\n"; gripper.setGripperPosition(0x80); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -81,8 +75,7 @@ int main() std::cout << "Closing gripper...\n"; gripper.setGripperPosition(0xFF); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } @@ -91,13 +84,10 @@ int main() std::cout << "Opening gripper...\n"; gripper.setGripperPosition(0x00); - while (gripper.gripperIsMoving()) - { + while (gripper.gripperIsMoving()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { std::cout << "Failed to communicating with the Gripper. Please check the Gripper connection"; return 1; } diff --git a/robotiq_driver/src/hardware_interface.cpp b/robotiq_driver/src/hardware_interface.cpp index 60baa70..d14f72b 100644 --- a/robotiq_driver/src/hardware_interface.cpp +++ b/robotiq_driver/src/hardware_interface.cpp @@ -28,6 +28,8 @@ #include "robotiq_driver/hardware_interface.hpp" +#include + #include #include #include @@ -37,7 +39,6 @@ #include "hardware_interface/actuator_interface.hpp" #include "hardware_interface/types/hardware_interface_type_values.hpp" #include "rclcpp/rclcpp.hpp" -#include constexpr uint8_t kGripperMinPos = 3; constexpr uint8_t kGripperMaxPos = 230; @@ -47,14 +48,12 @@ const auto kLogger = rclcpp::get_logger("RobotiqGripperHardwareInterface"); namespace robotiq_driver { -RobotiqGripperHardwareInterface::RobotiqGripperHardwareInterface() -{ -} +RobotiqGripperHardwareInterface::RobotiqGripperHardwareInterface() {} -hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(const hardware_interface::HardwareInfo& info) +hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init( + const hardware_interface::HardwareInfo & info) { - if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) - { + if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) { return CallbackReturn::ERROR; } @@ -74,52 +73,48 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(cons reactivate_gripper_cmd_ = NO_NEW_CMD_; reactivate_gripper_async_cmd_.store(false); - const hardware_interface::ComponentInfo& joint = info_.joints[0]; + const hardware_interface::ComponentInfo & joint = info_.joints[0]; // There is one command interface: position. - if (joint.command_interfaces.size() != 1) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), - joint.command_interfaces.size()); + if (joint.command_interfaces.size() != 1) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(), + joint.command_interfaces.size()); return CallbackReturn::ERROR; } - if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), - joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); + if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %s command interfaces found. '%s' expected.", joint.name.c_str(), + joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION); return CallbackReturn::ERROR; } // There are two state interfaces: position and velocity. - if (joint.state_interfaces.size() != 2) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), - joint.state_interfaces.size()); + if (joint.state_interfaces.size() != 2) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %zu state interface. 2 expected.", joint.name.c_str(), + joint.state_interfaces.size()); return CallbackReturn::ERROR; } - for (int i = 0; i < 2; ++i) - { + for (int i = 0; i < 2; ++i) { if (!(joint.state_interfaces[i].name == hardware_interface::HW_IF_POSITION || - joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) - { - RCLCPP_FATAL(kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), - joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, - hardware_interface::HW_IF_VELOCITY); + joint.state_interfaces[i].name == hardware_interface::HW_IF_VELOCITY)) { + RCLCPP_FATAL( + kLogger, "Joint '%s' has %s state interface. Expected %s or %s.", joint.name.c_str(), + joint.state_interfaces[i].name.c_str(), hardware_interface::HW_IF_POSITION, + hardware_interface::HW_IF_VELOCITY); return CallbackReturn::ERROR; } } - try - { + try { // Create the interface to the gripper. gripper_interface_ = std::make_unique(com_port_); gripper_interface_->setSpeed(gripper_speed * 0xFF); gripper_interface_->setForce(gripper_force * 0xFF); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { RCLCPP_FATAL(kLogger, "Failed to open gripper port."); return CallbackReturn::ERROR; } @@ -127,51 +122,49 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_init(cons return CallbackReturn::SUCCESS; } -std::vector RobotiqGripperHardwareInterface::export_state_interfaces() +std::vector +RobotiqGripperHardwareInterface::export_state_interfaces() { std::vector state_interfaces; - state_interfaces.emplace_back( - hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_)); - state_interfaces.emplace_back( - hardware_interface::StateInterface(info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, &gripper_velocity_)); + state_interfaces.emplace_back(hardware_interface::StateInterface( + info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_)); + state_interfaces.emplace_back(hardware_interface::StateInterface( + info_.joints[0].name, hardware_interface::HW_IF_VELOCITY, &gripper_velocity_)); return state_interfaces; } -std::vector RobotiqGripperHardwareInterface::export_command_interfaces() +std::vector +RobotiqGripperHardwareInterface::export_command_interfaces() { std::vector command_interfaces; command_interfaces.emplace_back(hardware_interface::CommandInterface( - info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_command_)); - command_interfaces.emplace_back( - hardware_interface::CommandInterface("reactivate_gripper", "reactivate_gripper_cmd", &reactivate_gripper_cmd_)); + info_.joints[0].name, hardware_interface::HW_IF_POSITION, &gripper_position_command_)); + command_interfaces.emplace_back(hardware_interface::CommandInterface( + "reactivate_gripper", "reactivate_gripper_cmd", &reactivate_gripper_cmd_)); command_interfaces.emplace_back(hardware_interface::CommandInterface( - "reactivate_gripper", "reactivate_gripper_response", &reactivate_gripper_response_)); + "reactivate_gripper", "reactivate_gripper_response", &reactivate_gripper_response_)); return command_interfaces; } -hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*previous_state*/) +hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_activate( + const rclcpp_lifecycle::State & /*previous_state*/) { // set some default values for joints - if (std::isnan(gripper_position_)) - { + if (std::isnan(gripper_position_)) { gripper_position_ = 0; gripper_velocity_ = 0; gripper_position_command_ = 0; } // Activate the gripper. - try - { + try { gripper_interface_->deactivateGripper(); gripper_interface_->activateGripper(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { RCLCPP_FATAL(kLogger, "Failed to communicate with Gripper. Check Gripper connection."); return CallbackReturn::ERROR; } @@ -185,16 +178,12 @@ RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*pr const auto io_interval = std::chrono::milliseconds(10); auto last_io = std::chrono::high_resolution_clock::now(); - while (command_interface_is_running_.load()) - { + while (command_interface_is_running_.load()) { const auto now = std::chrono::high_resolution_clock::now(); - if (now - last_io > io_interval) - { - try - { + if (now - last_io > io_interval) { + try { // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). - if (reactivate_gripper_async_cmd_.load()) - { + if (reactivate_gripper_async_cmd_.load()) { this->gripper_interface_->deactivateGripper(); this->gripper_interface_->activateGripper(); reactivate_gripper_async_cmd_.store(false); @@ -208,10 +197,9 @@ RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*pr gripper_current_state_.store(this->gripper_interface_->getGripperPosition()); last_io = now; - } - catch (serial::IOException& e) - { - RCLCPP_ERROR(kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", e.what()); + } catch (serial::IOException & e) { + RCLCPP_ERROR( + kLogger, "Check Robotiq Gripper connection and restart drivers. ERROR: %s", e.what()); command_interface_is_running_.store(false); } } @@ -221,18 +209,15 @@ RobotiqGripperHardwareInterface::on_activate(const rclcpp_lifecycle::State& /*pr return CallbackReturn::SUCCESS; } -hardware_interface::CallbackReturn -RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/) +hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_deactivate( + const rclcpp_lifecycle::State & /*previous_state*/) { command_interface_is_running_.store(false); command_interface_.join(); - try - { + try { gripper_interface_->deactivateGripper(); - } - catch (const std::exception& e) - { + } catch (const std::exception & e) { RCLCPP_ERROR(kLogger, "Failed to deactivate gripper. Check Gripper connection"); return CallbackReturn::ERROR; } @@ -240,20 +225,19 @@ RobotiqGripperHardwareInterface::on_deactivate(const rclcpp_lifecycle::State& /* return CallbackReturn::SUCCESS; } -hardware_interface::return_type RobotiqGripperHardwareInterface::read(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::read( + const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) { - gripper_position_ = gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / kGripperRange; + gripper_position_ = + gripper_closed_pos_ * (gripper_current_state_.load() - kGripperMinPos) / kGripperRange; - if (!std::isnan(reactivate_gripper_cmd_)) - { + if (!std::isnan(reactivate_gripper_cmd_)) { RCLCPP_INFO(kLogger, "Sending gripper reactivation request."); reactivate_gripper_async_cmd_.store(true); reactivate_gripper_cmd_ = NO_NEW_CMD_; } - if (reactivate_gripper_async_response_.load().has_value()) - { + if (reactivate_gripper_async_response_.load().has_value()) { reactivate_gripper_response_ = reactivate_gripper_async_response_.load().value(); reactivate_gripper_async_response_.store(std::nullopt); } @@ -261,10 +245,11 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::read(const rclc return hardware_interface::return_type::OK; } -hardware_interface::return_type RobotiqGripperHardwareInterface::write(const rclcpp::Time& /*time*/, - const rclcpp::Duration& /*period*/) +hardware_interface::return_type RobotiqGripperHardwareInterface::write( + const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) { - double gripper_pos = (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + kGripperMinPos; + double gripper_pos = + (gripper_position_command_ / gripper_closed_pos_) * kGripperRange + kGripperMinPos; gripper_pos = std::max(std::min(gripper_pos, 255.0), 0.0); write_command_.store(uint8_t(gripper_pos)); @@ -275,4 +260,5 @@ hardware_interface::return_type RobotiqGripperHardwareInterface::write(const rcl #include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS(robotiq_driver::RobotiqGripperHardwareInterface, hardware_interface::SystemInterface) +PLUGINLIB_EXPORT_CLASS( + robotiq_driver::RobotiqGripperHardwareInterface, hardware_interface::SystemInterface) diff --git a/robotiq_driver/src/robotiq_gripper_interface.cpp b/robotiq_driver/src/robotiq_gripper_interface.cpp index 0cf7157..58b6d24 100644 --- a/robotiq_driver/src/robotiq_gripper_interface.cpp +++ b/robotiq_driver/src/robotiq_gripper_interface.cpp @@ -27,12 +27,13 @@ // POSSIBILITY OF SUCH DAMAGE. #include "robotiq_driver/robotiq_gripper_interface.hpp" -#include "robotiq_driver/crc.hpp" +#include #include #include #include -#include + +#include "robotiq_driver/crc.hpp" constexpr int kBaudRate = 115200; constexpr auto kTimeoutMilliseconds = 1000; @@ -62,55 +63,44 @@ constexpr size_t kResponseHeaderSize = 3; constexpr size_t kGripperStatusIndex = 0; constexpr size_t kPositionIndex = 4; -static uint8_t getFirstByte(uint16_t val) -{ - return (val & 0xFF00) >> 8; -} +static uint8_t getFirstByte(uint16_t val) { return (val & 0xFF00) >> 8; } -static uint8_t getSecondByte(uint16_t val) -{ - return val & 0x00FF; -} +static uint8_t getSecondByte(uint16_t val) { return val & 0x00FF; } -RobotiqGripperInterface::RobotiqGripperInterface(const std::string& com_port, uint8_t slave_id) - : port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)) - , slave_id_(slave_id) - , read_command_(createReadCommand(kFirstOutputRegister, kNumOutputRegisters)) - , commanded_gripper_speed_(0x80) - , commanded_gripper_force_(0x80) +RobotiqGripperInterface::RobotiqGripperInterface(const std::string & com_port, uint8_t slave_id) +: port_(com_port, kBaudRate, serial::Timeout::simpleTimeout(kTimeoutMilliseconds)), + slave_id_(slave_id), + read_command_(createReadCommand(kFirstOutputRegister, kNumOutputRegisters)), + commanded_gripper_speed_(0x80), + commanded_gripper_force_(0x80) { - if (!port_.isOpen()) - { + if (!port_.isOpen()) { THROW(serial::IOException, "Failed to open gripper port."); } } void RobotiqGripperInterface::activateGripper() { - const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0100, 0x0000, 0x0000 } // set rACT to 1, clear all - // other registers. + const auto cmd = createWriteCommand( + kActionRequestRegister, {0x0100, 0x0000, 0x0000} // set rACT to 1, clear all + // other registers. ); - try - { + try { sendCommand(cmd); readResponse(kWriteResponseSize); updateStatus(); - if (gripper_status_ == GripperStatus::COMPLETED) - { + if (gripper_status_ == GripperStatus::COMPLETED) { return; } - while (gripper_status_ == GripperStatus::IN_PROGRESS) - { + while (gripper_status_ == GripperStatus::IN_PROGRESS) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); updateStatus(); } - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -119,14 +109,11 @@ void RobotiqGripperInterface::activateGripper() void RobotiqGripperInterface::deactivateGripper() { - const auto cmd = createWriteCommand(kActionRequestRegister, { 0x0000, 0x0000, 0x0000 }); - try - { + const auto cmd = createWriteCommand(kActionRequestRegister, {0x0000, 0x0000, 0x0000}); + try { sendCommand(cmd); readResponse(kWriteResponseSize); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to activate gripper"; throw; @@ -139,22 +126,19 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t gripper_options_1 = 0x00; uint8_t gripper_options_2 = 0x00; - const auto cmd = - createWriteCommand(kActionRequestRegister, - { uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), - uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_) }); - try - { + const auto cmd = createWriteCommand( + kActionRequestRegister, + {uint16_t(action_register << 8 | gripper_options_1), uint16_t(gripper_options_2 << 8 | pos), + uint16_t(commanded_gripper_speed_ << 8 | commanded_gripper_force_)}); + try { sendCommand(cmd); readResponse(kWriteResponseSize); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to set gripper position\n"; - if (port_.isOpen()) - { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + if (port_.isOpen()) { + std::cerr << "Error caught while reading or writing to device. Connection is open, " + "continuing to attempt " "communication with gripper.\n ERROR: " << e.what(); return; @@ -165,12 +149,9 @@ void RobotiqGripperInterface::setGripperPosition(uint8_t pos) uint8_t RobotiqGripperInterface::getGripperPosition() { - try - { + try { updateStatus(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -181,12 +162,9 @@ uint8_t RobotiqGripperInterface::getGripperPosition() bool RobotiqGripperInterface::gripperIsMoving() { - try - { + try { updateStatus(); - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { // catch connection error and rethrow std::cerr << "Failed to get gripper position\n"; throw; @@ -195,45 +173,41 @@ bool RobotiqGripperInterface::gripperIsMoving() return object_detection_status_ == ObjectDetectionStatus::MOVING; } -std::vector RobotiqGripperInterface::createReadCommand(uint16_t first_register, uint8_t num_registers) +std::vector RobotiqGripperInterface::createReadCommand( + uint16_t first_register, uint8_t num_registers) { - std::vector cmd = { slave_id_, - kReadFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers) }; + std::vector cmd = { + slave_id_, + kReadFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers)}; auto crc = computeCRC(cmd); cmd.push_back(getFirstByte(crc)); cmd.push_back(getSecondByte(crc)); return cmd; } -void RobotiqGripperInterface::setSpeed(uint8_t speed) -{ - commanded_gripper_speed_ = speed; -} +void RobotiqGripperInterface::setSpeed(uint8_t speed) { commanded_gripper_speed_ = speed; } -void RobotiqGripperInterface::setForce(uint8_t force) -{ - commanded_gripper_force_ = force; -} +void RobotiqGripperInterface::setForce(uint8_t force) { commanded_gripper_force_ = force; } -std::vector RobotiqGripperInterface::createWriteCommand(uint16_t first_register, - const std::vector& data) +std::vector RobotiqGripperInterface::createWriteCommand( + uint16_t first_register, const std::vector & data) { uint16_t num_registers = data.size(); uint8_t num_bytes = 2 * num_registers; - std::vector cmd = { slave_id_, - kWriteFunctionCode, - getFirstByte(first_register), - getSecondByte(first_register), - getFirstByte(num_registers), - getSecondByte(num_registers), - num_bytes }; - for (auto d : data) - { + std::vector cmd = { + slave_id_, + kWriteFunctionCode, + getFirstByte(first_register), + getSecondByte(first_register), + getFirstByte(num_registers), + getSecondByte(num_registers), + num_bytes}; + for (auto d : data) { cmd.push_back(getFirstByte(d)); cmd.push_back(getSecondByte(d)); } @@ -250,24 +224,22 @@ std::vector RobotiqGripperInterface::readResponse(size_t num_bytes_requ std::vector response; size_t num_bytes_read = port_.read(response, num_bytes_requested); - if (num_bytes_read != num_bytes_requested) - { - const auto error_msg = - "Requested " + std::to_string(num_bytes_requested) + " bytes, but only got " + std::to_string(num_bytes_read); + if (num_bytes_read != num_bytes_requested) { + const auto error_msg = "Requested " + std::to_string(num_bytes_requested) + + " bytes, but only got " + std::to_string(num_bytes_read); THROW(serial::IOException, error_msg.c_str()); } return response; } -void RobotiqGripperInterface::sendCommand(const std::vector& cmd) +void RobotiqGripperInterface::sendCommand(const std::vector & cmd) { size_t num_bytes_written = port_.write(cmd); port_.flush(); - if (num_bytes_written != cmd.size()) - { - const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + " bytes, but only wrote " + - std::to_string(num_bytes_written); + if (num_bytes_written != cmd.size()) { + const auto error_msg = "Attempted to write " + std::to_string(cmd.size()) + + " bytes, but only wrote " + std::to_string(num_bytes_written); THROW(serial::IOException, error_msg.c_str()); } } @@ -275,8 +247,7 @@ void RobotiqGripperInterface::sendCommand(const std::vector& cmd) void RobotiqGripperInterface::updateStatus() { // Tell the gripper that we want to read its status. - try - { + try { sendCommand(read_command_); const auto response = readResponse(kReadResponseSize); @@ -285,14 +256,15 @@ void RobotiqGripperInterface::updateStatus() uint8_t gripper_status_byte = response[kResponseHeaderSize + kGripperStatusIndex]; // Activation status. - activation_status_ = ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; + activation_status_ = + ((gripper_status_byte & 0x01) == 0x00) ? ActivationStatus::RESET : ActivationStatus::ACTIVE; // Action status. - action_status_ = ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; + action_status_ = + ((gripper_status_byte & 0x08) == 0x00) ? ActionStatus::STOPPED : ActionStatus::MOVING; // Gripper status. - switch ((gripper_status_byte & 0x30) >> 4) - { + switch ((gripper_status_byte & 0x30) >> 4) { case 0x00: gripper_status_ = GripperStatus::RESET; break; @@ -305,8 +277,7 @@ void RobotiqGripperInterface::updateStatus() } // Object detection status. - switch ((gripper_status_byte & 0xC0) >> 6) - { + switch ((gripper_status_byte & 0xC0) >> 6) { case 0x00: object_detection_status_ = ObjectDetectionStatus::MOVING; break; @@ -323,13 +294,11 @@ void RobotiqGripperInterface::updateStatus() // Read the current gripper position. gripper_position_ = response[kResponseHeaderSize + kPositionIndex]; - } - catch (const serial::IOException& e) - { + } catch (const serial::IOException & e) { std::cerr << "Failed to update gripper status.\n"; - if (port_.isOpen()) - { - std::cerr << "Error caught while reading or writing to device. Connection is open, continuing to attempt " + if (port_.isOpen()) { + std::cerr << "Error caught while reading or writing to device. Connection is open, " + "continuing to attempt " "communication with gripper.\n ERROR: " << e.what(); return; From 801ce6177700ea8e4a38ec6e8dd3d8ded6dca2ce Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 30 Jun 2023 13:07:55 -0600 Subject: [PATCH 10/19] disable uncrustify: conflicts with clang format This disables uncrustify we use clang format Signed-off-by: Alex Moriarty --- robotiq_controllers/CMakeLists.txt | 5 +++++ robotiq_driver/CMakeLists.txt | 3 +++ 2 files changed, 8 insertions(+) diff --git a/robotiq_controllers/CMakeLists.txt b/robotiq_controllers/CMakeLists.txt index 57fa910..5e955f0 100644 --- a/robotiq_controllers/CMakeLists.txt +++ b/robotiq_controllers/CMakeLists.txt @@ -55,6 +55,11 @@ if(BUILD_TESTING) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) + + # the following skips uncrustify + # ament_uncrustify and ament_clang_format cannot both be satisfied + set(ament_cmake_uncrustify_FOUND TRUE) + ament_lint_auto_find_test_dependencies() endif() diff --git a/robotiq_driver/CMakeLists.txt b/robotiq_driver/CMakeLists.txt index b89d558..d18e5b7 100644 --- a/robotiq_driver/CMakeLists.txt +++ b/robotiq_driver/CMakeLists.txt @@ -83,6 +83,9 @@ if(BUILD_TESTING) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) + # the following skips uncrustify + # ament_uncrustify and ament_clang_format cannot both be satisfied + set(ament_cmake_uncrustify_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() From f139b2c54866fe18d1b04ed5e8b82d34d08ba670 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 30 Jun 2023 13:29:55 -0600 Subject: [PATCH 11/19] Add missing copywrite notices - fixes copywrite linter complaint that these were missing Signed-off-by: Alex Moriarty --- robotiq_driver/include/robotiq_driver/crc.hpp | 28 +++++++++++++++++++ robotiq_driver/src/crc.cpp | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/robotiq_driver/include/robotiq_driver/crc.hpp b/robotiq_driver/include/robotiq_driver/crc.hpp index f88617c..ca19d21 100644 --- a/robotiq_driver/include/robotiq_driver/crc.hpp +++ b/robotiq_driver/include/robotiq_driver/crc.hpp @@ -1,3 +1,31 @@ +// Copyright (c) 2022 PickNik, Inc. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the {copyright_holder} nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + #pragma once #include diff --git a/robotiq_driver/src/crc.cpp b/robotiq_driver/src/crc.cpp index 09b855d..f6a8563 100644 --- a/robotiq_driver/src/crc.cpp +++ b/robotiq_driver/src/crc.cpp @@ -1,3 +1,31 @@ +// Copyright (c) 2022 PickNik, Inc. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the {copyright_holder} nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + #include "robotiq_driver/crc.hpp" /* Table of CRC values for high–order byte */ From 4715e75c23d3ee8b4742466e2d8336c930cf8dae Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 30 Jun 2023 15:40:48 -0600 Subject: [PATCH 12/19] IWYU fixes Signed-off-by: Alex Moriarty --- robotiq_driver/include/robotiq_driver/hardware_interface.hpp | 1 + .../include/robotiq_driver/robotiq_gripper_interface.hpp | 3 ++- robotiq_driver/src/hardware_interface.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp index d763e40..06fd8e3 100644 --- a/robotiq_driver/include/robotiq_driver/hardware_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/hardware_interface.hpp @@ -29,6 +29,7 @@ #pragma once #include +#include #include #include #include diff --git a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp index 8389688..c6203e2 100644 --- a/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp +++ b/robotiq_driver/include/robotiq_driver/robotiq_gripper_interface.hpp @@ -41,7 +41,8 @@ class RobotiqGripperInterface { public: - RobotiqGripperInterface(const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); + explicit RobotiqGripperInterface( + const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09); /** * @brief Activates the gripper. diff --git a/robotiq_driver/src/hardware_interface.cpp b/robotiq_driver/src/hardware_interface.cpp index d14f72b..0f9aa8b 100644 --- a/robotiq_driver/src/hardware_interface.cpp +++ b/robotiq_driver/src/hardware_interface.cpp @@ -182,7 +182,8 @@ hardware_interface::CallbackReturn RobotiqGripperHardwareInterface::on_activate( const auto now = std::chrono::high_resolution_clock::now(); if (now - last_io > io_interval) { try { - // Re-activate the gripper (this can be used, for example, to re-run the auto-calibration). + // Re-activate the gripper + // (this can be used, for example, to re-run the auto-calibration). if (reactivate_gripper_async_cmd_.load()) { this->gripper_interface_->deactivateGripper(); this->gripper_interface_->activateGripper(); From f3216fef464b8a8c4dc13dbae3da487ec4480922 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Sun, 2 Jul 2023 19:59:12 -0600 Subject: [PATCH 13/19] flake8: apply fixes Signed-off-by: Alex Moriarty --- .../launch/robotiq_control.launch.py | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/robotiq_driver/launch/robotiq_control.launch.py b/robotiq_driver/launch/robotiq_control.launch.py index 2e0d196..b84dd1b 100644 --- a/robotiq_driver/launch/robotiq_control.launch.py +++ b/robotiq_driver/launch/robotiq_control.launch.py @@ -26,6 +26,8 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +import os + import launch from launch.substitutions import ( Command, @@ -34,51 +36,50 @@ PathJoinSubstitution, ) import launch_ros -import os def generate_launch_description(): description_pkg_share = launch_ros.substitutions.FindPackageShare( - package="robotiq_description" - ).find("robotiq_description") + package='robotiq_description' + ).find('robotiq_description') default_model_path = os.path.join( - description_pkg_share, "urdf", "robotiq_2f_85_gripper.urdf.xacro" + description_pkg_share, 'urdf', 'robotiq_2f_85_gripper.urdf.xacro' ) default_rviz_config_path = os.path.join( - description_pkg_share, "rviz", "view_urdf.rviz" + description_pkg_share, 'rviz', 'view_urdf.rviz' ) pkg_share = launch_ros.substitutions.FindPackageShare( - package="robotiq_driver" - ).find("robotiq_driver") + package='robotiq_driver' + ).find('robotiq_driver') args = [] args.append( launch.actions.DeclareLaunchArgument( - name="model", + name='model', default_value=default_model_path, - description="Absolute path to gripper URDF file", + description='Absolute path to gripper URDF file', ) ) args.append( launch.actions.DeclareLaunchArgument( - name="rvizconfig", + name='rvizconfig', default_value=default_rviz_config_path, - description="Absolute path to rviz config file", + description='Absolute path to rviz config file', ) ) robot_description_content = Command( [ - PathJoinSubstitution([FindExecutable(name="xacro")]), - " ", - LaunchConfiguration("model"), - " ", - "use_fake_hardware:=false", + PathJoinSubstitution([FindExecutable(name='xacro')]), + ' ', + LaunchConfiguration('model'), + ' ', + 'use_fake_hardware:=false', ] ) robot_description_param = { - "robot_description": launch_ros.parameter_descriptions.ParameterValue( + 'robot_description': launch_ros.parameter_descriptions.ParameterValue( robot_description_content, value_type=str ) } @@ -86,19 +87,19 @@ def generate_launch_description(): update_rate_config_file = PathJoinSubstitution( [ pkg_share, - "config", - "robotiq_update_rate.yaml", + 'config', + 'robotiq_update_rate.yaml', ] ) - controllers_file = "robotiq_controllers.yaml" + controllers_file = 'robotiq_controllers.yaml' initial_joint_controllers = PathJoinSubstitution( - [pkg_share, "config", controllers_file] + [pkg_share, 'config', controllers_file] ) control_node = launch_ros.actions.Node( - package="controller_manager", - executable="ros2_control_node", + package='controller_manager', + executable='ros2_control_node', parameters=[ robot_description_param, update_rate_config_file, @@ -107,39 +108,39 @@ def generate_launch_description(): ) robot_state_publisher_node = launch_ros.actions.Node( - package="robot_state_publisher", - executable="robot_state_publisher", + package='robot_state_publisher', + executable='robot_state_publisher', parameters=[robot_description_param], ) rviz_node = launch_ros.actions.Node( - package="rviz2", - executable="rviz2", - name="rviz2", - output="log", - arguments=["-d", LaunchConfiguration("rvizconfig")], + package='rviz2', + executable='rviz2', + name='rviz2', + output='log', + arguments=['-d', LaunchConfiguration('rvizconfig')], ) joint_state_broadcaster_spawner = launch_ros.actions.Node( - package="controller_manager", - executable="spawner", + package='controller_manager', + executable='spawner', arguments=[ - "joint_state_broadcaster", - "--controller-manager", - "/controller_manager", + 'joint_state_broadcaster', + '--controller-manager', + '/controller_manager', ], ) robotiq_gripper_controller_spawner = launch_ros.actions.Node( - package="controller_manager", - executable="spawner", - arguments=["robotiq_gripper_controller", "-c", "/controller_manager"], + package='controller_manager', + executable='spawner', + arguments=['robotiq_gripper_controller', '-c', '/controller_manager'], ) robotiq_activation_controller_spawner = launch_ros.actions.Node( - package="controller_manager", - executable="spawner", - arguments=["robotiq_activation_controller", "-c", "/controller_manager"], + package='controller_manager', + executable='spawner', + arguments=['robotiq_activation_controller', '-c', '/controller_manager'], ) nodes = [ From f0427d96981ece899d204c64adfc0aaa7ceeae5e Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Sun, 2 Jul 2023 23:56:27 -0300 Subject: [PATCH 14/19] Revert "flake8: apply fixes" This reverts commit f3216fef464b8a8c4dc13dbae3da487ec4480922. --- .../launch/robotiq_control.launch.py | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/robotiq_driver/launch/robotiq_control.launch.py b/robotiq_driver/launch/robotiq_control.launch.py index b84dd1b..2e0d196 100644 --- a/robotiq_driver/launch/robotiq_control.launch.py +++ b/robotiq_driver/launch/robotiq_control.launch.py @@ -26,8 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -import os - import launch from launch.substitutions import ( Command, @@ -36,50 +34,51 @@ PathJoinSubstitution, ) import launch_ros +import os def generate_launch_description(): description_pkg_share = launch_ros.substitutions.FindPackageShare( - package='robotiq_description' - ).find('robotiq_description') + package="robotiq_description" + ).find("robotiq_description") default_model_path = os.path.join( - description_pkg_share, 'urdf', 'robotiq_2f_85_gripper.urdf.xacro' + description_pkg_share, "urdf", "robotiq_2f_85_gripper.urdf.xacro" ) default_rviz_config_path = os.path.join( - description_pkg_share, 'rviz', 'view_urdf.rviz' + description_pkg_share, "rviz", "view_urdf.rviz" ) pkg_share = launch_ros.substitutions.FindPackageShare( - package='robotiq_driver' - ).find('robotiq_driver') + package="robotiq_driver" + ).find("robotiq_driver") args = [] args.append( launch.actions.DeclareLaunchArgument( - name='model', + name="model", default_value=default_model_path, - description='Absolute path to gripper URDF file', + description="Absolute path to gripper URDF file", ) ) args.append( launch.actions.DeclareLaunchArgument( - name='rvizconfig', + name="rvizconfig", default_value=default_rviz_config_path, - description='Absolute path to rviz config file', + description="Absolute path to rviz config file", ) ) robot_description_content = Command( [ - PathJoinSubstitution([FindExecutable(name='xacro')]), - ' ', - LaunchConfiguration('model'), - ' ', - 'use_fake_hardware:=false', + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + LaunchConfiguration("model"), + " ", + "use_fake_hardware:=false", ] ) robot_description_param = { - 'robot_description': launch_ros.parameter_descriptions.ParameterValue( + "robot_description": launch_ros.parameter_descriptions.ParameterValue( robot_description_content, value_type=str ) } @@ -87,19 +86,19 @@ def generate_launch_description(): update_rate_config_file = PathJoinSubstitution( [ pkg_share, - 'config', - 'robotiq_update_rate.yaml', + "config", + "robotiq_update_rate.yaml", ] ) - controllers_file = 'robotiq_controllers.yaml' + controllers_file = "robotiq_controllers.yaml" initial_joint_controllers = PathJoinSubstitution( - [pkg_share, 'config', controllers_file] + [pkg_share, "config", controllers_file] ) control_node = launch_ros.actions.Node( - package='controller_manager', - executable='ros2_control_node', + package="controller_manager", + executable="ros2_control_node", parameters=[ robot_description_param, update_rate_config_file, @@ -108,39 +107,39 @@ def generate_launch_description(): ) robot_state_publisher_node = launch_ros.actions.Node( - package='robot_state_publisher', - executable='robot_state_publisher', + package="robot_state_publisher", + executable="robot_state_publisher", parameters=[robot_description_param], ) rviz_node = launch_ros.actions.Node( - package='rviz2', - executable='rviz2', - name='rviz2', - output='log', - arguments=['-d', LaunchConfiguration('rvizconfig')], + package="rviz2", + executable="rviz2", + name="rviz2", + output="log", + arguments=["-d", LaunchConfiguration("rvizconfig")], ) joint_state_broadcaster_spawner = launch_ros.actions.Node( - package='controller_manager', - executable='spawner', + package="controller_manager", + executable="spawner", arguments=[ - 'joint_state_broadcaster', - '--controller-manager', - '/controller_manager', + "joint_state_broadcaster", + "--controller-manager", + "/controller_manager", ], ) robotiq_gripper_controller_spawner = launch_ros.actions.Node( - package='controller_manager', - executable='spawner', - arguments=['robotiq_gripper_controller', '-c', '/controller_manager'], + package="controller_manager", + executable="spawner", + arguments=["robotiq_gripper_controller", "-c", "/controller_manager"], ) robotiq_activation_controller_spawner = launch_ros.actions.Node( - package='controller_manager', - executable='spawner', - arguments=['robotiq_activation_controller', '-c', '/controller_manager'], + package="controller_manager", + executable="spawner", + arguments=["robotiq_activation_controller", "-c", "/controller_manager"], ) nodes = [ From 825b7d34c56cd2bd89a1c25a20912ca5955d11b4 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 3 Jul 2023 00:10:22 -0300 Subject: [PATCH 15/19] Add flake8 to pre-commit and add .flake8 ament_lint runs flake8 and flake8 and black are conflicting over " vs ' Signed-off-by: Alex Moriarty --- .flake8 | 10 ++++++++++ .pre-commit-config.yaml | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..14e35c3 --- /dev/null +++ b/.flake8 @@ -0,0 +1,10 @@ +[flake8] +max-line-length = 88 + +# Report all errors starting with E, F, W or C - or Bugbear's B590 rule, which is a "pragmatic" version of E501 (line too long) +select = E,F,W,C,B590 + +# Ignore W503 - Line break occurred before a binary operator - because this error is introduced by Black formatter. +# Ignore E203 - whitespace before ':' - because Black includes spaces in formatting slice expressions. +# Ignore E501 - line too long - in favor of B590, which is more forgiving of long strings and comments that would be silly to break up. +extend-ignore = W503, E203, E501 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ec4437d..c63eae3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,6 +36,12 @@ repos: hooks: - id: black + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 + hooks: + - id: flake8 + # configured in .flake8 file + - repo: https://github.com/codespell-project/codespell rev: v2.2.5 hooks: From eac5fccaf1f08338a808964186de1b69b384db7a Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 3 Jul 2023 00:36:09 -0300 Subject: [PATCH 16/19] fix linter include order Signed-off-by: Alex Moriarty --- robotiq_driver/src/gripper_interface_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/robotiq_driver/src/gripper_interface_test.cpp b/robotiq_driver/src/gripper_interface_test.cpp index 3c1c382..b77dc32 100644 --- a/robotiq_driver/src/gripper_interface_test.cpp +++ b/robotiq_driver/src/gripper_interface_test.cpp @@ -27,9 +27,10 @@ // POSSIBILITY OF SUCH DAMAGE. #include -#include #include +#include + constexpr auto kComPort = "/dev/ttyUSB0"; constexpr auto kSlaveID = 0x09; From 199a0d459df138581e3814bd99ebe6f1f2ab296a Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 3 Jul 2023 00:54:52 -0300 Subject: [PATCH 17/19] clang/cpplint include " vs < With < clang-format will re-order When re-ordered cpplint complains Signed-off-by: Alex Moriarty --- robotiq_driver/src/gripper_interface_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robotiq_driver/src/gripper_interface_test.cpp b/robotiq_driver/src/gripper_interface_test.cpp index b77dc32..c93a8de 100644 --- a/robotiq_driver/src/gripper_interface_test.cpp +++ b/robotiq_driver/src/gripper_interface_test.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include "robotiq_driver/robotiq_gripper_interface.hpp" constexpr auto kComPort = "/dev/ttyUSB0"; constexpr auto kSlaveID = 0x09; From 3b3f3685db5e7f229475b6a8b129abd69208a65f Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 3 Jul 2023 01:43:06 -0300 Subject: [PATCH 18/19] disable ament_flake8 flake8 via pre-commit - disable ament_flake8, flake8 via pre-commit reads .flake8 config - ament_flake8 in ros-tooling didn't read .flake8 - flake8 and black will conflit over single vs double quotes Signed-off-by: Alex Moriarty --- robotiq_driver/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/robotiq_driver/CMakeLists.txt b/robotiq_driver/CMakeLists.txt index d18e5b7..bda81ea 100644 --- a/robotiq_driver/CMakeLists.txt +++ b/robotiq_driver/CMakeLists.txt @@ -86,6 +86,10 @@ if(BUILD_TESTING) # the following skips uncrustify # ament_uncrustify and ament_clang_format cannot both be satisfied set(ament_cmake_uncrustify_FOUND TRUE) + # the following skips ament_flake8 + # ament_flake8 and black fight over double or single quotes + # flake8 is run via pre-commit with a .flake8 configuration file + set(ament_cmake_flake8_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() From 437228ff8691100a0b6cf15faa2a6c0f86d13114 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Mon, 3 Jul 2023 19:16:06 -0300 Subject: [PATCH 19/19] run pre-commit format check on push to main --- .github/workflows/ci-format.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-format.yml b/.github/workflows/ci-format.yml index 2d02865..3d60336 100644 --- a/.github/workflows/ci-format.yml +++ b/.github/workflows/ci-format.yml @@ -6,6 +6,9 @@ name: Format on: workflow_dispatch: pull_request: + push: + branches: + - main jobs: pre-commit: