Ask Your Question

Replacement for in ROS2?

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

OwnageManFromLOL gravatar image

In ROS1 if I wanted to publish an Odometry msg I would use 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 =
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

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

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.


More info on the design can be found here:

edit flag offensive delete link more


Hey tfoote thanks for your help :)

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

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

another helpful answer

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

The .to_msg() is critical!

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


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

Seen: 4,423 times

Last updated: Apr 21 '19