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

rospy.Time.now() returns 0

asked 2018-08-19 09:10:04 -0500

pitosalas gravatar image
 #! /usr/bin/env python

import rospy
rospy.init_node('h')
print(rospy.Time.now()) => 0

Prints zero? Here is the context

  1. Kinetic
  2. rosparam get /use_sim_time -> true

    $ rostopic info /clock Type: rosgraph_msgs/Clock

    Publishers:

    Subscribers:

edit retag flag offensive close merge delete

Comments

Is Gazebo paused?

gvdhoorn gravatar image gvdhoorn  ( 2018-08-19 13:02:32 -0500 )edit

No, it’s up. Also when I rostopic echo /clock I see the messages go by. Also when I set /use_sim_time to False the same code works.

pitosalas gravatar image pitosalas  ( 2018-08-19 13:38:52 -0500 )edit

Anyone? I am stumped. Thinking that I had corrupted something in my install, i see the same behavior on a different computer altogether.

pitosalas gravatar image pitosalas  ( 2018-08-21 16:57:34 -0500 )edit

3 Answers

Sort by » oldest newest most voted
2

answered 2018-08-24 13:25:31 -0500

fergs gravatar image

I know you've already reinstalled -- but in case someone else (or even you) runs into this later -- it is possible you simply have a race condition. If you put the print() statement in a loop, I imagine your values would start to increase. It is possible that either the python node came up and printed before gazebo really started publishing /clock, or that the print statement happened before the first clock message came in.

I've seen some codebases where the developers explicitly wait until time > 0 before letting the rest of the initialization proceed.

edit flag offensive delete link more

Comments

Interesting information... In my case I just extracted that code sample to show the problem starkly but it was actually in a loop and I did wait a while. I also did see some kind of weird behavior as I toggled /use_simtime and watched what happened.

pitosalas gravatar image pitosalas  ( 2018-08-24 20:12:40 -0500 )edit

It appears rospy.sleep(0.0) works (at least in noetic), at least a single clock message has to arrive to return from that sleep.

lucasw gravatar image lucasw  ( 2021-10-28 18:23:38 -0500 )edit
0

answered 2018-08-22 07:27:53 -0500

pitosalas gravatar image

Sad to say, I had to uninstall all of ROS, delete all the state that I could find, and then reinstall. Pretty delicate creature.

edit flag offensive delete link more
0

answered 2022-10-30 12:38:51 -0500

bmgatten gravatar image

If you're using system time and replaying a bagfile you'll need to make sure that /clock has been recorded (otherwise set use_sim_time to false) .

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-08-19 09:10:04 -0500

Seen: 2,648 times

Last updated: Oct 30 '22