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

Implement shared memory data publishing between nodelets [closed]

asked 2014-12-23 13:05:20 -0500

ajain gravatar image

updated 2014-12-23 17:05:24 -0500

tfoote gravatar image

I have a set of 3 nodelets running which publish and subscribe to topics amongst themselves. To optimize the process I want to use the shared memory functionality for zero-copy data being shared between nodelets through publish and subscribe. I tried following this example. The example uses a very basic data type for std_msgs::String::ConstPtr. I am using a custom defined message and I get a compile time error saying that I cannot assign values to boost::shared_ptr.

For e.g. if my message type is the following (MyMessage.msg)-

Header header
int dataA
string dataB

In my publish method I do something like this -

void publishTopic()
{
    std::string str("my message");
    MyMessage::ConstPtr msg;
    msg->dataA = 5;
    msg->dataB = str;

    myPublisher.publish(msg);
}

Lines msg->dataA = 5 and msg->dataB = str are giving me the errors. I know I'm doing something wrong with how I'm assigning values to pointers, but cannot think of a solution off the top of my head. Any help will be appreciated.

Can you please also refer a documentation for using boost::shared_ptr in ROS if any exists?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ajain
close date 2015-01-05 12:40:03.792973

1 Answer

Sort by » oldest newest most voted
1

answered 2014-12-23 17:12:46 -0500

tfoote gravatar image

Your problem is that you're using const pointers. const pointers cannot be mutated, which is why you are getting errors.

When you are generating a message for publishing it needs to be a standard shared pointer. When you receive it in your callback it will be a const pointer or else it will be copied.

Note: When you publish a message with a shared pointer you're not allowed to modify it after it has been sent as other parts of the process might be accessing it.

For information on boost pointers I suggest the boost documentation: http://www.boost.org/doc/libs/1_57_0/... Or general reference sites like stack overflow: http://stackoverflow.com/questions/56...

edit flag offensive delete link more

Comments

Thanks a lot for a quick answer. It works if I instantiate msg as boost::shared_ptr<MyMessage> msg.

ajain gravatar image ajain  ( 2014-12-23 18:01:01 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-12-23 13:05:20 -0500

Seen: 2,333 times

Last updated: Dec 23 '14