Hello I am new to ROS. I want to send messages in the form of string from Node1->Node2 and Node2->Node1. As Node1 can publish and Node2 can subscribe to the messages. Node2 can publish the message but in Node1 callback function is not getting called.
Program for Node1(talker)
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from number_generation import give_prime, secret_no
from modulo_operations import calculate
def callback2(data):
rospy.loginfo('I heard %s', data.data)
def talker():
pub = rospy.Publisher('chatter1', String, queue_size=1)
pub1 = rospy.Publisher('chatter', String, queue_size=1)
rospy.init_node('talker', anonymous=True)
P=str(give_prime())
q=str(give_prime())
secret = secret_no()
Server = str(calculate(int(P), int(q), int(secret)))
rospy.loginfo(P)
rospy.loginfo(q)
pub.publish(P)
pub1.publish(q)
rospy.Subscriber('c', String, callback2)
rospy.spin()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
Program for Node2(listener)
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from number_generation import secret_no
from modulo_operations import calculate
P='asdasd'
q='ygyg'
secret = 2
client = 13
def callback(data):
global P
P=int(data.data)
rospy.loginfo(rospy.get_caller_id() + 'I heard %s', P)
def callback1(data):
global q
global secret
global client
q=int(data.data)
rospy.loginfo(rospy.get_caller_id() + 'I heard %s', q)
sum()
def sum():
global secret
secret = secret_no()
client = str(calculate(int(P), int(q), int(secret)))
print 'calculation', client
pub2.publish(client)
if __name__ == '__main__':
rospy.init_node('listener', anonymous=True)
pub2 = rospy.Publisher('c',String,queue_size=1)
rospy.Subscriber('chatter', String, callback)
rospy.Subscriber('chatter1', String, callback1)
rospy.spin()
Originally posted by Anuja_Rane on ROS Answers with karma: 3 on 2018-10-01
Post score: 0