How to publish sim time at desired frequency
Hi, I want to run the simulated time at frequency of 1Hz by publishing to the /clock
topic and set rosparam /use_sim_time
to be true/1.
However my following code produce simulated clock at a frequency of few kHz.
If use the commented part, the simulated clock will start at 0 and stops there.
If rosparam /use_sim_time
is not set or set to false, the commented part will work fine. I am guessing that this clock topic is treated as a usual topic published and the rospy.Rate
refers back and use the wall time to time the Rate
object?
rospy.init_node('tmp')
pub = rospy.Publisher('/clock', Clock, queue_size=1)
epoch = rospy.Time(1546300800, 0)
rate = rospy.Rate(1)
clock = rospy.Time()
clock.set(1546300800,0)
rate = rospy.Rate(1)
while not rospy.is_shutdown():
rospy.loginfo('')
epoch += rospy.Duration(1)
pub.publish(epoch)
# rate.sleep()
# rospy.sleep(1)