ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

TF2 throws rclcpp::exceptions::RCLInvalidROSArgsError when Pytorch libraries are linked

asked 2022-07-13 22:04:38 -0500

Woz gravatar image

updated 2022-07-13 23:28:49 -0500

I've been trying to integrate pytorch into my ROS 2 galactic node but have encountered an issue. When the executable gets to this line in my code:

_tf_buffer = std::make_unique<tf2_ros::Buffer>(this->get_clock());
_transform_listener = std::make_shared<tf2_ros::TransformListener>(*_tf_buffer);  # specifically this line

It throws a run time error:

what():  failed to parse arguments: Couldn't parse remap rule: '-r __node:=transform_listener_impl_563,a2c,cfa,cc0'. Error: Expected lexeme type (1) not found, search ended at index 35, at /tmp/binarydeb/ros-galactic-rcl-3.1.3/src/rcl/lexer_lookahead.c:233, at /tmp/binarydeb/ros-galactic-rcl-3.1.3/src/rcl/arguments.c:371

I did a test where I added these lines to CMakeLists.txt to another package utilizing TF2:

find_package(Torch REQUIRED)

target_link_libraries(${PROJECT_NAME} ${TORCH_LIBRARIES})

and the same error message appeared. I didn't change the package source files except modifying the CMakeLists.txt file.

For some reason, the act of linking pytorch libraries breaks TF2. I don't understand what the error message means so I'm not sure how to proceed.

Here's something resembling a stack trace. Nothing stands out to me for what could cause this message:

geometry2/tf2_ros/src/transform_listener.cpp
54 rclcpp::Node::make_shared()

rclcpp/rclcpp/src/rclcpp/node.cpp
143 Node::Node
151 get_rcl_node_options()

rclcpp/rclcpp/src/rclcpp/node_options.cpp
94 get_rcl_node_options
120 rcl_parse_arguments()

rcl/rcl/src/rcl/arguments.c
248 rcl_parse_arguments
363 _rcl_parse_remap_rule()
1827 _rcl_parse_remap_rule
1850 _rcl_parse_remap_begin_remap_rule()
1618 _rcl_parse_remap_begin_remap_rule
1666 rcl_lexer_lookahead2_expect()

rcl/rcl/src/rcl/lexer_lookahead.c
222 rcl_lexer_lookahead2_expect
233 rcl_lexer_lookahead2_peek()

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-14 02:39:50 -0500

Woz gravatar image

I found a solution to the issue. I dug into the source of geometry2. transform_listener_impl_563,a2c,cfa,cc0 shouldn't have commas in it. For whatever reason, the presence of pytorch libraries causes string formatters to insert commas.

So when pytorch isn't linked, sstream << "transform_listener_impl_" << std::hex << reinterpret_cast<size_t>(this); generates a string transform_listener_impl_563a2ccfacc0, but with it linked, it generates transform_listener_impl_563,a2c,cfa,cc0 which causes the rcl arg parser to freak out.

My solution was to avoid using C++ streams and modify the geometry2 source code:

  char node_name[64];
  sprintf(node_name, "transform_listener_impl_%lx", reinterpret_cast<size_t>(this));
edit flag offensive delete link more

Comments

Wow, that's a nasty side effect the pytorch linking that changes the stringstream std::hex basefield formatting. I can't find a comma separated option in ios_base: https://cplusplus.com/reference/ios/i... They might be somehow overloading or replacing the implementation in a not so nice way. That's probably worth a ticket on pytorch. Can you isolate that down to a smaller example? Such as just a stringstream in main?

tfoote gravatar image tfoote  ( 2022-07-14 17:22:11 -0500 )edit

Sure! I'll post a file when I can.

Woz gravatar image Woz  ( 2022-07-14 19:46:19 -0500 )edit

I have a mini example here: https://github.com/pytorch/pytorch/is...

Interestingly, it seems the call to .str() produces the commas. It doesn't happen when you pipe it straight to cout.

Woz gravatar image Woz  ( 2022-07-14 23:54:08 -0500 )edit

Wow, nice job tracking this down to a very minimal example!

tfoote gravatar image tfoote  ( 2022-07-15 00:53:50 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-07-13 22:04:38 -0500

Seen: 290 times

Last updated: Jul 14 '22