Ask Your Question
0

print python same std:cout

asked 2015-09-01 11:17:14 -0500

Porti77 gravatar image

updated 2015-09-02 10:23:13 -0500

I want print in a console in a script of python, i not want use rospy.loginfo or warn. I want something like C ++ cout. Any idea?

Edit 1:

#!/usr/bin/env python
# Software License Agreement (BSD License)

import rospy
import roslib
import tf
import sys

import serial, string, math, time, calendar

if __name__ == '__main__':
    rospy.init_node('Compass', anonymous=True) 

    try:
        while not rospy.is_shutdown():
            rospy.logwarn("Angulo yaw: %.1f", z_axis_direction * orientation_rad / math.pi * 180.)
            print " Print "
            sys.stdout.write("stdout")
                rospy.loginfo("ros info")
    pass

Rospy log warn prints in a console but like a warning message with yellow color. Print and stdout not do anything. And finally rospy log info print in a /rosout topic.

Edit 1: The launch

<!-- Compass nodo of Furuno PG-1000 -->
<launch>
       <node name="compass1" pkg="nodos_creados" type="FurunoCompassNode.py" respawn="true">
       </node>
</launch>
edit retag flag offensive close merge delete

Comments

Are you launching the node using roslaunch? What does your launchfile look like?

sloretz gravatar imagesloretz ( 2015-09-02 10:05:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2015-09-01 11:33:12 -0500

gvdhoorn gravatar image

updated 2015-09-02 10:33:24 -0500

This is really a bit off-topic, but what about print(..) or sys.stdout.write(..)?


Edit:

<node name="compass1" pkg="nodos_creados" type="FurunoCompassNode.py" respawn="true" />

Try adding output="screen". Without that, the stdout of your node will not end up on your console. Which is probably why you don't see any output when using print(..) or sys.stdout.write(..).

See also wiki/roslaunch/XML/node - Attributes:

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'.

And for instance How can I get my cout output on the console with roslaunch.

edit flag offensive delete link more

Comments

That does not work! I do it and not print anything on the console, is for this that I ask this question.

Porti77 gravatar imagePorti77 ( 2015-09-02 03:38:14 -0500 )edit

Then you should've given us more information. Please update your original question (using the edit button/link) with an example (so Python source) of what you tried, what happens and what you think should happen.

gvdhoorn gravatar imagegvdhoorn ( 2015-09-02 03:57:00 -0500 )edit

print definitely works. You're probably doing something in how you setup/run the node that redirects stdout.

dornhege gravatar imagedornhege ( 2015-09-02 08:18:47 -0500 )edit

OK!! Thank you @gvdhoorn , I had not realized that.

Porti77 gravatar imagePorti77 ( 2015-09-02 11:20:57 -0500 )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

1 follower

Stats

Asked: 2015-09-01 11:17:14 -0500

Seen: 3,232 times

Last updated: Sep 02 '15