0

i am working with ROS and my task is to migrate existing Projects from ros1 to ros2. In ros1 stream functions like

ROS_INFO_STREAM(String << variable << ...) 

exist but not in ros2, because they are not implemented yet in the rclcpp. My idea is to write a function in c++ that works with these operators and works like std::cout. But i really don't know how to implement a function like this.

Does anyone have an idea or approach?

Solution: A possible solution is to define a macro like this

#define ROS_INFO_STREAM(logger, _msgStream) std::stringstream stream_buffer; stream_buffer << _msgStream; ROS_INFO(logger, stream_buffer.str().c_str());

in a separate headerfile and include it wherever it is needed.

Steffan
  • 1
  • 2
  • 2
    It's very likely that `ROS_INFO_STREAM` is a macro defined in a ROS header file. That should make it simple to find the definition and look at how they do it. Then you could possibly attempt to duplicate it? – Some programmer dude Jan 10 '19 at 13:47
  • Have you tried to look into the header console.h ? – Clonk Jan 10 '19 at 13:54
  • ROS_INFO_STREAM is defined in macros_generated.h at line 99 #define ROS_INFO_STREAM(args) ROS_LOG_STREAM(::ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, args) – Steffan Jan 10 '19 at 13:59
  • 3
    Okay, so what does `ROS_LOG_STREAM` do? (That was a rhetorical question. Let's not go through this step by step - you can follow the breadcrumbs to the implementation on your own) – Lightness Races in Orbit Jan 10 '19 at 14:08

1 Answers1

0

The difference is that in ROS 2, the RCLCPP_INFO_STREAM expects a logger a the first argument. This should work similarly to the ROS 1

int a = 0;
int b = 1; 
RCLCPP_INFO_STREAM(rclcpp::get_logger("rclcpp"), "Value of a = " << a << ", and value of b = " << b);
Robotawi
  • 11
  • 2