ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

yk6's profile - activity

2020-01-08 03:15:47 -0500 marked best answer 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)
2019-07-10 08:18:19 -0500 received badge  Famous Question (source)
2019-07-10 08:18:19 -0500 received badge  Notable Question (source)
2019-07-10 08:18:19 -0500 received badge  Popular Question (source)
2019-03-12 03:09:26 -0500 received badge  Enthusiast
2019-03-12 03:09:26 -0500 received badge  Enthusiast
2019-03-12 03:09:26 -0500 received badge  Enthusiast
2019-03-04 04:43:47 -0500 received badge  Supporter
2019-03-04 04:39:24 -0500 answered a question How to publish sim time at desired frequency

Use python's time module to control the frequency by adding import time and add time.sleep(1.0) in the while loop

2019-03-03 09:46:50 -0500 answered a question Creating a node which contains both a subscriber and publisher with Python Class

Some googled answer looks like may solve your problem https://answers.ros.org/question/229894/publisher-and-subscriber-

2019-03-03 00:41:56 -0500 asked a question How to publish sim time at desired frequency

How to publish sim time at desired frequency Hi, I want to run the simulated time at frequency of 1Hz by publishing to t