ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ptr suffix in ROS messages

asked 2019-09-28 05:34:43 -0500

thanasis_t gravatar image

Hello,

I would like to know if i could get an object of message X when I have an object of message XPtr. For example, if I have an object of type geometry_msgs::PosePtr, is it possible to get an object of type geometry_msgs::Pose? Furthermore, what is the difference between geometry_msgs::Pose* and geometry_msgs::PosePtr? Thanks a lot in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-09-29 07:55:14 -0500

You you can definitely make a concrete message type from a <Message>Ptr type. Because the original type is a pointer you'll need to copy the entire message to do this, fine for small geometry messages but it will have a performance penalty for larger point cloud or image message types. You can use the copy constructor to create a local concrete instance of a message which is the same as a given <Message>Ptr type. This is the same as if if was a regular C++ pointer.

void myFunction(geometry_msgs::PosePtr postMsg)
{
    geometry_msgs::Pose concretePose = *poseMsg;

    // ... do something with concretePose 
}

Regarding your second point the geometry_msgs::PosePtr is actually a boost::shared_ptr<geometry_msgs::Pose> not a simple C++ pointer. A Boost shared pointer is a smart pointer container that ensures memory will always deleted when no more references to the object exist. You can read more about these here.

Hope this helps.

edit flag offensive delete link more

Comments

Yes your comment was very helpful. Thanks a lot.

thanasis_t gravatar image thanasis_t  ( 2019-09-29 08:23:40 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-09-28 05:34:43 -0500

Seen: 633 times

Last updated: Sep 29 '19