Trying to publish information from subscriber node.
I'm trying to make system consist of several sections, it must surely have at least 1 node doing 2 roles, both subscriber and publisher. and here it my codes.
First section
#!/usr/bin/env python3
import rospy as R
from std_msgs.msg import Float64
def sender_3():
x = 0
y = float(input("Give us the float num: "))
pub = R.Publisher("line3", Float64, queue_size=10)
R.init_node("sender_3", anonymous=True)
rate = R.Rate(10)
while not R.is_shutdown() and x < y:
x += 0.1
t = x
print(x)
pub.publish(t)
rate.sleep()
if __name__ == "__main__":
try:
sender_3()
except R.ROSInterruptException:
pass
Second section
#!/usr/bin/env python3
import rospy as R
from std_msgs.msg import Float64, String
def callback(data):
global r_data
r_data = data.data
R.loginfo("sawadee krub i've received as info: %f", data.data)
global t_o
t_o = str(r_data)
R.loginfo("Applied num to chatGPT: %s", t_o)
def receiver_2():
R.init_node("receiver_2", anonymous=10)
R.Subscriber("line3", Float64, callback, queue_size=True)
pub = R.Publisher("translne", String, queue_size=10)
rate = R.Rate(10)
while not R.is_shutdown:
print(t_o)
pub.publish(t_o)
rate.sleep()
R.spin()
#def transporter():
# R.init_node("transporter send you", anonymous=10)
# pub = R.Publisher("translne", String, queue_size=10)
# while not R.is_shutdown:
# print(receiver_2)
# pub.publish(receiver_2)
# R.Rate(10)
if __name__ == "__main__":
receiver_2()
Last section
#!/usr/bin/env python3
import rospy as R
from std_msgs.msg import String
def callback(data):
R.loginfo("I've received an information: %s", data.data)
def sub_receiver():
R.init_node("sub_receiver", anonymous=True)
R.Subscriber("translne", String , callback, queue_size=10)
R.spin()
if __name__ == "__main__":
sub_receiver()
My problem is during the transition between second and last section, it seems like last section didn't receive any information which is translated into String and published to last section, cause there's nothing appears even error. P.S I commented on third section for several previous tries. Edited: Mistakes have been fixed.
Thank you in advance.