6 #include <boost/utility/enable_if.hpp> 7 #include <boost/type_traits/is_convertible.hpp> 11 #include <Eigen/Dense> 17 #ifndef ADD_ROSPARAM_OPERATION 18 #define ADD_ROSPARAM_OPERATION(return_type_str, return_type, func) \ 19 this->addOperation("get"#return_type_str, &ROSParamService::get##func< return_type , RELATIVE >, this).doc("Get a " #return_type " from rosparam"); \ 20 this->addOperation("set"#return_type_str, &ROSParamService::set##func< return_type , RELATIVE >, this).doc("Set a " #return_type " in rosparam"); \ 21 this->addOperation("get"#return_type_str"Relative", &ROSParamService::get##func< return_type , RELATIVE >, this).doc("Get a " #return_type " from rosparam using the relative resolution policy : `relative/param`"); \ 22 this->addOperation("set"#return_type_str"Relative", &ROSParamService::set##func< return_type , RELATIVE >, this).doc("Set a " #return_type " in rosparam using the relative resolution policy : `relative/param`"); \ 23 this->addOperation("get"#return_type_str"Absolute", &ROSParamService::get##func< return_type , ABSOLUTE >, this).doc("Get a " #return_type " from rosparam using the absolute resolution policy : `/global/param`"); \ 24 this->addOperation("set"#return_type_str"Absolute", &ROSParamService::set##func< return_type , ABSOLUTE >, this).doc("Set a " #return_type " in rosparam using the absolute resolution policy : `/global/param`"); \ 25 this->addOperation("get"#return_type_str"Private", &ROSParamService::get##func< return_type , PRIVATE >, this).doc("Get a " #return_type " from rosparam using the private resolution policy : `~private/param`"); \ 26 this->addOperation("set"#return_type_str"Private", &ROSParamService::set##func< return_type , PRIVATE >, this).doc("Set a " #return_type " in rosparam using the private resolution policy : `~private/param`"); \ 27 this->addOperation("get"#return_type_str"ComponentPrivate", &ROSParamService::get##func< return_type , COMPONENT_PRIVATE >, this).doc("Get a " #return_type " from rosparam using the following resolution policy : `~component_name/param`"); \ 28 this->addOperation("set"#return_type_str"ComponentPrivate", &ROSParamService::set##func< return_type , COMPONENT_PRIVATE >, this).doc("Set a " #return_type " in rosparam using the following resolution policy : `~component_name/param`"); \ 29 this->addOperation("get"#return_type_str"ComponentRelative", &ROSParamService::get##func< return_type , COMPONENT_RELATIVE >, this).doc("Get a " #return_type " from rosparam using the following resolution policy : `component_name/param`"); \ 30 this->addOperation("set"#return_type_str"ComponentRelative", &ROSParamService::set##func< return_type , COMPONENT_RELATIVE >, this).doc("Set a " #return_type " in rosparam using the following resolution policy : `component_name/param`"); \ 31 this->addOperation("get"#return_type_str"ComponentAbsolute", &ROSParamService::get##func< return_type , COMPONENT_ABSOLUTE >, this).doc("Get a " #return_type " from rosparam using the following resolution policy : `/component_name/param`"); \ 32 this->addOperation("set"#return_type_str"ComponentAbsolute", &ROSParamService::set##func< return_type , COMPONENT_ABSOLUTE >, this).doc("Set a " #return_type " in rosparam using the following resolution policy : `/component_name/param`"); 48 this->doc(
"RTT Service for synchronizing ROS parameters with the properties of a corresponding RTT component");
59 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the relative namespace.");
61 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the absolute namespace.");
63 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the node's private namespace.");
65 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's private namespace.");
67 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's relative namespace.");
69 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's absolute namespace.");
71 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's private namespace. This is an alias for getAllComponentPrivate().");
74 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the relative namespace.");
76 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the absolute namespace.");
78 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the node's private namespace.");
80 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the component's private namespace.");
82 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the component's relative namespace.");
84 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the component's absolute namespace.");
86 .doc(
"Stores all properties of this component (and its sub-services) on the ROS param server from the similarly-named property in the component's private namespace. This is an alias for setAllComponentPrivate().");
89 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server based on the given resolution policy.")
90 .arg(
"name",
"Name of the property / service / parameter.")
91 .arg(
"policy",
"ROS parameter namespace resolution policy.");
93 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server based on the given ROS parameter name.")
94 .arg(
"param_name",
"Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution.")
95 .arg(
"name",
"Name of the RTT property or service.");
98 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the relative namespace.")
99 .arg(
"name",
"Name of the property / service / parameter.");
101 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the absolute namespace.")
102 .arg(
"name",
"Name of the property / service / parameter.");
104 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the node's private namespace.")
105 .arg(
"name",
"Name of the property / service / parameter.");
107 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the component's private namespace.")
108 .arg(
"name",
"Name of the property / service / parameter.");
110 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the component's relative namespace.")
111 .arg(
"name",
"Name of the property / service / parameter.");
113 .doc(
"Gets one property of this component (or populates the properties of a named RTT sub-service) from the ROS param server in the component's absolute namespace.")
114 .arg(
"name",
"Name of the property / service / parameter.");
117 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the ROS parameter namespace based on the given resolution policy.")
118 .arg(
"name",
"Name of the property / service / parameter.")
119 .arg(
"policy",
"ROS parameter namespace resolution policy.");
121 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the ROS parameter namespace based on the given ROS parameter name.")
122 .arg(
"param_name",
"Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution.")
123 .arg(
"name",
"Name of the RTT property or service.");
126 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the relative namespace.")
127 .arg(
"name",
"Name of the property / service / parameter.");
129 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the absolute namespace.")
130 .arg(
"name",
"Name of the property / service / parameter.");
132 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the node's private namespace.")
133 .arg(
"name",
"Name of the property / service / parameter.");
135 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the component's private namespace.")
136 .arg(
"name",
"Name of the property / service / parameter.");
138 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the component's relative namespace.")
139 .arg(
"name",
"Name of the property / service / parameter.");
141 .doc(
"Sets one parameter on the ROS param server from the similarly-named property of this component (or stores the properties of a named RTT sub-service) in the component's absolute namespace.")
142 .arg(
"name",
"Name of the property / service / parameter.");
164 template <
typename T, ResolutionPolicy P>
bool getParamImpl(
const std::string& ros_param_name, T& value)
173 template <
typename T, ResolutionPolicy P>
void setParamImpl(
const std::string& ros_param_name,
const T& value)
178 template <
typename T, ResolutionPolicy P>
bool getEigenVectorParamImpl(
const std::string& ros_param_name, Eigen::Matrix<T,Eigen::Dynamic,1>& eigen_vector)
180 std::vector<T> value;
181 if (!getParamImpl< std::vector<T> , P >(ros_param_name,value)) {
184 eigen_vector = Eigen::Matrix<T,Eigen::Dynamic,1>::Map(value.data(),value.size());
188 template <
typename T, ResolutionPolicy P>
void setEigenVectorParamImpl(
const std::string& ros_param_name,
const Eigen::Matrix<T,Eigen::Dynamic,1>& eigen_vector)
190 std::vector<T> value(eigen_vector.data(),eigen_vector.data() + eigen_vector.size() );
191 setParamImpl< std::vector<T> , P >(ros_param_name,value);
195 const std::string resolvedName(
196 const std::string ¶m_name,
209 const std::string ¶m_name,
212 const std::string &ros_name,
213 const std::string &rtt_name);
231 const std::string ¶m_name,
234 const std::string &ros_name,
235 const std::string &rtt_name);
245 const std::string ¶m_name,
248 std::string leader =
"";
249 std::string resolved_name =
"";
251 if(param_name.length() > 0) {
252 leader = param_name[0];
257 resolved_name = param_name;
260 resolved_name = (leader ==
"/") ? param_name : std::string(
"/") + param_name;
263 resolved_name = (leader ==
"~") ? param_name : std::string(
"~") + param_name;
276 RTT::log(
RTT::Debug) <<
"["<<this->getOwner()->getName()<<
"] Resolving ROS param \""<<param_name<<
"\" to \""<<resolved_name<<
"\"" <<
RTT::endlog();
278 return resolved_name;
344 for(RTT::PropertyBag::Properties::const_iterator it = properties.begin();
345 it != properties.end();
360 for(
unsigned i=0; i<vec.size(); i++) {
361 xml_array[i] = rttPropertyToXmlParam<T>(vec.at(i));
373 for(
unsigned i=0; i<vec.size(); i++) {
374 xml_array[i] = rttPropertyToXmlParam<double>(vec(i));
386 for(
unsigned i=0; i<vec.size(); i++) {
387 xml_array[i] = rttPropertyToXmlParam<double>(vec(i));
395 #define RETURN_RTT_PROPERTY_TO_XML_PARAM(type,prop)\ 396 if(castable< type >(prop)) { return rttPropertyToXmlParam< type >(static_cast<const RTT::Property< type >*>(prop)->rvalue()); } 398 #define RETURN_RTT_PROPERTY_CONTAINER_TO_XML_PARAM(type,elem_type,prop)\ 399 if(castable< type >(prop)) { return rttPropertyToXmlParam< elem_type >(static_cast<const RTT::Property< type >*>(prop)->rvalue()); } 440 const std::string ¶m_name,
441 const unsigned int policy)
445 const std::string resolved_name = resolvedName(param_name,
ResolutionPolicy(policy));
447 return this->setParam(resolved_name, param_name);
451 const std::string &ros_name,
452 const std::string &rtt_name)
470 return setParams(service, ros_name);
479 return setParams(this->getOwner()->provides(), resolvedName(std::string(), policy));
484 const std::string& ns) {
491 for (RTT::Service::ProviderNames::const_iterator it = names.begin(); it != names.end(); ++it)
520 template <
class XMLRPCType,
class PropertyType,
class enabled=
void>
struct XmlParamToValue{
521 static bool assign(
const XMLRPCType& xml_value, PropertyType &prop_value)
527 template <
class XMLRPCType,
class PropertyType >
528 struct XmlParamToValue <XMLRPCType, PropertyType, typename
boost::enable_if<boost::is_convertible<XMLRPCType,PropertyType> >::type >{
529 static bool assign(
const XMLRPCType& xml_value, PropertyType &prop_value)
531 prop_value = xml_value;
582 std::vector<T> &vec = prop->
value();
583 vec.resize(xml_value.
size());
585 for(
size_t i=0; i<vec.size(); i++) {
608 std::vector<bool> &vec = prop->
value();
609 vec.resize(xml_value.
size());
611 for(
size_t i=0; i<vec.size(); i++) {
636 Eigen::VectorXd &vec = prop->
value();
637 vec.resize(xml_value.
size());
639 for(
size_t i=0; i<vec.size(); i++) {
664 Eigen::VectorXf &vec = prop->
value();
665 vec.resize(xml_value.
size());
667 for(
size_t i=0; i<vec.size(); i++) {
677 bool xmlParamToProp<RTT::PropertyBag>(
695 for(XmlRpc::XmlRpcValue::ValueStruct::iterator it = xml_value_struct.
begin();
696 it != xml_value_struct.
end();
782 const std::string ¶m_name,
783 const unsigned int policy)
787 const std::string resolved_name = resolvedName(
790 return this->getParam(resolved_name, param_name);
794 const std::string &ros_name,
795 const std::string &rtt_name)
823 return getParams(service, ros_name);
839 return getParams(this->getOwner()->provides(), resolvedName(std::string(), policy));
844 const std::string& ns)
870 for (RTT::Service::ProviderNames::const_iterator it = names.begin(); it != names.end(); ++it)
874 std::string sub_ns = sub->getName();
876 getParams(sub, sub_ns);
static bool assign(const XMLRPCType &xml_value, PropertyType &prop_value)
bool getParamsComponentAbsolute()
const std::string & getMessage() const
ROSParamService(TaskContext *owner)
void setEigenVectorParamImpl(const std::string &ros_param_name, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &eigen_vector)
bool getParamAbsolute(const std::string &name)
XmlRpc::XmlRpcValue rttPropertyToXmlParam< char >(const char &prop)
bool propertyDecomposition(base::PropertyBase *source, PropertyBag &targetbag, bool recurse)
Component resolution: "name" -> "COMPONENT_NAME/name".
bool setParamsComponentAbsolute()
std::string getName(void *handle)
#define ORO_SERVICE_NAMED_PLUGIN(SERVICE, NAME)
XmlRpc::XmlRpcValue rttPropertyToXmlParam(const T &prop)
Convert a value to an XmlRpc value.
bool getParamComponentPrivate(const std::string &name)
bool xmlParamToProp< bool >(const XmlRpc::XmlRpcValue &xml_value, RTT::Property< std::vector< bool > > *prop)
bool getParamsComponentRelative()
std::vector< std::string > ProviderNames
Type const & getType() const
const std::string resolvedName(const std::string ¶m_name, const ResolutionPolicy policy)
Resolve a parameter name based on the given ResolutionPolicy.
Absolute resolution: "name" -> "/name".
bool setParamsComponentRelative()
bool set(const std::string ¶m_name, const unsigned int policy=(unsigned int) COMPONENT_PRIVATE)
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
bool getParamsComponentPrivate()
bool getParamPrivate(const std::string &name)
std::map< std::string, XmlRpcValue > ValueStruct
bool setParams(RTT::Service::shared_ptr service, const std::string &ns)
XmlRpc::XmlRpcValue rttPropertyToXmlParam< unsigned int >(const unsigned int &prop)
static bool assign(const XMLRPCType &xml_value, PropertyType &prop_value)
bool setParamPrivate(const std::string &name)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define RETURN_RTT_PROPERTY_CONTAINER_TO_XML_PARAM(type, elem_type, prop)
bool getParamImpl(const std::string &ros_param_name, T &value)
bool castable(const RTT::base::PropertyBase *prop)
Determine if the RTT property can be casted into an RTT::Property<T>
bool setParamsComponentPrivate()
XmlRpc::XmlRpcValue rttPropertyBaseToXmlParam(RTT::base::PropertyBase *prop)
Convert an abstract RTT PropertyBase to an XmlRpc value.
bool setParamComponentPrivate(const std::string &name)
bool getParamComponentAbsolute(const std::string &name)
bool get(const std::string ¶m_name, const unsigned int policy=(unsigned int) COMPONENT_PRIVATE)
bool xmlParamToValue(const XmlRpc::XmlRpcValue &xml_value, PropertyType &value)
Convert an XmlRpc value to type T.
bool xmlParamToProp(const XmlRpc::XmlRpcValue &xml_value, RTT::Property< T > *prop)
Convert an XmlRpc value into an RTT property.
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
bool getParamRelative(const std::string &name)
bool setParamAbsolute(const std::string &name)
bool getParam(const std::string &ros_name, const std::string &rtt_name)
Relative resolution: "name" -> "name".
XmlRpc::XmlRpcValue rttPropertyToXmlParam< float >(const float &prop)
bool setParam(const std::string &ros_name, const std::string &rtt_name)
Private resolution: "name" -> "~name".
bool setParamRelative(const std::string &name)
bool getEigenVectorParamImpl(const std::string &ros_param_name, Eigen::Matrix< T, Eigen::Dynamic, 1 > &eigen_vector)
const std::string & getName() const
XmlRpc::XmlRpcValue rttPropertyToXmlParam< unsigned char >(const unsigned char &prop)
bool getParamComponentRelative(const std::string &name)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
#define RETURN_RTT_PROPERTY_TO_XML_PARAM(type, prop)
bool setParamComponentAbsolute(const std::string &name)
bool getParams(RTT::Service::shared_ptr service, const std::string &ns)
#define ADD_ROSPARAM_OPERATION(return_type_str, return_type, func)
static Logger::LogFunction endlog()
Component resolution: "name" -> "~COMPONENT_NAME/name".
bool setParamComponentRelative(const std::string &name)
std::vector< base::PropertyBase * > Properties
void setParamImpl(const std::string &ros_param_name, const T &value)
Component resolution: "name" -> "/COMPONENT_NAME/name".