Ask Your Question

Using the orocos/rtt rosparam service in c++

asked 2012-04-18 15:34:08 -0500

jbohren gravatar image

I'd like to use the rtt_ros_integration rosparam service from within one of my own components in c++. The only documentation I can find for accessing the interface of a service plugin through c++ requires that the service has a class declaration in some header that can be included:

Is there a way to do this by leveraging the rtt operations defined in rtt_rosparam_service.cpp?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-04-18 15:58:39 -0500

psoetens gravatar image

updated 2012-04-18 15:59:23 -0500

What you need to do for this particular service is to first load the service:

// In your TaskContext subclass:
PluginLoader::Instance()->loadService("rosparam", this);

And then you could dynamic_cast the service pointer:

boost::shared_ptr<RosParam> rp = boost::dynamic_pointer_cast<RosParam>( this->provides("rosparam") );

rp->storeProperties(); // etc.

UNFORTUNATELY, this service was implemented fully in the .cpp file, so no header is available. What you can do, if you don't want to submit a patch which creates a nice hpp/cpp file and installs the hpp, you can write this as a workaround:

OperationCaller<bool(void)> storeProperties = this->provides("rosparam")->getOperation("storeProperties");

storeProperties(); // calls the Service's Operation.


edit flag offensive delete link more


Ahh! I see. After loading the plugin, I was trying this->requires("rosparam")->getOperation("storeProperties"). Thanks!

jbohren gravatar image jbohren  ( 2012-04-18 16:03:34 -0500 )edit

answered 2016-08-18 21:48:48 -0500

In my case, I used a simpler method to require the service.

// Within TaskContext class
if (this->loadService("rosparam"))
OperationCaller<bool(void)> storeProperties = this->provides("rosparam")->getOperation("storeProperties");

The benefit is that my code can try to load the service more than one time if it fails at the beginning.

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: 2012-04-18 15:34:08 -0500

Seen: 564 times

Last updated: Apr 18 '12