This package provides an RTT service and service-requester for associating RTT component properties with ROS parameters.
This RTT service enables both setting/getting individual RTT properties of a given RTT component to/from the ROS parameter server, as well as setting/getting all properties of a component simultaneously. The operations map directly onto operations in the roscpp library, except they only store the retrieved values in RTT properties of the given component.
Using this service requires that the RTT properties of a given component match the names of their associated ROS parameters, modulo the namespace resolution policy (see below).
RELATIVE
Relative resolution:"name"
->"name"
ABSOLUTE
Absolute resolution:"name"
->"/name"
PRIVATE
Private resolution:"name"
->"~name"
COMPONENT
Component resolution:"name"
->"~COMPONENT_NAME/name"
getAll()
orgetAllComponentPrivate()
Attempt to get all properties of this component (and its sub-services) from the ROS parameter server in the COMPONENT namespace.getAllRelative()
Attempt to get all properties of this component (and its sub-services) from the ROS parameter server in the relative namespace.getAllAbsolute()
Attempt to get all properties of this component (and its sub-services) from the ROS parameter server in the absolute namespace.getAllPrivate()
Attempt to get all properties of this component (and its sub-services) from the ROS parameter server in the node's private namespace.
setAll()
orsetAllComponentPrivate()
Stores all properties of this component (and its sub-services) on the ROS parameter server from the similarly-named property in the COMPONENT's private namespace.setAllRelative()
Stores all properties of this component (and its sub-services) on the ROS parameter server from the similarly-named property in the relative namespace.setAllAbsolute()
Stores all properties of this component (and its sub-services) on the ROS parameter server from the similarly-named property in the absolute namespace.setAllPrivate()
Stores all properties of this component (and its sub-services) on the ROS parameter server from the similarly-named property in the node's private namespace.
getParam(ros_name, rtt_name)
Get the ROS paramros_name
and store it in the RTT propertyrtt_name
. Use leaders like~
and/
for private and absolute resolution.get(name ,policy)
Attempt to get the property namedname
(or populates the properties of a named RTT sub-service) from the ROS parameter namespace specified bypolicy
.getRelative(name)
getAbsolute(name)
getPrivate(name)
getComponentPrivate(name)
setParam(ros_name, rtt_name)
Set the ROS paramros_name
from the value in the RTT propertyrtt_name
*. Use leaders like~
and/
for private and absolute resolution.set(name, policy)
Attempt to set the property namedname
(or stores the properties of a named RTT sub-service) in the ROS parameter namespace specified bypolicy
.setRelative(name)
setAbsolute(name)
setPrivate(name)
setComponentPrivate(name)
The following operations of the rosparam
service can be used to create properties
in the owner component that link to ROS parameters. When the properties are
evaluate()
-d through get()
or set()
, the ROS parameter server is queried.
IMPORTANT Setting or getting the value of a ROS parameter through a property is a non real-time safe operation and therefore it shouldn't be used from within a real-time component.
addRosParamProperty_type_(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aRelative
namespace resolution context.addRosParamProperty_type_Relative(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aRelative
namespace resolution context.addRosParamProperty_type_Absolute(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aAbsolute
namespace resolution context.addRosParamProperty_type_Private(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aPrivate
namespace resolution context.addRosParamProperty_type_ComponentPrivate(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aComponentPrivate
namespace resolution context.addRosParamProperty_type_ComponentAbsolute(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aComponentAbsolute
namespace resolution context.addRosParamProperty_type_ComponentRelative(name)
Adds a property of type_type_
with namename
to the owning task context which is linked to the ROS parameter with the same name in aComponentRelative
namespace resolution context.
Components which were never meant to be used with ROS parameters can have their properties set from the ROS parameter server through the scripting interface:
// Import packages
import("rtt_ros")
ros.import("rtt_rosparam")
// Create your components ...
laodService("my_component","rosparam")
// Try to get all parameters from the component namespace "~my_component/..."
my_component.rosparam.getAll()
// Try to get the "robot_description" property from the absolute namespace "/robot_description"
my_component.rosparam.getAbsolute("robot_description")
// Alternatively:
my_component.rosparam.get("robot_description",my_component.rosparam.ABSOLUTE)
// Create a property linked to a ROS parameter
my_component.rosparam.addRosParamPropertyDouble("parameter_double")
my_component.rosparam.addRosParamPropertyStringAbsolute("robot_name")
// Change ROS parameter through Property
my_component.parameter_double = 3.1
my_component.parameter_double = other_component.other_double
var double my_double
my_component.parameter_double = my_double
If your component is designed to be used with ROS parameters, you can also easily access the rosparam service from C++ using an RTT ServiceRequester.
For example, a simple component which gets the "robot_description"
ROS param
from the global namespace ("/robot_description"
) and the "publish_period"
ROS
param from the node's private namespace ("~publish_period"
) would look something
like the following:
// Include the service requester interface
#include <rtt_rosparam/rosparam.h>
class MyComponent : public RTT::TaskContext {
private:
// Storage for RTT properties
std::string robot_description_;
double publish_period_;
public:
MyComponent::MyComponent(std::string &name) : RTT::TaskContext(name) {
// Add some properties
this->addProperty("robot_description",robot_description_);
this->addProperty("publish_period",publish_period_);
// Get the rosparam service requester
boost::shared_ptr<rtt_rosparam::ROSParam> rosparam =
this->getProvider<rtt_rosparam::ROSParam>("rosparam");
if(rosparam) {
// Add some more properties linked to ROS parameters
rosparam->addRosParamPropertyDouble("parameter_double");
}
}
// ...
bool configureHook() {
bool all_params_found = true;
// Get the rosparam service requester
boost::shared_ptr<rtt_rosparam::ROSParam> rosparam =
this->getProvider<rtt_rosparam::ROSParam>("rosparam");
// Get the parameters
if(rosparam) {
// Get the ROS parameter "/robot_description"
all_params_found &= rosparam->getAbsolute("robot_description");
// Get the ROS parameter "~publish_period"
all_params_found &= rosparam->getPrivate("publish_priod");
// Evaluate parameter (updates from)
this->getProperty("parameter_double")->value();
}
return all_params_found;
}
// ...
}
See the API documentation for more information.