Robotics StackExchange | Archived questions

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

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??

Asked by baxmay on 2019-06-26 22:17:31 UTC

Comments

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

Asked by gvdhoorn on 2019-06-27 02:00:16 UTC

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()

Asked by baxmay on 2019-06-27 02:19:38 UTC

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.

Asked by gvdhoorn on 2019-06-27 02:29:06 UTC

Answers