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

replaced eigen_conversions with tf2_eigen in moveit_core #2472

Merged
merged 15 commits into from
Feb 17, 2021
Merged

replaced eigen_conversions with tf2_eigen in moveit_core #2472

merged 15 commits into from
Feb 17, 2021

Conversation

petkovich
Copy link
Contributor

@petkovich petkovich commented Jan 5, 2021

Description

Followed the tutorial and replaced eigen_conversions with tf2_eigen

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@welcome
Copy link

welcome bot commented Jan 5, 2021

Thanks for helping in improving MoveIt and open source robotics!

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this initial work. Could you, please, continue replacing eigen_conversions in all remaining packages as well (not only moveit_core)? I just pushed another commit removing eigen_conversions from various cmake files and package.xml (but did not yet adapted the actual conversion routines).
Note, that there are also many eigen_conversions in moveit_planners/pilz_industrial_motion_planner*.

@codecov
Copy link

codecov bot commented Jan 5, 2021

Codecov Report

Merging #2472 (7c33bd0) into master (ea50801) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2472      +/-   ##
==========================================
- Coverage   60.30%   60.26%   -0.03%     
==========================================
  Files         351      351              
  Lines       26471    26475       +4     
==========================================
- Hits        15960    15953       -7     
- Misses      10511    10522      +11     
Impacted Files Coverage Δ
...anner/src/trajectory_blender_transition_window.cpp 100.00% <ø> (ø)
...strial_motion_planner/src/trajectory_generator.cpp 100.00% <ø> (ø)
..._motion_planner_testutils/cartesianconfiguration.h 44.45% <ø> (ø)
moveit_core/kinematic_constraints/src/utils.cpp 30.04% <100.00%> (-0.50%) ⬇️
...strial_motion_planner/src/trajectory_functions.cpp 100.00% <100.00%> (ø)
...l_motion_planner/src/trajectory_generator_circ.cpp 100.00% <100.00%> (ø)
...al_motion_planner/src/trajectory_generator_lin.cpp 100.00% <100.00%> (ø)
...al_motion_planner/src/trajectory_generator_ptp.cpp 100.00% <100.00%> (ø)
...n_planner_testutils/src/cartesianconfiguration.cpp 63.83% <100.00%> (+1.33%) ⬆️
moveit_core/robot_model/src/joint_model_group.cpp 63.08% <0.00%> (-2.46%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4755105...24475ec. Read the comment docs.

@gleichdick
Copy link
Contributor

Just for the record, this belongs to a first-timer-only issue I opened (#2437).
@petkovich thank you for contributing to this project. If you want to continue to replace eigen_conversions and friends (like Robert proposed) and have any questions, please don't hesitate to ask for help. I'm also happy to provide further patches for you to apply, if needed.

Basically, all methods in the tf namespace (quaternionEigenToMsg(), poseMsgToEigen(), transformKDLToEigen(), transformEigenToKDL(), vectorEigenToKDL(), poseMsgToEigen(), ...) have to be replaced. You can use tf2::convert() (defined in <tf2/convert.h>) for all of these functions. It takes two parameters, the first is the source and the second is the destination of the conversion. For all Eigen and/or KDL datatypes, you also have to include <tf2_eigen/tf2_eigen.h> resp. <tf2_kdl/tf2_kdl.h>. Please also make sure that the packages tf2_eigen and/or tf2_kdl are included in both package.xml and CMakeLists.txt.

So far, I found these methods in these files:

moveit_kinematics/ikfast_kinematics_plugin/templates/ikfast61_moveit_plugin_template.cpp
moveit_planners/ompl/ompl_interface/test/test_planning_context_manager.cpp
moveit_planners/pilz_industrial_motion_planner/src/trajectory_functions.cpp
moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_circ.cpp
moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_lin.cpp
moveit_planners/pilz_industrial_motion_planner_testutils/src/cartesianconfiguration.cpp
moveit_ros/planning_interface/test/move_group_interface_cpp_test.cpp
moveit_ros/planning_interface/test/subframes_test.cpp

I just used grep -r tf:: <path to moveit sources>.
Again, I'm happy to answer any questions and to supply further patches, if requested.

@petkovich
Copy link
Contributor Author

No problem, @gleichdick. Are there any functionality tests or we just consider passed build as proof of well done migration? Also, is it convention to commit changes to the pull request multiple times (as one would on a normal coding project) or should it be done only once, when the whole issue is solved?

@rhaschke
Copy link
Contributor

rhaschke commented Jan 6, 2021

Thanks, for handling the remaining conversions as well. It's no problem, to push as many commits as you like to a PR branch.

@petkovich
Copy link
Contributor Author

petkovich commented Jan 16, 2021

I have replaced
tf::transformKDLToEigen(trajectory.Pos(*time_iter), pose_sample);
with
tf2::convert(trajectory.Pos(*time_iter), pose_sample);
in moveit/moveit_planners/pilz_industrial_motion_planner/src/trajectory_functions.cpp

As result, my build fails with:

In file included from /opt/ros/noetic/include/tf2/convert.h:39,
from /home/tomislav/ws_moveit/src/moveit/moveit_planners/pilz_industrial_motion_planner/src/trajectory_functions.cpp:39:
/opt/ros/noetic/include/tf2/impl/convert.h: In instantiation of ‘static void tf2::impl::Converter<IS_MESSAGE_A, IS_MESSAGE_B>::convert(const A&, B&) [with A = KDL::Frame; B = Eigen::Transform<double, 3, 1>; bool IS_MESSAGE_A = false; bool IS_MESSAGE_B = false]’:
/opt/ros/noetic/include/tf2/convert.h:116:113: required from ‘void tf2::convert(const A&, B&) [with A = KDL::Frame; B = Eigen::Transform<double, 3, 1>]’
/home/tomislav/ws_moveit/src/moveit/moveit_planners/pilz_industrial_motion_planner/src/trajectory_functions.cpp:228:57: required from here
/opt/ros/noetic/include/tf2/impl/convert.h:83:16: error: ‘toMsg’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
83 | fromMsg(toMsg(a), b);
| ~~~~~^~~

Do you know what could be the cause of missed definition? As far as I can see, I have included all the relevant files as in moveit_planners/pilz_industrial_motion_planner_testutils/include/pilz_industrial_motion_planner_testutils/cartesianconfiguration.h, where tf2::convert raises no issue?
I have pushed my code in "toMsg_error" branch I hope that is ok?

@gleichdick
Copy link
Contributor

Could you try to replace the tf2::convert() function with an explicit call to the conversion functions, this:

const geometry_msgs::Pose pose_msg = tf2::toMsg(trajectory.Pos(*time_iter));
tf2::fromMsg(pose_msg, pose_sample);

In this case, tf2::convert() sees that both parameters are not ROS message types and tries to deduce a message type (which is geometry_msgs::Pose). Currently, there are some issues in the tf2 package, AFAIK because of the mix of templated and non-templated functions and the header inclusion order.
PS. In general it's almost always a good idea to make separate branches, especially for helping other people reproduce (or fix) an error 😄

PPS. One small nitpick: In the header cartesianconfiguration.h, nothing (no types, no functions) from the tf2_eigen package is used so far. Only in the corresponding translation unit (cartesianconfiguration.cpp). To speed up compilation time and to tidy up the header file a bit, it'd be a good idea to move the #include <tf2_eigen/tf2_eigen.h> statement from the header into the .src file.

@petkovich
Copy link
Contributor Author

@gleichdick thank you for your help. If I am not wrong, all tf:: occurrences are now replaced as well as eigen_conversions dependancies.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this work. Let's see whether CI will be satisfied now.

Comment on lines 23 to 24
tf2
tf2_eigen
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure tf2_eigen is required for building? This PR, only comprises changes to the testing code of OMPL.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think tf2_ros is also not necessary

@@ -8,7 +8,6 @@ add_definitions(-Wextra)
add_definitions(-Wno-unused-parameter)

find_package(catkin REQUIRED COMPONENTS
eigen_conversions
kdl_conversions
Copy link
Contributor

Choose a reason for hiding this comment

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

What about kdl_conversions? Is this still needed, now that you use eigen_kdl?

Copy link
Contributor

@gleichdick gleichdick left a comment

Choose a reason for hiding this comment

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

Good work, you're almost done!

@@ -1387,7 +1386,7 @@ void IKFastKinematicsPlugin::transformToChainFrame(const geometry_msgs::Pose& ik
if (base_transform_required_)
ik_eigen_pose = chain_base_to_group_base_ * ik_eigen_pose;

tf::transformEigenToKDL(ik_eigen_pose, ik_pose_chain);
tf2::convert(ik_eigen_pose, ik_pose_chain);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the explicit conversion (toMsg() / fromMsg()) for the same reason as before

Comment on lines 23 to 24
tf2
tf2_eigen
Copy link
Contributor

Choose a reason for hiding this comment

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

I think tf2_ros is also not necessary

@gleichdick
Copy link
Contributor

This should fix the linking error in the CI:

--- a/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_circ.cpp
+++ b/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_circ.cpp
@@ -42,12 +42,12 @@
 #include <kdl/trajectory_segment.hpp>
 #include <kdl/utilities/error.h>
 #include <kdl/utilities/utility.h>
-#include <kdl_conversions/kdl_msg.h>
 #include <moveit/robot_state/conversions.h>
 #include <ros/ros.h>
 #include <tf2/convert.h>
 #include <tf2_eigen/tf2_eigen.h>
 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
+#include <tf2_kdl/tf2_kdl.h>
 
 namespace pilz_industrial_motion_planner
 {
@@ -222,9 +222,8 @@ std::unique_ptr<KDL::Path> TrajectoryGeneratorCIRC::setPathCIRC(const MotionPlan
   pose_msg = tf2::toMsg(info.goal_pose);
   tf2::fromMsg(pose_msg, goal_pose);
 
-  KDL::Vector path_point;
-  const geometry_msgs::Point point_msg = tf2::toMsg(info.circ_path_point.second);
-  tf2::fromMsg(point_msg, path_point);
+  const auto& eigen_path_point = info.circ_path_point.second;
+  const KDL::Vector path_point{ eigen_path_point.x(), eigen_path_point.y(), eigen_path_point.z() };
 
   // pass the ratio of translational by rotational velocity as equivalent radius
   // to get a trajectory with rotational speed, if no (or very little)
diff --git a/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_lin.cpp b/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_lin.cpp
index 67e5e939d..cd86b7b1c 100644
--- a/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_lin.cpp
+++ b/moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_lin.cpp
@@ -45,6 +45,7 @@
 #include <kdl/trajectory_segment.hpp>
 #include <kdl/utilities/error.h>
 
+#include <tf2_kdl/tf2_kdl.h>
 #include <tf2/convert.h>
 #include <tf2_eigen/tf2_eigen.h>
 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>

Unfortunately, one conversion function with KDL::Vector is missing, so we have do do it on our own...

@petkovich
Copy link
Contributor Author

Is there any way to know whether CI will pass without pushing the code and waiting? Last few commits pass without warnings/errors locally but do not satisfy the CI check.

@rhaschke
Copy link
Contributor

You can run the CI scripts locally as described here.
However, often it is more efficient to just look for the failing Travis command(s) and fix them, in your case, catkin_lint:
https://travis-ci.com/github/ros-planning/moveit/jobs/473550318

@petkovich
Copy link
Contributor Author

It looks like the previous check passed, although, if I am correct, it did not at the time I have committed it. Is this PR now solved?

Copy link
Contributor Author

@petkovich petkovich left a comment

Choose a reason for hiding this comment

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

Forgot to review them until now, fixed.

* Use tf2::toMsg / tf2::fromMsg where possible
* Use tf2::convert when converting between two non-message types
  exception: conversion to/from KDL types:
             Due to a bad implementation of tf2_kdl (not using templates), tf2::convert cannot be used.
Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for your effort. I added another commit to even more unify usage of conversion functions:

  • Use tf2::toMsg / tf2::fromMsg where possible
  • Use tf2::convert when converting between two non-message types
    exception: conversion to/from KDL types: Due to a bad implementation of tf2_kdl (not using templates), tf2::convert cannot be used.

Ready to merge if CI is happy.

@rhaschke rhaschke merged commit b7711c1 into moveit:master Feb 17, 2021
@welcome
Copy link

welcome bot commented Feb 17, 2021

Congrats on getting your first MoveIt pull request merged and improving open source robotics!

@tylerjw tylerjw mentioned this pull request Apr 9, 2021
@tylerjw tylerjw mentioned this pull request Apr 29, 2021
sjahr pushed a commit to sjahr/moveit that referenced this pull request Jun 21, 2024
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