rosin-project / rxros

Reactive programming for ROS
BSD 3-Clause "New" or "Revised" License
48 stars 6 forks source link

The RxROS logging framework should be redesigned #17

Open henrik7264 opened 5 years ago

henrik7264 commented 5 years ago

It should be possible to write something similar to the following code:

rxros::Logging().info() << "Hello world  ";
rxros::observable::from_device<input_event>(keyboardDevice)
        | map(keyboardEvent2KeyboardMsg)
        | log_info(...)
        | publish_to_topic<teleop_msgs::Keyboard>("/keyboard");

It is important to provide a consistent and simple logging framework. It should be equally easy to log in a sequence of operator as well as outside. A proposed framework should be presented before implementation.

wasowski commented 4 years ago

This is a fragment how I did logging in the rxros_talker (still not merged):

rxcpp::observable<>::interval (std::chrono::milliseconds (1000))
  | map ([&](int i)٠                                            
      { return mk_msg(hello + std::to_string(i)); })            
  | tap ([](const std_msgs::String& msg)٠                       
      { ROS_INFO ("%s", msg.data.c_str()); })                   
  | publish_to_topic<std_msgs::String> ("/chatter", 1000);      

As you can see tap does almost what you want. It is probably very hard to do more -- you want to have access to the current message when formatting the string. So the only thing we can save is to remove ROS_INFO call, perhaps a simple wrapper around tap for rxros_info and the associated siblings of ROS_INFO could be added, to save this one call.

But it is probably not a very high priority. I would not argue against it though. Seems like a nice-to-have.