Ask Your Question
0

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 imagegvdhoorn ( 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 imagepitosalas ( 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 imagepitosalas ( 2018-08-21 16:57:34 -0500 )edit

2 Answers

Sort by » oldest newest most voted
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
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 imagepitosalas ( 2018-08-24 20:12:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 421 times

Last updated: Aug 24 '18