I am having an issue figuring out how to write a publisher node (ROS Python) that will send the subscriber the actual time (IE: 12:46) which I need to do for my homework. I need to publish the actual time, so that the subscriber can use that time, and a difference in time requested through a service to calculate the time somewhere else in the world. (Ie: Node1 publishes time in New York, Node2 subscribes and requests the time difference between current location-New York- and London. Node1 sends the information on the time difference to Node2. Node2 takes current time and time difference and adds them to find out the current time in London)
I have googled the issue and I cannot find any helpful information. I have found some confusing sources that say how to get the simulated time in seconds, and (maybe) the clock time in seconds, but I did not really understand what they were saying enough to use the information.
code that I have so far: Sorry, IDK how to format it right on this website
#!/usr/bin/env python
from beginner_tutorials.srv import TimeDiff, TimeDifResponse
from std_msgs.msg import Time
import rospy
pub = rospy.Publisher('currentTime', Time, queue_size=10)
CurrentTime= localtime()
def setupPublisher():
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(5) # 5hz
while not rospy.is_shutdown():
global CurrentTime
CurrentTime= localtime()
pub.publish(CurrentTime)
rate.sleep()
if __ name __ == "__ main __":
setupPublisher()
I don't really have any code to share because I don't know how to incorporate the time. This is what I have so far, but I don't think it's right
It should publish the time to the subscriber, but I have no idea what it is doing, or what variables I should be using, or anything for that matter. We didn't learn about this in class at all.