Last active
December 11, 2015 20:19
-
-
Save PierrickKoch/4654458 to your computer and use it in GitHub Desktop.
ROS Pub / Sub demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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!")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # in bash | |
| rostopic pub /test std_msgs/String "Hello world!" | |
| rostopic echo /test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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