Skip to content

Instantly share code, notes, and snippets.

@contradict
Created May 1, 2015 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contradict/42f5ed7fa39e1de1cc51 to your computer and use it in GitHub Desktop.
Save contradict/42f5ed7fa39e1de1cc51 to your computer and use it in GitHub Desktop.
yaml over ros topic
#!/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