Ask Your Question
1

Print message from launch file

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

Ravi Joshi 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
2

answered 2017-11-17 11:17:23 -0600

lucasw gravatar image

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

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 -0600

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

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.")

Ravi Joshi gravatar imageRavi Joshi ( 2017-11-17 08:57:50 -0600 )edit

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

josephcoombe gravatar imagejosephcoombe ( 2017-11-17 09:19:15 -0600 )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 imagehbaqueiro ( 2018-11-08 09:29:07 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 2,755 times

Last updated: Nov 17 '17