Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor driver library to follow patterns from PickNikRobotics/ros2_epick_gripper #34

Merged
merged 48 commits into from
Oct 31, 2023

Conversation

kineticsystem
Copy link
Contributor

@kineticsystem kineticsystem commented Sep 5, 2023

The monolithic code has been broken apart to introduce tests.

The serial connection creation has been moved from the driver constructor to the hardware interface configure method.

A lot of code has been refactored with the intention of bringing the Epick gripper into this same repository and reusing some common code.

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #34 (f5d7b7a) into main (743d20f) will increase coverage by 20.77%.
Report is 6 commits behind head on main.
The diff coverage is 21.34%.

❗ Current head f5d7b7a differs from pull request most recent head 4c3fd18. Consider uploading reports for the commit 4c3fd18 to get more accurate results

@@            Coverage Diff             @@
##            main      #34       +/-   ##
==========================================
+ Coverage   0.00%   20.77%   +20.77%     
==========================================
  Files          5       20       +15     
  Lines        352      597      +245     
  Branches       0      240      +240     
==========================================
+ Hits           0      124      +124     
+ Misses       352      341       -11     
- Partials       0      132      +132     
Flag Coverage Δ
unittests 20.77% <21.34%> (+20.77%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../include/robotiq_driver/default_driver_factory.hpp 100.00% <100.00%> (ø)
.../include/robotiq_driver/default_serial_factory.hpp 100.00% <100.00%> (ø)
robotiq_driver/include/robotiq_driver/serial.hpp 100.00% <100.00%> (ø)
robotiq_driver/src/crc_utils.cpp 100.00% <100.00%> (ø)
.../tests/test_robotiq_gripper_hardware_interface.cpp 33.33% <33.33%> (ø)
robotiq_driver/tests/mock/mock_driver.hpp 40.00% <40.00%> (ø)
robotiq_driver/tests/test_crc_utils.cpp 14.28% <14.28%> (ø)
robotiq_driver/tests/test_data_utils.cpp 45.45% <45.45%> (ø)
...driver/include/robotiq_driver/driver_exception.hpp 0.00% <0.00%> (ø)
robotiq_driver/tests/mock/mock_serial.hpp 0.00% <0.00%> (ø)
... and 10 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)
find_package(ament_lint_auto REQUIRED)
find_package(ros2_control_test_assets REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be added to the package.xml as a <test_depend>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

@moriarty
Copy link
Contributor

moriarty commented Sep 5, 2023

From the logs it looks like the test assets were installed, but that file still not found..

https://github.com/PickNikRobotics/ros2_robotiq_gripper/actions/runs/6084786368/job/16507440934

2023-09-05T12:51:27.9022317Z �[1mexecuting command [apt-get install -y -qq ros-rolling-ament-cmake-copyright]�[0m
2023-09-05T12:51:27.9022908Z �[1mexecuting command [apt-get install -y -qq ros-rolling-ament-cmake-lint-cmake]�[0m
2023-09-05T12:51:27.9023473Z �[1mexecuting command [apt-get install -y -qq ros-rolling-ament-cmake-gmock]�[0m
2023-09-05T12:51:27.9024043Z �[1mexecuting command [apt-get install -y -qq ros-rolling-ros2-control-test-assets]�[0m
2023-09-05T12:51:27.9024623Z Setting up ros-rolling-ros2-control-test-assets (3.16.0-1jammy.20230711.194957) ...
2023-09-05T12:51:27.9025474Z �[1mexecuting command [apt-get install -y -qq ros-rolling-gripper-controllers]�[0m
2023-09-05T12:51:27.9025954Z Setting up python3-typeguard (2.2.2-1.1) ...
2023-09-05T12:51:27.9026404Z Setting up ros-rolling-tl-expected (1.0.2-3jammy.20230711.195032) ...
2023-09-05T12:51:27.9026836Z Setting up python3-markupsafe (2.0.1-2build1) ...
2023-09-05T12:51:27.9027224Z Setting up python3-tz (2022.1-1ubuntu0.22.04.1) ...
2023-09-05T12:51:27.9027645Z Setting up python-babel-localedata (2.8.0+dfsg.1-7) ...
2023-09-05T12:51:27.9028097Z Setting up ros-rolling-tcb-span (1.0.2-3jammy.20230711.195007) ...
2023-09-05T12:51:27.9028578Z Setting up ros-rolling-realtime-tools (2.5.0-2jammy.20230711.230518) ...
2023-09-05T12:51:27.9029006Z Setting up libelf-dev:amd64 (0.186-1build1) ...
2023-09-05T12:51:27.9029374Z Setting up liblzma-dev:amd64 (5.2.5-2ubuntu1) ...
2023-09-05T12:51:27.9029756Z Setting up python3-babel (2.8.0+dfsg.1-7) ...
2023-09-05T12:51:27.9030202Z Setting up ros-rolling-control-toolbox (3.1.0-1jammy.20230711.231139) ...
2023-09-05T12:51:27.9030620Z Setting up libdw-dev:amd64 (0.186-1build1) ...
2023-09-05T12:51:40.8430488Z Setting up ros-rolling-rsl (0.2.2-1jammy.20230711.232011) ...
2023-09-05T12:51:40.8430952Z Setting up python3-jinja2 (3.0.3-1) ...
2023-09-05T12:51:40.8441174Z Setting up ros-rolling-parameter-traits (0.3.3-1jammy.20230711.232510) ...
2023-09-05T12:51:40.8442021Z Setting up ros-rolling-backward-ros (1.0.2-4jammy.20230711.194802) ...
2023-09-05T12:51:40.8442572Z Setting up ros-rolling-generate-parameter-library-py (0.3.3-1jammy.20230711.194824) ...
2023-09-05T12:51:40.8443177Z Setting up ros-rolling-generate-parameter-library (0.3.3-1jammy.20230711.232811) ...
2023-09-05T12:51:40.8443734Z Setting up ros-rolling-gripper-controllers (3.12.0-1jammy.20230718.185445) ...
2023-09-05T12:51:40.8444330Z �[1mexecuting command [apt-get install -y -qq ros-rolling-joint-state-broadcaster]�[0m
2023-09-05T12:51:40.8444912Z Setting up ros-rolling-joint-state-broadcaster (3.12.0-1jammy.20230718.185413) ...
2023-09-05T12:51:40.8445798Z ##[endgroup]
2023-09-05T12:51:40.8446214Z �[32m'install_target_dependencies' returned with code '0' after 2 min 3 sec�[0m
2023-09-05T12:51:40.8446586Z 
2023-09-05T12:51:40.8448241Z ##[group]�[34mbuild_target_workspace�[0m
2023-09-05T12:51:40.8448434Z 
2023-09-05T12:51:40.8449251Z �[1m$ ( source /home/runner/work/ros2_robotiq_gripper/ros2_robotiq_gripper/.work/upstream_ws/install/setup.bash && cd /home/runner/work/ros2_robotiq_gripper/ros2_robotiq_gripper/.work/target_ws && colcon build --event-handlers desktop_notification- status- terminal_title-; )�[0m
2023-09-05T12:51:40.8449890Z Starting >>> robotiq_controllers
2023-09-05T12:51:40.8450174Z Starting >>> robotiq_description
2023-09-05T12:51:40.8450476Z Finished <<< robotiq_description [0.81s]
2023-09-05T12:51:40.8454764Z Starting >>> robotiq_driver
2023-09-05T12:51:40.8455270Z Finished <<< robotiq_controllers [2.93s]
2023-09-05T12:51:40.8455640Z --- stderr: robotiq_driver
2023-09-05T12:51:40.8456545Z �[01m�[K/home/runner/work/ros2_robotiq_gripper/ros2_robotiq_gripper/.work/target_ws/src/ros2_robotiq_gripper/robotiq_driver/tests/test_robotiq_gripper_hardware_interface.cpp:41:10:�[m�[K �[01;31m�[Kfatal error: �[m�[Kros2_control_test_assets/components_urdfs.hpp: No such file or directory
2023-09-05T12:51:40.8457502Z    41 | #include �[01;31m�[K<ros2_control_test_assets/components_urdfs.hpp>�[m�[K
2023-09-05T12:51:40.8457956Z       |          �[01;31m�[K^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[m�[K

Copy link
Contributor

@moriarty moriarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge PR so I just took a first pass and left some comments.

IIRC we shouldn't set the VERSION of a ROS package in the CMakeLists.txt as this is set in the package.xml and it should match, with the version in the package.xml being the source of truth

.github/workflows/prerelease-check.yml Outdated Show resolved Hide resolved
.github/workflows/prerelease-check.yml Outdated Show resolved Hide resolved
.github/workflows/prerelease-check.yml Outdated Show resolved Hide resolved
.github/workflows/prerelease-check.yml Outdated Show resolved Hide resolved
.github/workflows/prerelease-check.yml Outdated Show resolved Hide resolved
Comment on lines +25 to +27
- humble
- iron
- master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be an old/outdated file or one that was autogenerated or accidentally copied while setting up this repo.

This repo doesn't have humble/iron/master branches only main

@@ -13,6 +13,10 @@
<ros2_control name="${name}" type="system">
<!-- Plugins -->
<hardware>

<!-- Set use_dummy to true to connect to a dummy driver for testing purposes. -->
<param name="use_dummy">false</param>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be use_mock I thought there was a discussion to unify the language in another project

robotiq_driver/CMakeLists.txt Outdated Show resolved Hide resolved
@kineticsystem kineticsystem marked this pull request as ready for review September 8, 2023 21:24
Copy link
Contributor

@moriarty moriarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope github saves my files viewed when i finish this review and leave the comments so far.

with:
distribution: rolling
linter: cpplint
arguments: "--linelength=121 --filter=-whitespace/newline"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this 121 ? that seems strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in the clang formatter. Sometimes a line is cut at 121 and this causes this linter to fail.
I experienced this bug in one single line of code: hardware_interface.cpp line 73.
If you have any suggestions let me know, maybe I'm missing something.

@@ -10,10 +10,11 @@ find_package(ament_cmake REQUIRED)

install(
DIRECTORY
urdf
config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the controller configuration being moved from the robotiq_driver/config -> robotiq_description/config ?

And why is the controller the launch for the controllers also being moved into the robotiq_description?

I think the description should have only the urdf but now that I look at the package.xml in robotiq_description I see that we've already messed up the dependencies and seperation a bit because the description depends on rviz2 which it should not.

I need to think about this.

What I want to avoid is the driver itself depending on any gui or simulation dependencies... which already seems to not be the case 😞 I didn't notice this when originally taking over this repo and opening it... but it would be great if someone could install the driver without needing to install rviz.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in my opinion, the driver (robotiq_driver) should not know who controls it, that's why I moved the controller config out of it.

On the other hand, the description package (robotiq_description) which contains the robot launch file should know both about the driver and the controller (robotiq_controllers), because you want to use it to start a working robot.

I also think that the urdf in the description package should be of a robot example, not a real robot which may differ a lot from the example. Because the description package knows about the robot and contains the launch file, it seemed natural to add a dependency to rviz too.

@@ -67,6 +64,11 @@ def generate_launch_description():
description="Absolute path to rviz config file",
)
)
args.append(
launch.actions.DeclareLaunchArgument(
name="launch_rviz", default_value="false", description="Launch RViz?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my previous comment maybe we should remove this, or stick it somewhere else so that rviz is not a transitive dependency of the driver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find an agreement or check with somebody else in the team. To me, the driver is the one in the robotiq_driver package. The robotiq_description describes how to use the driver.

Comment on lines +34 to +55
include/robotiq_driver/fake/fake_driver.hpp
include/robotiq_driver/crc_utils.hpp
include/robotiq_driver/data_utils.hpp
include/robotiq_driver/default_driver.hpp
include/robotiq_driver/default_driver_factory.hpp
include/robotiq_driver/default_serial.hpp
include/robotiq_driver/default_serial_factory.hpp
include/robotiq_driver/driver.hpp
include/robotiq_driver/driver_exception.hpp
include/robotiq_driver/driver_factory.hpp
include/robotiq_driver/hardware_interface.hpp
include/robotiq_driver/serial.hpp
include/robotiq_driver/serial_factory.hpp
include/robotiq_driver/visibility_control.hpp
src/crc_utils.cpp
src/data_utils.cpp
src/hardware_interface.cpp
src/robotiq_gripper_interface.cpp
src/default_driver.cpp
src/default_driver_factory.cpp
src/fake/fake_driver.cpp
src/default_serial.cpp
src/default_serial_factory.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it the files listed here are the meat of this PR and the rest of the changes in the PR are actually minor formatting changes and style changes but it's very hard to tell with such a large PR

Copy link
Contributor Author

@kineticsystem kineticsystem Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't changed the logic of how the driver works, I broke it apart into smaller pieces to allow testing without being connected to the hardware. Originally it was a monolithic project with no tests and with the hard requirement of having hardware at hand.

I intentionally followed the structure of the Epick Gripper so that later we can merge the two drivers into the same repo and extract common code. For example, all the serial communication is common to both.

I definitely made the mistake of formatting the code later which makes the PR hard to read.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this was just a note to self when I was reviewing I wanted to check the main changes parts in more detain.

I definitely agree we should get he Epick Grippper merged into one repo that would be great.

Comment on lines +43 to +46
* <!-- Set use_dummy to true to connect to a dummy driver. -->
* <param name="use_dummy">true</param>
*/
class FakeDriver : public Driver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there is a mismatch between the param an the thing Fake vs Dummy. I think Fake should be used instead of Dummy but you also have a tests/mock/mock_driver.hpp so is this a Fake or a Mock driver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the point of view of the client, the HardwareInterface, a Fake is a simplified replacement for the real thing. A Mock is a class in which I want to test its expectations.

"use_fake" would be probably more accurate. The reason I used "use_dummy" is because it is used in the Dynamixel ROS2 drivers: https://github.com/dynamixel-community/dynamixel_hardware/blob/d84511db57094e3aeb5c09181517649e40172a67/dynamixel_hardware/include/dynamixel_hardware/dynamixel_hardware.hpp#L106

<package format="3">
<name>robotiq_hardware_tests</name>
<version>0.0.1</version>
<description>ROS2 driver for the Robotiq gripper.</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this package actually do? who is the intended user? should it be robotiq_hardware_utils is it simple commands for checking that hardware is functioning as expected? or is it tests that don't need to be distributed via a ros package but could just be internal to the robotiq_driver package for development but not packages and installed for end users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are commands (to be run in the terminal) to check that the hardware is properly connected and working as expected.
If you think "robotiq_hardware_utils" is more appropriate I do not mind renaming it.

@schornakj schornakj changed the title Refactoring for testability. Refactor driver library to follow patterns from PickNikRobotics/ros2_epick_gripper Oct 11, 2023
@kineticsystem kineticsystem enabled auto-merge (squash) October 11, 2023 19:37
# See https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html

cmake_minimum_required(VERSION 3.8)
project(robotiq_hardware_tests VERSION 0.0.1 LANGUAGES CXX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This VERSION number should be set in the package.xml and IIRC it should match the other versions else the ros release tools complain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@kineticsystem kineticsystem merged commit 29ce398 into main Oct 31, 2023
@delete-merged-branch delete-merged-branch bot deleted the pr-refactoring branch October 31, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants