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

Segregating roscolsole output (C++)

asked 2015-05-19 13:43:46 -0600

Jordan9 gravatar image

updated 2015-05-27 12:12:08 -0600

I'm running a node that has two main threads going on it it. I would like to segregate the output from these two threads by sending the text in ROS_INFO/ROS_ERROR/etc. to one of two different terminals. For example:

ROS_INFO("term1", "This should appear on Terminal 1");
ROS_INFO("term2", "This should appear on Terminal 2");

I want to do this because the two threads have quite different purposes, and I want to be able to easily see which output is from which thread and have it all together in one place. Is there any convenient way of doing this? I'm not overly familiar with Linux, but maybe piping the output to something other than stdout and then having a shell script that reads from the output and writes to stdout on a different terminal?

EDIT: is there a way to bump this question, or put a bounty on it or something? The two answers given do not, unfortunately, solve the problem.

edit retag flag offensive close merge delete

Comments

There's no way to put a bounty on questions on ROS Answers. I haven't heard of anyone trying to do anything like what you're proposing, so you're not likely to find a pre-made solution.

ahendrix gravatar image ahendrix  ( 2015-05-27 20:38:37 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-05-20 01:16:39 -0600

Wolf gravatar image

All ROS_CONSOLE macros have a version with postfix _NAMED, e. g.

ROS_INFO(  ... )

and

ROS_INFO_NAMED( name, ... )

(See your macros_generated.h; it should be in /opt/ros/indigo/include/rosconsole/macros_generated.h)

Calling ROS_INFO_NAMED with an name following the same args like a ROS_INFO call results in the same behaviour but the node name is overriden by the name you have given to it.

So you can easily always call ROS_INFO_NAMED, ROS_WARN_NAMED, ROS_INFO_STREAM_NAMED and so on with different names in both threads of your node and then open two instances of rqt_console and filter in both instances the messages by name....

edit flag offensive delete link more

Comments

This sounds pretty much like what I need. Can you elaborate a little bit on the rqt_console bit? It looks like rqt_console is a GUI, but I need the output in a terminal because it's running over a simple SSH connection.

Jordan9 gravatar image Jordan9  ( 2015-05-20 11:01:23 -0600 )edit

the logs are published to /rosout so how can also run rqt_console on a remote conputer (if it is in your ROS network)

Wolf gravatar image Wolf  ( 2015-05-21 01:08:27 -0600 )edit

Yeah, so I was looking at /rosout to try to find a way to just subscribe to the logs and print them in a different node. Unfortunately, the rosgraph_msgs/Log message that is published on /rosout only includes the name of the node, not the name of the logger that I provided in ROS_INFO_NAMED().

Jordan9 gravatar image Jordan9  ( 2015-05-21 09:03:03 -0600 )edit

So, since I can't get the logger name out of the /rosout message, I can't separate which ones were from ROS_INFO_NAMED("term1",...) and which ones were from ROS_INFO_NAMED("term2"...) if they originated from the same node.

Jordan9 gravatar image Jordan9  ( 2015-05-21 09:04:06 -0600 )edit

To view them separately use a tool like rqt_console and the filters to get the separate streams after creating the named loggers.

tfoote gravatar image tfoote  ( 2015-05-22 00:46:12 -0600 )edit

@tfoote yes I can do it with rqt_console, but as mentioned in a previous comment I need it to be terminal-based (non-gui) because I need to run it over an SSH tunnel.

Jordan9 gravatar image Jordan9  ( 2015-05-22 10:55:23 -0600 )edit
1

ROS is network-based; you should be able to set the ROS_MASTER_URI on your local machine to use the ROS master on your robot, and run rqt_console locally.

ahendrix gravatar image ahendrix  ( 2015-05-27 20:39:13 -0600 )edit
0

answered 2015-05-19 19:50:50 -0600

Thomas D gravatar image

If you type this in your terminal prior to running your nodes then you will see which node is printing output.

export ROSCONSOLE_FORMAT='[${severity}] [${time}] - ${node}:${line}: ${message}'

Put that line in your ~/.bashrc file to make it persistent across restarting terminal sessions.

edit flag offensive delete link more

Comments

Thanks for the suggestion. I already have it listing which thread of the code it's coming from, but I need a way to separate where the output actually goes. Basically, one of them outputs fairly rapidly and the other less often but with important messages, and I need to be able to keep track of both

Jordan9 gravatar image Jordan9  ( 2015-05-19 22:25:56 -0600 )edit

Have you tried multiple instances of rqt_console?

Thomas D gravatar image Thomas D  ( 2015-05-19 22:49:13 -0600 )edit

How would you select between them within the code though, to determine which ROS_INFO goes where?

Jordan9 gravatar image Jordan9  ( 2015-05-19 23:05:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-05-19 13:43:46 -0600

Seen: 926 times

Last updated: May 27 '15