Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 99

How can i make communication between two nodes(Python)

$
0
0
Hi... I have a problem with rospy. I want to create two nodes that communicate with each other. The problem is that the communication starts only when node1 and node2 send information on the channel where they are subscribed. ROSPY NODE1 import rospy from std_msgs.msg import String def callback(msg): print '%s' % msg.data def nodo(): pub = rospy.Publisher('chatter1', String, queue_size=10) rospy.init_node('nodo1', anonymous=True) rospy.Subscriber('chatter2', String, callback) rate = rospy.Rate(1) # 10hz x = "Nodo1" while not rospy.is_shutdown(): for i in range(1,51): num = "%s" % (x) rospy.loginfo(num) pub.publish(num) rate.sleep() rospy.spin() if __name__ == '__main__': try: nodo() except rospy.ROSInterruptException: pass ROSPY NODE2 import rospy from std_msgs.msg import String def callback(msg): print '%s' % msg.data def nodo(): pub = rospy.Publisher('chatter2', String, queue_size=10) rospy.init_node('nodo2', anonymous=True) rospy.Subscriber('chatter1', String, callback) rate = rospy.Rate(1) # 10hz x2 = "Nodo2" while not rospy.is_shutdown(): for i in range(1,51): num = "%s" % (x2) rospy.loginfo(num) pub.publish(num) rate.sleep() rospy.spin() if __name__ == '__main__': try: nodo() except rospy.ROSInterruptException: pass How can i start the communication only when the nodes are enabled???

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>