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

Trace terminal output to program

asked 2022-01-08 15:46:41 -0500

USAotearoa gravatar image

Does anyone know how I can trace the terminal output to the actual program where it is coming from? I have listed all nodes, search through the program's source codes with VS Code and terminal search, but I just can't find the "print" or "cout" where that text is originating from.

Here is what I'm trying to do: Run autonomous map exploration on ROS noetic (simulation for now) using turtlebot3. I found github repo from "fazildgr8 /ros_autonomous_slam " But it is not autonomously moving. Autonomy fails, I'm trying to find out why, but can't add print statements and watch the terminal output, because too much other stuff that is irrelevant is being printed. Which leads me to this question.

Here some of the output, I'm trying to suppress:

m_count 556
Average Scan Matching Score=202.256
neff= 99.9999
Registering Scans:Done
update frame 1671
update ld=2.48113e-07 ad=2.22128e-06
Laser Pose= -2.06351 0.500132 -3.14022
m_count 557
Average Scan Matching Score=203.167
neff= 99.9999
Registering Scans:Done
update frame 1674
update ld=2.49394e-07 ad=2.23275e-06
Laser Pose= -2.06351 0.500132 -3.14021
m_count 558
Average Scan Matching Score=203.222
neff= 99.9999
Registering Scans:Done
update frame 1677
update ld=2.49809e-07 ad=2.23646e-06
Laser Pose= -2.06351 0.500133 -3.14021
m_count 559
Average Scan Matching Score=203.229
neff= 99.9999
Registering Scans:Done
update frame 1680
update ld=2.49819e-07 ad=2.23655e-06
Laser Pose= -2.06351 0.500133 -3.14021
m_count 560
Average Scan Matching Score=202.238
neff= 99.9999
Registering Scans:Done
update frame 1683
update ld=2.50245e-07 ad=2.24037e-06
Laser Pose= -2.06351 0.500133 -3.14021

I have looked at the topics and noticed, nothing is being published on the /cmd_vel topic. And that started the curiosity, by adding print statements in the move_base node, which is according to rqt_graph publishing the topic. But rostopic echo /cmd_vel results no info, just a Warning, questioning if anything is being published on that topic.

So, does anyone know how I could find the source of all that text being printed to the console?

Thank you

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-01-08 19:31:06 -0500

osilva gravatar image

Hi @USAotearoa, interesting question, you need to peel the layers to find the source of these "terminal messages".

The package ros_autonomous_slam: https://github.com/fazildgr8/ros_auto... in the turtlebot3_slam.launch file, calls turtlebot3_gmapping.launch from turtlebot3_slam package as seen below:

<!-- SLAM: Gmapping, Cartographer, Hector, Karto, Frontier_exploration, RTAB-Map -->
  <include file="$(find turtlebot3_slam)/launch/turtlebot3_$(arg slam_methods).launch">
    <arg name="model" value="$(arg model)"/>
    <arg name="configuration_basename" value="$(arg configuration_basename)"/>
  </include>

The turtlebot3_gmapping.launch file found here calls slam_gmapping from gmapping package:

<node pkg="gmapping" type="slam_gmapping" name="turtlebot3_slam_gmapping" output="screen">

The slam_gmapping source code can be found here that calls the following header files: slam_gmapping.h that calls gmapping/gridfastslam/gridslamprocessor.h that calls gridslamprocessor.hxx found in this line code here.

In gridslamprocessor.hxx you can find the source of the message in line 39:

m_infoStream << "Average Scan Matching Score=" << sumScore/m_particles.size() << std::endl;

and in line 151:

std::cerr << "Registering Scans:";

You don't need to change the source code, but just wanted to show you how to find where the message is coming from. To avoid the message printing in terminal you can modify the launch file from:

<node pkg="gmapping" type="slam_gmapping" name="turtlebot3_slam_gmapping" output="screen">

to:

<node pkg="gmapping" type="slam_gmapping" name="turtlebot3_slam_gmapping" output="log">

There are two options for nodes:

output="log|screen"(optional)

If 'screen', stdout/stderr from the node will be sent to the screen. If 'log', the stdout/stderr output will be sent to a log file in $ROS_HOME/log, and stderr will continue to be sent to screen. The default is 'log'. Source: http://wiki.ros.org/roslaunch/XML/node

edit flag offensive delete link more

Comments

@osilva Mate, just just saved me the rest of the afternoon :-) Thank you for spending your valuable time and helping out! Appreciate it, truly.

I was peeling into those layers already and I did actually perform searches in the turtlebot packages as well, because I knew that is where it's coming from. But unfortunately I limited my search to "cout" and rospy.logerr, .loginfo" etc.

I did modify the launch file, as I'm familiar with the output statement, however that resulted in having no terminal output at all. So I will opt for modifying the source code and recompile, now (thanks to you) where I need to apply those changes :-) Excited

Cheers

USAotearoa gravatar image USAotearoa  ( 2022-01-08 20:13:20 -0500 )edit

One trick for your repertoire, the way I found it was to search the message in github. Glad it helped

osilva gravatar image osilva  ( 2022-01-08 20:22:18 -0500 )edit
1

answered 2022-01-08 17:33:12 -0500

miura gravatar image

Setting ROSCONSOLE_FORMAT seems to accomplish the goal.

http://wiki.ros.org/rosconsole#Consol...

You can also use the rqt_logger_level tool to suppress console log output or allow debug messages to be displayed.

http://wiki.ros.org/rqt_logger_level

edit flag offensive delete link more

Comments

Hi @miura, thanks for the reply. Appreciate you taking the time to help :-)

I have set the logging level of everything in rqt_logger_level to "fatal", but still get the same console output.

The first solution offered, is not going to work, as it will also impact my debugging output, right? Or does the ROSCONSOLE_FORMAT not affect print and cout statements printing to the console, but rather only the rospy.loginfo, rospy.logerr and the others?

Thanks for clarifying. In the meantime I will give it a try and report back!

osilva gravatar image osilva  ( 2022-01-08 19:32:28 -0500 )edit

@USAotearoa moved your answer as comment responding to @miura.

osilva gravatar image osilva  ( 2022-01-08 19:56:53 -0500 )edit

@osilva Sorry for the late reply. I'm glad to hear that you solved the problem.

I don't know much about ROSCONSOLE_FORMAT, but I think it only affects rospy.loginfo, rospy.logerr, and so on.

miura gravatar image miura  ( 2022-01-09 18:42:26 -0500 )edit

Hi @miura. Sorry, my name was added when I edited and moved OP answer to comment

osilva gravatar image osilva  ( 2022-01-09 18:49:00 -0500 )edit

@osilva I see. Thank you very much.

@USAotearoa I'm sure this has been resolved, but I commented above.

miura gravatar image miura  ( 2022-01-10 17:30:33 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-01-08 15:46:41 -0500

Seen: 293 times

Last updated: Jan 08 '22