Ask Your Question
1

Replacement for rospy.time.now() 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 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
3

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.

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 imageOwnageManFromLOL ( 2019-04-22 19:33:20 -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

Stats

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

Seen: 154 times

Last updated: Apr 21