Search code examples
pythonc++ros

How do I use positional argument to initialize Pose from geometry_msgs of ROS?


In the documentation, it says that I can initialize with "complete set of field values, in .msg order".

What does this mean? And how do I implement it in Python and C++?


Solution

  • This simply means you can pass __init__ arguments in the order they appear in the .msg file. You would find the exact definition in the geometry_msgs Pose docs here. This is more typically seen as a python paradigm, and uses the * unpacking operator. Such as the following example:

    def unpacking_func(*args):
        print(f'I was passed {len(args)} items, they are: ')
        for item in args:
            print(item)
    unpacking_func('first', 'second', 'third')
    

    A specific example for the Pose you linked would look like this:

    # NOTE: These are just empty values
    position = geometry_msgs.Point()
    quaternion = geometry_msgs.Quaternion()
    pose = geometry_msgs.Pose(position, quaternion)
    

    As a final point I'd note that you linked Diamondback docs, which has been EOL for a long time. This should all hold true for newer distros, but obviously there's no guarantee.