June 2018
Beginner to intermediate
280 pages
6h 58m
English
The subscriber code is as follows:
#!/usr/bin/env python import rospy from std_msgs.msg import String
The following code is a callback function that is executed when a message reaches the hello_pub topic. The data variable contains the message from the topic, and it will print using rospy.loginfo():
def callback(data):
rospy.loginfo(rospy.get_caller_id()+"I heard %s",data.data)
The following steps will start the node with a hello_world_subscriber name and start subscribing to the /hello_pub topic:
def listener():
rospy.init_node('hello_world_subscriber', anonymous=True) rospy.Subscriber("hello_pub", ...