Skip to content

Instantly share code, notes, and snippets.

@PierrickKoch
Last active December 11, 2015 20:19
Show Gist options
  • Select an option

  • Save PierrickKoch/4654458 to your computer and use it in GitHub Desktop.

Select an option

Save PierrickKoch/4654458 to your computer and use it in GitHub Desktop.
ROS Pub / Sub demo
"""
Publisher demo
"""
import rospy
from std_msgs.msg import String
rospy.init_node('my_second_node_description')
topic_name = "/test"
pub = rospy.Publisher(topic_name, String)
pub.publish(String("Hello world!"))
# in bash
rostopic pub /test std_msgs/String "Hello world!"
rostopic echo /test
"""
Subscriber demo
"""
import rospy
from std_msgs.msg import String
rospy.init_node('my_first_node_description')
def callback(message):
# see: ros.org/doc/api/std_msgs/html/msg/String.html
print(message.data)
topic_name = "/test"
sub = rospy.Subscriber(topic_name, String, callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment