#!/usr/bin/env python
import rospy
from msg_send.msg import my_msg
from std_msgs.msg import String
import time
def call_back(data):
st_name = data.last_name + ' ' + data.first_name
curr_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
st_name2 = "Good morning, " + st_name + " " + curr_time
pub.publish(st_name2)
rospy.init_node("remote_teacher",anonymous = True)
pub = rospy.Publisher("msg_from_xycar", String, queue_size =1)
sub = rospy.Subscriber("msg_to_xycar", my_msg, call_back)
rospy.spin()
#!/usr/bin/env python
import rospy
from msg_send.msg import my_msg
from std_msgs.msg import String
done = False
def call_back(data):
print(data.data)
done = True
rospy.init_node('remote_student', anonymous = True)
pub = rospy.Publisher('msg_to_xycar', my_msg, queue_size = 1)
rospy.Subscriber('msg_from_xycar', String, call_back)
rate = rospy.Rate(1)
msg = my_msg()
msg.first_name = "Sanghun"
msg.last_name = "Park"
msg.age = 26
msg.score = 100
msg.id_number = 12345678
msg.phone_number = "010-0000-0000"
while not rospy.is_shutdown() and not done:
pub.publish(msg)
print("sending message...")
rate.sleep()
<launch>
<node pkg ="msg_send" type="remote_teacher.py" name="teacher" output="screen"/>
<node pkg ="msg_send" type="remote_student.py" name="student" output="screen"/>
</launch>