rospy.Time.now() sometimes returns 0.
Hello, I'm trying to run this code:
prevTime = rospy.Time.now()
while not rospy.is_shutdown():
currentTime = rospy.Time.now()
delT = currentTime-prevTime
print("Previous time:",prevTime.to_sec())
print("Current time",currentTime.to_sec())
print("Time:",delT.to_sec())
rate.sleep()
to get the time of the while loop, because I have a function of time that needs it. Sometimes when running this, prevTime becomes 0:
Previous time: 0.0
Current time 1266.097
Time: 1266.097
Previous time: 0.0
Current time 1266.107
Time: 1266.107
Previous time: 0.0
Current time 1266.117
Time: 1266.117
Previous time: 0.0
Current time 1266.127
Time: 1266.127
And other times it works as intended:
Previous time: 1263.221
Current time 1263.321
Time: 0.1
Previous time: 1263.221
Current time 1263.331
Time: 0.11
Previous time: 1263.221
Current time 1263.341
Time: 0.12
Previous time: 1263.221
Current time 1263.351
Time: 0.13
Wondering what the issue could be, and how to stop it from becoming 0
Are you using simulated time?
Yes, running the simluations in Gazebo