Created
May 1, 2015 05:57
-
-
Save contradict/42f5ed7fa39e1de1cc51 to your computer and use it in GitHub Desktop.
yaml over ros topic
This file contains 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
#!/usr/bin/env python | |
# run the receiver: | |
# $ ./yaml_send.py | |
# | |
# run the transmitter: | |
# $ ./yaml_send.py send <myfile.yaml> | |
import yaml | |
import sys | |
import rospy | |
from std_msgs.msg import String | |
def receive(msg): | |
parsed = yaml.load(msg.data) | |
print parsed | |
def send(yamlfile): | |
pub = rospy.Publisher('yaml', String, queue_size=1) | |
rospy.sleep(1.0) | |
with open(yamlfile) as f: | |
msg = String(f.read()) | |
pub.publish(msg) | |
rospy.sleep(1.0) | |
if __name__=="__main__": | |
if len(sys.argv)==1: | |
rospy.init_node('yaml_receiver') | |
sub = rospy.Subscriber('yaml', String, receive) | |
rospy.spin() | |
elif sys.argv[1] == 'send': | |
rospy.init_node('yaml_sender') | |
send(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment