Ask Your Question

How do you make an /odom node for a physical robot in ros2?(How do you handle time?)

asked 2021-06-10 16:25:45 -0500

rydb gravatar image

updated 2021-06-14 16:01:37 -0500

I am lost on how to do this.

I have scoured the GitHub pages for turtlebot3 and have checked navigation2 tutorial page but turtlebot3 references the /odom topic but doesn't define it and the navigation2 tutorial shows you how publish a /odom topic based off of a gazebo simulated robot, not a physical robot

I've also checked the /odom publishing tutorial for ros1 here, it looks potentially useful, but its throwing a lot of errors when I try to replace the ros1 libraries with their ros2 equivalents. I'm not sure whats changed between ros1 Odom and ros2 Odom, so I'm not sure how to convert it to ros2.

Edit: First problem I've run into is im not sure how to handle time for the /odom node, according to here, I should use "Now" as a part of rclpy, but when i try this in my python node:

class Odom(Node):
    def __init__(self):
        print("placeholder string")

def main():

    odom = Odom()


I get an error, because there is no "Now" for node, and if i try:


I get a different error saying:

AttributeError: 'Odom' object has no attribute '_clock'

I have a feeling that the error relates to here:

but now i'm not sure how to handle making a custom clock for the node, since my robot is physical robot and not a simulated one with simulated time.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-06-10 17:00:22 -0500

It really shouldn't be any different for ROS1 or ROS2 -- the math is the exact same. Its just about using the ROS2 version of the ROS1 toolset to publish that information. Your code sample looks about right -- you need to take your wheel ticks / speed and convert them into relative motion.

You should look at the ROS2 tutorials, there is still a bunch of things that are not converted to ROS2 yet (e.x. anything with namespace ros::), you're not properly name spacing the messages, you're using the TF1 API, etc. All of these things are covered with the basic ROS2 tutorials. I'd drop this task for a couple of days and learn that stuff first and then revisit it once you're more familiar with ROS2.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-06-10 16:25:45 -0500

Seen: 67 times

Last updated: Jun 14