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

Revision history [back]

rospy has a logger, use it

topic = 'sensor_msgs/LaserScan/topic'
 rospy.loginfo("I will publish to the topic %s", topic)

and some latter in the callback:

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

rospy has a logger, use it

topic = 'sensor_msgs/LaserScan/topic'
 rospy.loginfo("I will publish to the topic %s", topic)

and some latter in the callback:

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

if you maybe need to collect the data to later use it / reproduce it for analytics purposes then a Rosbag is the way to go :)

import rosbag
from std_msgs.msg import Int32, String

bag = rosbag.Bag('test.bag', 'w')

try:
    str = String()
    str.data = 'foo'

    i = Int32()
    i.data = 42

    bag.write('chatter', str)
    bag.write('numbers', i)
finally:
    bag.close()