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

Print message from launch file

asked 2017-11-17 04:44:24 -0500

ravijoshi gravatar image

I am wondering if there is any way to print message from launch file. For example, I am calling a node from launch file and I do not want the user to terminate this process. Hence I simply want to print following:

Please keep this running in a separate tab.

Any workaround to achieve it? Thank you very much. Please note that I am using Python 2.7 in ROS Indigo on Ubuntu 14.04 LTS PC.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2017-11-17 11:17:23 -0500

lucasw gravatar image

updated 2017-11-17 11:19:26 -0500

rostopic echo:

<?xml version="1.0"?>
<launch>
  <arg name="msg" default="Please keep this running in a separate tab." />
  <node name="pub_text" pkg="rostopic" type="rostopic"
     args="pub /msg std_msgs/String '$(arg msg)'"
     output="screen" />
  <node name="print_text" pkg="rostopic" type="rostopic"
     args="echo /msg" output="screen" />

yields:

data: Please keep this running in a separate tab.

Though maybe the data: is undesirable

Adding a -p to the echo yields:

%time,field.data
1510939080429253101,Please keep this running in a separate tab.
edit flag offensive delete link more
1

answered 2017-11-17 07:26:44 -0500

updated 2017-11-17 09:22:12 -0500

I don't think it's possible to print text directly form the roslaunch xml (w/o passing it into a node as a param / arg).

Best solution would be to put

print("Please keep this running in a separate tab.")

in your node script.


In your *.launch script, if you set the node's output attribute to "screen", the message will be printed to the terminal window.

<node name="PrintToScreenNode_1" pkg="my_package" type="print_to_screen.py" output="screen"/>

Note: You can also start your nodes in their own separate terminal windows using the launch-prefix attribute.

<node name="PrintToScreenNode_2" pkg="my_package" type="print_to_screen.py" output="screen" launch-prefix="xterm -e"/>

EDIT:

Here's an example script that just prints to the terminal:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
# Name: print_to_screen.py
# Author: Joseph Coombe
'''

# Uncomment lines 10, 13, 15 if you're running this node in its own separate
# terminal window. Otherwise the script will immediately exit and its terminal window will close.
#import rospy

def main():
    #rospy.init_node('print_to_screen', anonymous=True)
    print("Please keep this running in a separate tab.")
    #rospy.spin()

if __name__ == '__main__':
    main()

You'll want to un-comment the rospy lines if you're launching this script in its own terminal (by using the launch-prefix attribute in your *.launch file). Otherwise, it'll immediately exit and close its terminal window (and as a result nobody will see the message).

edit flag offensive delete link more

Comments

Thank you very much. I want to know, if it is possible to create print_to_screen.py with only following content and nothing else print("Please keep this running in a separate tab.")

ravijoshi gravatar image ravijoshi  ( 2017-11-17 08:57:50 -0500 )edit

@Ravi Joshi Yes. I've edited my answer with a simple example.

josephcoombe gravatar image josephcoombe  ( 2017-11-17 09:19:15 -0500 )edit

What about printing a value from inside the launch file, say an arg or param value? How can the python script access them and print?

hbaqueiro gravatar image hbaqueiro  ( 2018-11-08 09:29:07 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-11-17 04:44:24 -0500

Seen: 9,921 times

Last updated: Nov 17 '17