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

Drop PyKDL dependency in tf2_geometry_msgs #509

Merged
merged 19 commits into from
Mar 21, 2022
Merged

Conversation

Flova
Copy link
Contributor

@Flova Flova commented Mar 10, 2022

Currently, the python tf2_geometry_msgsare excluded because of the PyKDL/orocos issue.
This pull request drops the dependency all together and replaces the transformations with ones done in pure NumPy.

Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
@clalancette
Copy link
Contributor

I'm torn on whether we should take this. On the plus side, this gets rid of the PyKDL dependency which has been nagging this package for a long time, and makes this package available to users. On the negative side, we are hoping to get PyKDL into Humble (via ros2/orocos_kdl_vendor#1), and this ends up dropping the public API transform_to_kdl.

Here are some options I can see for this:

  1. Wait for Add vendor package files for orocos_kdl orocos_kdl_vendor#1 to land, and then just keep the existing code as-is. This assumes we get PyKDL in before Humble.
  2. Take this patch as it stands (after review, etc), knowing that we lose transform_to_kdl. We can always add transform_to_kdl back in later by re-introducing a dependency on PyKDL.
  3. Wait to see if we actually get PyKDL into Humble. If we do, then close this PR and just use PyKDL. If we don't, then take this PR and follow up later when we do get PyKDL.

There may be other options.

@ros2/team @Flova Thoughts?

Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
@Flova
Copy link
Contributor Author

Flova commented Mar 10, 2022

On the negative side, we are hoping to get PyKDL into Humble (via ros2/orocos_kdl_vendor#1), and this ends up dropping the public API transform_to_kdl.

I understand the implications and that this is a tough choice. I also appreciate the efforts regarding PyKDL/orocos_kdl which I am following for some time now. As all introduced methods are private, I would see no issue except the administrative overhead, in releasing this fix as it is for now (with your feedback + some testing) and replacing it with the PyKDL implementation later on if it is available again. I am not that worried about the transform_to_kdl method as it is currently not available like the rest of this module, so making a subset of the features available for now would still help. I personally think that this package is quite essential for many people who migrate their python tf2 code to ros2. I therefore would prefer the second option you proposed.

I would suggest opening a new PR to merge things like the improved typing/docstrings of the existing functions as well as the fixes applied to the tests, if we choose to close this one.

@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

Any other thought on this?

@clalancette
Copy link
Contributor

I think we can go ahead here and review this. We can always add back the transform_to_kdl API later on, when we know for sure that we have PyKDL available. I'll go ahead and do a review.

@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

Nice, thank you :)

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

I've left a few minor things to change. Looks good overall; once those things are fixed, I'll fire up CI on it.

tf2_geometry_msgs/CMakeLists.txt Show resolved Hide resolved
tf2_geometry_msgs/package.xml Show resolved Hide resolved
Flova and others added 8 commits March 15, 2022 16:36
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>

Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Florian Vahl <git@flova.de>

Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Florian Vahl <git@flova.de>

Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

I think I fixed everything. Let me know if there is something left I overlooked or if I should do something different.

@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

This PR closes #360, right?

@clalancette
Copy link
Contributor

This PR closes #360, right?

Yeah, it should. I think it will also close one or two open issues, but I'll have to check on that.

@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

I also tested in 20.04, but I guess my NumPy version was replaced/overlaid with a newer one by installing some pip package that depended on it. https://packages.ubuntu.com/focal/python3-numpy shows that the current version is 1.17 and Typing was introduced in 1.20. Replacing the more general npt.ArrayLike with np.ndarray should be no problem for this package, as it is only used internally with objects of type np.ndarray.
This also effects #507.

@Flova
Copy link
Contributor Author

Flova commented Mar 15, 2022

I will address these flake8 errors, but my flake8 checks passed. Is there a config I don't know about for ROS2 and flake8 which is not applied automatically? Or is it because of the first point you mentioned?

Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
Signed-off-by: Florian Vahl <git@flova.de>
@Flova
Copy link
Contributor Author

Flova commented Mar 16, 2022

I fixed the first and third issue you observed @clalancette, but the flake8 one seems kind of weird. The first point regarding the order of the imported elements from geometry_msgs.msg makes sense, but the second one suggests that the imports should be ordered like this if I understand it correctly:

import numpy as np
from geometry_msgs.msg import (PointStamped, Pose, PoseStamped,
                               PoseWithCovarianceStamped, TransformStamped,
                               Vector3Stamped)
import tf2_ros

This seems of as normally the from * imports come after it. It is also strange, that I get this output from the tests regarding flake8 for both issues you described:

6: Test timeout computed to be: 60
6: -- run_test.py: invoking following command in '/home/florian/colcon_ws/src/geometry2-1/tf2_geometry_msgs':
6:  - /opt/ros/rolling/bin/ament_flake8 --xunit-file /home/florian/colcon_ws/build/tf2_geometry_msgs/test_results/tf2_geometry_msgs/flake8.xunit.xml
6:                                              
6: 3 files checked
6: No problems found
6: 
6: Checked files:
6: 
6: * ./src/tf2_geometry_msgs/tf2_geometry_msgs.py
6: * ./src/tf2_geometry_msgs/__init__.py
6: * ./test/test_tf2_geometry_msgs.py
6: -- run_test.py: return code 0
6: -- run_test.py: verify result file '/home/florian/colcon_ws/build/tf2_geometry_msgs/test_results/tf2_geometry_msgs/flake8.xunit.xml'
 6/10 Test  #6: flake8 ...........................   Passed    0.76 sec

Do you use a special flake8 config? From the output, it seems like you have built the ament_flake8 package yourself (Idk about your setup, so this could be normal).

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor

Unfortunately flake8 is a bit annoying. Basically it runs with the flake8 plugins you currently have installed locally. The practical upshot of this is that you happen to have one missing, it will just silently ignore it.

As for the weird import order, yeah, I don't always agree with how flake8 orders things. But it's easier to just conform to it. I ended up fixing it with the latest commit.

While testing, I found a small bug in tf2_ros_py, where it isn't depending on sensor_msgs properly. That's now fixed in here as well. With all of that done, I'm happy with this so I'll do one more pass and then run CI on it.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@Flova
Copy link
Contributor Author

Flova commented Mar 21, 2022

Nice, the CI seem to look good.

@clalancette clalancette merged commit 6b18a40 into ros2:ros2 Mar 21, 2022
@Flova Flova deleted the no_pykdl branch March 21, 2022 17:11
@dawsonc
Copy link

dawsonc commented Jun 3, 2022

Hi!

Is there a timeline for getting these changes into a release? Currently rosdep does not install the python bindings for tf2_geometry_msgs in foxy.

Thanks!

@clalancette
Copy link
Contributor

Is there a timeline for getting these changes into a release? Currently rosdep does not install the python bindings for tf2_geometry_msgs in foxy.

It is currently available in Humble and Rolling. It's probably possible to backport to Foxy, though it might be a bit tricky; we had to do a couple of additional patches on top of this one to get it working.

What I'll do here is to ask the bot to try to backport it. That said, I'm unlikely to have time myself to fix it up, so it would be appreciated if you can fix any conflicts that arise, test it out, and generally make sure it will work in Foxy.

@clalancette
Copy link
Contributor

@Mergifyio backport foxy galactic

mergify bot pushed a commit that referenced this pull request Jun 3, 2022
* Drop PyKDL dependency

Signed-off-by: Florian Vahl <git@flova.de>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 6b18a40)

# Conflicts:
#	tf2_geometry_msgs/CMakeLists.txt
#	tf2_geometry_msgs/package.xml
#	tf2_geometry_msgs/src/tf2_geometry_msgs/tf2_geometry_msgs.py
#	tf2_geometry_msgs/test/test_tf2_geometry_msgs.py
#	tf2_ros_py/package.xml
mergify bot pushed a commit that referenced this pull request Jun 3, 2022
* Drop PyKDL dependency

Signed-off-by: Florian Vahl <git@flova.de>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 6b18a40)

# Conflicts:
#	tf2_geometry_msgs/CMakeLists.txt
#	tf2_geometry_msgs/package.xml
#	tf2_geometry_msgs/src/tf2_geometry_msgs/tf2_geometry_msgs.py
#	tf2_geometry_msgs/test/test_tf2_geometry_msgs.py
@mergify
Copy link
Contributor

mergify bot commented Jun 3, 2022

backport foxy galactic

✅ Backports have been created

@dawsonc
Copy link

dawsonc commented Jun 3, 2022

@clalancette Thank you! I'll take a look at testing the foxy backport and move discussion over to #530 #532 for foxy and #533 for galactic (since I don't think I have write access to the branch created by mergify).

clalancette pushed a commit that referenced this pull request Jul 9, 2022
#533)

* Drop PyKDL dependency in tf2_geometry_msgs (#509)

* Drop PyKDL dependency

Signed-off-by: Florian Vahl <git@flova.de>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 6b18a40)

# Conflicts:
#	tf2_geometry_msgs/CMakeLists.txt
#	tf2_geometry_msgs/package.xml
#	tf2_geometry_msgs/src/tf2_geometry_msgs/tf2_geometry_msgs.py
#	tf2_geometry_msgs/test/test_tf2_geometry_msgs.py

* Fix merge conflicts

Co-authored-by: Florian Vahl <florian@flova.de>
clalancette pushed a commit that referenced this pull request Oct 4, 2022
)

* Drop PyKDL dependency in tf2_geometry_msgs (#509)

* Drop PyKDL dependency

Signed-off-by: Florian Vahl <git@flova.de>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 6b18a40)

# Conflicts:
#	tf2_geometry_msgs/CMakeLists.txt
#	tf2_geometry_msgs/package.xml
#	tf2_geometry_msgs/src/tf2_geometry_msgs/tf2_geometry_msgs.py
#	tf2_geometry_msgs/test/test_tf2_geometry_msgs.py
#	tf2_ros_py/package.xml

* Clean up merge conflicts. Builds and tests pass!

Co-authored-by: Florian Vahl <florian@flova.de>
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