ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

crisannik's profile - activity

2018-02-20 09:04:56 -0500 received badge  Famous Question (source)
2016-11-21 08:05:47 -0500 received badge  Notable Question (source)
2016-05-31 02:09:19 -0500 received badge  Student (source)
2016-05-22 10:09:17 -0500 received badge  Popular Question (source)
2016-05-21 09:25:04 -0500 commented question How can i make communication between two nodes(Python)

Yes, my problem is related

2016-05-21 09:11:44 -0500 asked a question How can i make communication between two nodes(Python)

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???