Ask Your Question
3

Replacement for rospy.time.now() in ROS2?

asked 2019-04-21 14:13:11 -0600

OwnageManFromLOL gravatar image

In ROS1 if I wanted to publish an Odometry msg I would use rospy.Time.now() to get the current time and publish the odom msg using that time. However, I haven't been able to find anything similar in ROS2? Does anyone know what functionality I can use to get the time for a msg I am publishing in ROS2?

now = rospy.Time.now()
odom = Odometry()
odom.header.frame_id = self._odom_frame
odom.header.stamp = now
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-04-21 19:40:17 -0600

tfoote gravatar image

There's no longer a global instance of the communication library that you can rely on in rclpy.

You need to get a clock instance from your node instance.

my_node.get_clock().now()

More info on the design can be found here: https://design.ros2.org/articles/cloc...

edit flag offensive delete link more

Comments

Hey tfoote thanks for your help :)

OwnageManFromLOL gravatar image OwnageManFromLOL  ( 2019-04-22 19:33:20 -0600 )edit
4

dont forget to add .to_msg() at the end.

another helpful answer

flynneva gravatar image flynneva  ( 2020-06-09 19:59:00 -0600 )edit
1

The .to_msg() is critical!

mschickler gravatar image mschickler  ( 2020-08-26 08:42:23 -0600 )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

1 follower

Stats

Asked: 2019-04-21 14:13:11 -0600

Seen: 1,798 times

Last updated: Apr 21 '19