rospy.get_rostime() always return 0 out of while True loop

asked 2019-06-26 22:17:31 -0500

baxmay gravatar image

when I place rospy.get_rostime() in while loop like this

while True:
    print(rospy.get_rostime())

I get the result like this:

...
1120344000000
1120344000000
1120344000000
1120344000000
1120344000000
1120344000000
1120345000000
1120345000000
1120345000000
1120345000000
...

but when I change it to

i = 0
while i in xrange(10):
    print(rospy.get_rostime())
    i = i + 1

it returns

...
0
0
0
0
0
0
0
0
0
0
...

why??

edit retag flag offensive close merge delete

Comments

Please show us all of the code. rospy.get_rostime() can return 0, fi when you haven't called rospy.init_node().

gvdhoorn gravatar image gvdhoorn  ( 2019-06-27 02:00:16 -0500 )edit

That's all the code. Another two line above it is: import rospy and rospy.init_node("something") which is fundamental or else where is the result came from?? Another thing is if I don't call rospy.init_node("something") it will not return zero btw but it will ask wheretf is my rospy.init_node()

baxmay gravatar image baxmay  ( 2019-06-27 02:19:38 -0500 )edit

If that is all the code then I'm not surprised it doesn't work. You must initialise time properly, which is done when rospy.init_node(..) is called.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-27 02:29:06 -0500 )edit