made tf2_py compile on ROS2#26
Conversation
bringing up to date
following head
made tf2_py compile with ROS2
|
Thanks for doing this, this will be helpful for getting some of the tf2 debugging tools going. As a meta-comment, I think it would be best not to touch the pieces that don't absolutely require touching. This will make it easier for us to merge in stuff from the base ros/geometry2 repository as needed. In this PR, I would say that we shouldn't bother removing the meta-package stuff. I'll do a review of the rest of the stuff in here. |
clalancette
left a comment
There was a problem hiding this comment.
Nothing majorly wrong here, but I would like it to reuse some more existing code, and get parts of this in upstream ros/geometry2.
|
|
||
|
|
||
| }; | ||
| } |
There was a problem hiding this comment.
This is present in the upstream geometry2 code. Would you mind opening a PR there to remove it (and then we'll inherit it the next time we merge)? If you don't have time, let me know and I can do it instead.
There was a problem hiding this comment.
I confess I'm not too interested in fixing this for ROS1. My team at ASI isn't using ROS1, and I'm not too familiar with it.
tf2_py/CMakeLists.txt
Outdated
| # Dynamic linking with tf worked OK, except for exception propagation, which failed in the unit test. | ||
| # so build with the objects directly instead. | ||
| if(NOT WIN32) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wpedantic") |
There was a problem hiding this comment.
There's no way you could have known this, but we have changed this idiom. See the top of i.e. https://github.com/ros2/turtlebot2_demo/blob/master/turtlebot2_drivers/CMakeLists.txt for the new idiom.
| find_package(tf2 REQUIRED) | ||
| find_package(tf2_msgs REQUIRED) | ||
| find_package(PythonLibs 3 REQUIRED) | ||
| include_directories(${PYTHON_INCLUDE_PATH}) |
There was a problem hiding this comment.
Nit, but please alphabetize the find_package() invocations. Also a newline between them and include_directories()
tf2_py/CMakeLists.txt
Outdated
| ## Testing ## | ||
| ############# | ||
| add_library(${PROJECT_NAME} src/tf2_py.cpp) | ||
| set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) |
There was a problem hiding this comment.
Why did you need to add the LINKER_LANGUAGE when the upstream doesn't have it? A comment might be helpful, and is it something we should add to upstream?
There was a problem hiding this comment.
Fixed. The LINKER_LANGUAGE was required for the unique_id stuff, which I borrowed from.
tf2_py/CMakeLists.txt
Outdated
| # if(TARGET ${PROJECT_NAME}-test) | ||
| # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) | ||
| # endif() | ||
| ament_target_dependencies(${PROJECT_NAME} "rclcpp" "rclpy" "geometry_msgs" "tf2_msgs" "python") |
There was a problem hiding this comment.
Nit: we prefer one dependency per-line.
| <?xml version="1.0"?> | ||
| <package> | ||
| <?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="2"> |
There was a problem hiding this comment.
It would be good to change the upstream package.xml to format 2 (and clean it up while we are at it), and then just change the dependencies as necessary here. Again, if you don't have time to do that, let me know and I can.
| "_tf2.BufferCore", /*name*/ | ||
| sizeof(buffer_core_t), /*basicsize*/ | ||
| "_tf2.BufferCore", /* name */ | ||
| sizeof(buffer_core_t), /* basicsize */ |
There was a problem hiding this comment.
This seems like a spurious change.
There was a problem hiding this comment.
There's actually still a bug here. That structure isn't initialized completely. I pasted in (and aligned comments to) what I thought was the full initialization from http://python3porting.com/cextensions.html , but it still showed a lot of warnings and seemed incomplete.
| WRAP(source_id = bc->_validateFrameId("get_latest_common_time", source_frame)); | ||
| int r = bc->_getLatestCommonTime(target_id, source_id, time, &error_string); | ||
| if (r == 0) { | ||
| auto r = bc->_getLatestCommonTime(target_id, source_id, time, &error_string); |
There was a problem hiding this comment.
This change to "auto" (and elsewhere in the file) again look like something that could go into upstream tf2_py.
There was a problem hiding this comment.
These changes to auto were made because I was too lazy to figure out what the ROS2 equivalent types were (and what header they were defined in).
tf2_py/src/tf2_py.cpp
Outdated
| } | ||
| } | ||
|
|
||
| static int rostime_converter_blt(PyObject *obj, builtin_interfaces::msg::Time *rt) |
There was a problem hiding this comment.
We already have an interface to convert from builtin_interfaces::msg::Time -> tf2::TimePoint: https://github.com/ros2/geometry2/blob/ros2/tf2_ros/include/tf2_ros/buffer_interface.h#L58 . I think it would be best to reuse that, as having the conversions scattered around seems to be more fragile to me. That being said, that would introduce a new dependency on tf2_py, namely tf2_ros; I'm not sure if that is a problem or not.
There was a problem hiding this comment.
Any other thoughts on this dependency? I think it will be okay for the sake of "always reuse code".
| if (!PyArg_ParseTupleAndKeywords(args, kw, "|O&", (char**)keywords, rostime_converter, &time)) | ||
| return NULL; | ||
| return PyString_FromString(bc->_allFramesAsDot(time.toSec()).c_str()); | ||
| return stringToPython(bc->_allFramesAsDot(time).c_str()); |
There was a problem hiding this comment.
Again, looks like a good change for upstream.
There was a problem hiding this comment.
That method PyString_FromString didn't seem to exist for me. I don't know where it was coming from before.
fixed package ordering, time message conversion
| endif() | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options(-Wall -Wextra) |
There was a problem hiding this comment.
Do we need these flags on for some reason? I'd prefer these only get introduced if we're compiling with -DCMAKE_BUILD_TYPE=Debug.
There was a problem hiding this comment.
We use these flags everywhere in the ros2 codebase, we usually try to also use Wpedantic when it doesn't introduce spurious changes or make us diverge too much for upstream. I don't see a good reason for this package to not do so What is the rationale for enforcing these flags only in debug mode?
|
Other than that one small comment, this looks good to me (after changes that @clalancette brought up). |
mikaelarguedas
left a comment
There was a problem hiding this comment.
I made a few high level remarks on the approach but haven't reviewed the code, see comments below
tf2_py/package.xml
Outdated
| <build_depend>tf2</build_depend> | ||
| <build_depend>builtin_interfaces</build_depend> | ||
| <build_depend>geometry_msgs</build_depend> | ||
| <build_depend>rospy</build_depend> |
There was a problem hiding this comment.
This dependency should be removed because rospy is a ros1 package. All the code relying on rospy (starting with the import here https://github.com/ros2/geometry2/pull/26/files#diff-43abb9e427aa2b1429dbad6c940088e9R576) and calls to its functions should be updated to use ros2 functions
tf2_py/package.xml
Outdated
| <!-- Other tools can request additional information be placed here --> | ||
|
|
||
| <build_type>ament_cmake</build_type> | ||
| <build_type>ament_python</build_type> |
There was a problem hiding this comment.
ament packages cannot have several build types, in this case I think you want an ament_cmake build type and install the python modules through cmake
There was a problem hiding this comment.
Are there any examples of installing ROS2 python modules through cmake?
There was a problem hiding this comment.
Please see the following two CMake functions and their docblocks: https://github.com/ament/ament_cmake/tree/master/ament_cmake_python/cmake
|
Looking at this further today, the code still relies on |
Not at the moment, but that's just because we haven't had time to implement it. A full "ROS Time" interface is planned for Beta 3. I think that was mostly for C++, but we'll probably do Python at the same time. |
fixed dll deployment
|
I've changed it to deploy the shared library as part of the cmake_process. I moved the init.py file to match the default ament package deployment. I also had to add an install line, which I think should be part of the ament deployment instead. The leading underscore on the shared library -- is that the way we've always done C/C++ implementations of python modules? That seems a little weird to me (but matches what we did in ROS1). |
|
@tfoote to pull upstream changes. Moving in backlog given that we don't have time in python right now |
|
It looks like These commits are included in #99. I'll close this as replaced by that PR. |
I'm not sure it's being deployed correctly. Can somebody verify that?
There were a lot of pre-existing warnings about uninitialized structures. Those are still there.
I would like to finish converting geometry2 and run the tests. Talk it up if you want me to find time for that.
I removed the metapackages. I assume there will not be any equivalent of them in ROS2.