0
$\begingroup$

Rosanswers logo

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()


Originally posted by Woz on ROS Answers with karma: 78 on 2022-07-13

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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));

Originally posted by Woz with karma: 78 on 2022-07-14

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by tfoote on 2022-07-14:
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/ios_base/fmtflags/ 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?

Comment by Woz on 2022-07-14:
Sure! I'll post a file when I can.

Comment by Woz on 2022-07-14:
I have a mini example here: https://github.com/pytorch/pytorch/issues/81543

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

Comment by tfoote on 2022-07-15:
Wow, nice job tracking this down to a very minimal example!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.