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

why rospy time always prining zero?

asked 2016-06-16 12:04:47 -0500

anilmullapudi gravatar image

I need a time while running the simulation, but in my code returns zero time.

print rospy.get_time(); #output 0

print rospy.Time.now(); #output 0.0

but i see the time in terminal when i run rostopic echo /clock

Am i doing anything wrong while reading time?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-06-16 12:06:51 -0500

updated 2016-06-16 12:53:35 -0500

Did you initialize the ros node?

rospy.init_node("mynodename")

The typical approach to get the current time is:

now = rospy.Time.now()

If you are using some kind of simulation you also have to take into account how the use_sim_time parameter influence to the behavior of the rospy.Time. Have a look to: http://wiki.ros.org/Clock

edit flag offensive delete link more

Comments

yes, node was already initialized. still same issue

anilmullapudi gravatar image anilmullapudi  ( 2016-06-16 12:13:16 -0500 )edit

May be the use_sim_time param set to true? can you check what you get from the following command line: rosparam get /use_sim_time

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2016-06-16 12:43:50 -0500 )edit

Yes, the simulation is running. And the command rosparam get /use_sim_time is giving output true.

anilmullapudi gravatar image anilmullapudi  ( 2016-06-16 13:29:05 -0500 )edit

rospy.Time.now() is working now after setting the use_sim_true param to false in launch file.

anilmullapudi gravatar image anilmullapudi  ( 2016-06-16 13:47:57 -0500 )edit

if this answer solved your question, please mark it as solved.

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2016-06-16 14:54:10 -0500 )edit

Why setting that to false would help? And how do you set it to false?

Kansai gravatar image Kansai  ( 2021-03-07 07:12:32 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-16 12:04:47 -0500

Seen: 2,110 times

Last updated: Jun 16 '16