7 #include <boost/lexical_cast.hpp> 8 #include <boost/utility/enable_if.hpp> 9 #include <boost/type_traits/is_convertible.hpp> 13 #include <Eigen/Dense> 20 #ifndef ADD_ROSPARAM_OPERATION 21 #define ADD_ROSPARAM_OPERATION(return_type_str, return_type, func) \ 22 this->addOperation("get"#return_type_str, &ROSParamService::get##func< return_type , RELATIVE >, this).doc("Get a " #return_type " from rosparam"); \ 23 this->addOperation("set"#return_type_str, &ROSParamService::set##func< return_type , RELATIVE >, this).doc("Set a " #return_type " in rosparam"); \ 24 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`"); \ 25 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`"); \ 26 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`"); \ 27 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`"); \ 28 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`"); \ 29 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`"); \ 30 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`"); \ 31 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`"); \ 32 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`"); \ 33 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`"); \ 34 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`"); \ 35 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`"); 38 #ifndef ADD_ROSPARAM_PROPERTY_OPERATION 39 #define ADD_ROSPARAM_PROPERTY_OPERATION(return_type_str, return_type, func) \ 40 this->addOperation("addRosParamProperty"#return_type_str, &ROSParamService::addRosParamProperty<return_type, RELATIVE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 41 this->addOperation("addRosParamProperty"#return_type_str"Relative", &ROSParamService::addRosParamProperty<return_type, RELATIVE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 42 this->addOperation("addRosParamProperty"#return_type_str"Absolute", &ROSParamService::addRosParamProperty<return_type, ABSOLUTE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 43 this->addOperation("addRosParamProperty"#return_type_str"Private", &ROSParamService::addRosParamProperty<return_type, PRIVATE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 44 this->addOperation("addRosParamProperty"#return_type_str"ComponentPrivate", &ROSParamService::addRosParamProperty<return_type, COMPONENT_PRIVATE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 45 this->addOperation("addRosParamProperty"#return_type_str"ComponentRelative", &ROSParamService::addRosParamProperty<return_type, COMPONENT_RELATIVE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); \ 46 this->addOperation("addRosParamProperty"#return_type_str"ComponentAbsolute", &ROSParamService::addRosParamProperty<return_type, COMPONENT_ABSOLUTE>, this).doc("Adds a Property to the owner component that is linked to a ROS property of the same name").arg("name", "name of the ROS parameter, the property generated will use the same name"); 62 this->doc(
"RTT Service for synchronizing ROS parameters with the properties of a corresponding RTT component");
73 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the relative namespace.");
75 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the absolute namespace.");
77 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the node's private namespace.");
79 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's private namespace.");
81 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's relative namespace.");
83 .doc(
"Gets all properties of this component (and its sub-services) from the ROS param server in the component's absolute namespace.");
85 .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().");
88 .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.");
90 .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.");
92 .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.");
94 .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.");
96 .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.");
98 .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.");
100 .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().");
103 .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.")
104 .arg(
"name",
"Name of the property / service / parameter.")
105 .arg(
"policy",
"ROS parameter namespace resolution policy.");
107 .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.")
108 .arg(
"param_name",
"Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution.")
109 .arg(
"name",
"Name of the RTT property or service.");
112 .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.")
113 .arg(
"name",
"Name of the property / service / parameter.");
115 .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.")
116 .arg(
"name",
"Name of the property / service / parameter.");
118 .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.")
119 .arg(
"name",
"Name of the property / service / parameter.");
121 .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.")
122 .arg(
"name",
"Name of the property / service / parameter.");
124 .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.")
125 .arg(
"name",
"Name of the property / service / parameter.");
127 .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.")
128 .arg(
"name",
"Name of the property / service / parameter.");
131 .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.")
132 .arg(
"name",
"Name of the property / service / parameter.")
133 .arg(
"policy",
"ROS parameter namespace resolution policy.");
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 ROS parameter namespace based on the given ROS parameter name.")
136 .arg(
"param_name",
"Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution.")
137 .arg(
"name",
"Name of the RTT property or service.");
140 .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.")
141 .arg(
"name",
"Name of the property / service / parameter.");
143 .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.")
144 .arg(
"name",
"Name of the property / service / parameter.");
146 .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.")
147 .arg(
"name",
"Name of the property / service / parameter.");
149 .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.")
150 .arg(
"name",
"Name of the property / service / parameter.");
152 .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.")
153 .arg(
"name",
"Name of the property / service / parameter.");
155 .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.")
156 .arg(
"name",
"Name of the property / service / parameter.");
188 template <
typename T, ResolutionPolicy P>
bool getParamImpl(
const std::string& ros_param_name, T& value)
197 template <
typename T, ResolutionPolicy P>
void setParamImpl(
const std::string& ros_param_name,
const T& value)
202 template <
typename T, ResolutionPolicy P>
bool getEigenVectorParamImpl(
const std::string& ros_param_name, Eigen::Matrix<T,Eigen::Dynamic,1>& eigen_vector)
204 std::vector<T> value;
205 if (!getParamImpl< std::vector<T> , P >(ros_param_name,value)) {
208 eigen_vector = Eigen::Matrix<T,Eigen::Dynamic,1>::Map(value.data(),value.size());
212 template <
typename T, ResolutionPolicy P>
void setEigenVectorParamImpl(
const std::string& ros_param_name,
const Eigen::Matrix<T,Eigen::Dynamic,1>& eigen_vector)
214 std::vector<T> value(eigen_vector.data(),eigen_vector.data() + eigen_vector.size() );
215 setParamImpl< std::vector<T> , P >(ros_param_name,value);
219 const std::string resolvedName(
220 const std::string ¶m_name,
233 const std::string ¶m_name,
236 const std::string &ros_name,
237 const std::string &rtt_name);
255 const std::string ¶m_name,
258 const std::string &ros_name,
259 const std::string &rtt_name);
277 template<
typename T, ResolutionPolicy P>
279 const std::string resolved_name = resolvedName(name,P);
281 Property<T>* p =
new Property<T>(name,
"Property generated by rosparam attached to parameter: " + resolved_name, datasource);
282 this->getOwner()->properties()->ownProperty( p );
289 const std::string ¶m_name,
292 std::string leader =
"";
293 std::string resolved_name =
"";
295 if(param_name.length() > 0) {
296 leader = param_name[0];
301 resolved_name = param_name;
304 resolved_name = (leader ==
"/") ? param_name : std::string(
"/") + param_name;
307 resolved_name = (leader ==
"~") ? param_name : std::string(
"~") + param_name;
320 RTT::log(
RTT::Debug) <<
"["<<this->getOwner()->getName()<<
"] Resolving ROS param \""<<param_name<<
"\" to \""<<resolved_name<<
"\"" <<
RTT::endlog();
322 return resolved_name;
388 for(RTT::PropertyBag::Properties::const_iterator it = properties.begin();
389 it != properties.end();
404 for(
unsigned i=0; i<vec.size(); i++) {
405 xml_array[i] = rttPropertyToXmlParam<T>(vec.at(i));
417 for(
unsigned i=0; i<vec.size(); i++) {
418 xml_array[i] = rttPropertyToXmlParam<double>(vec(i));
430 for(
unsigned i=0; i<vec.size(); i++) {
431 xml_array[i] = rttPropertyToXmlParam<double>(vec(i));
450 xml_array.setSize(size->
get());
452 for (
int i=0; i<size->
get(); i++) {
461 #define RETURN_RTT_PROPERTY_TO_XML_PARAM(type,prop)\ 462 if(castable< type >(prop)) { return rttPropertyToXmlParam< type >(static_cast<const RTT::Property< type >*>(prop)->rvalue()); } 464 #define RETURN_RTT_PROPERTY_CONTAINER_TO_XML_PARAM(type,elem_type,prop)\ 465 if(castable< type >(prop)) { return rttPropertyToXmlParam< elem_type >(static_cast<const RTT::Property< type >*>(prop)->rvalue()); } 510 const std::string ¶m_name,
511 const unsigned int policy)
515 const std::string resolved_name = resolvedName(param_name,
ResolutionPolicy(policy));
517 return this->setParam(resolved_name, param_name);
521 const std::string &ros_name,
522 const std::string &rtt_name)
540 return setParams(service, ros_name);
549 return setParams(this->getOwner()->provides(), resolvedName(std::string(), policy));
554 const std::string& ns) {
561 for (RTT::Service::ProviderNames::const_iterator it = names.begin(); it != names.end(); ++it)
590 template <
class XMLRPCType,
class PropertyType,
class enabled=
void>
struct XmlParamToValue{
591 static bool assign(
const XMLRPCType& xml_value, PropertyType &prop_value)
597 template <
class XMLRPCType,
class PropertyType >
598 struct XmlParamToValue <XMLRPCType, PropertyType, typename
boost::enable_if<boost::is_convertible<XMLRPCType,PropertyType> >::type >{
599 static bool assign(
const XMLRPCType& xml_value, PropertyType &prop_value)
601 prop_value = xml_value;
652 std::vector<T> &vec = prop->
value();
653 vec.resize(xml_value.
size());
655 for(
size_t i=0; i<vec.size(); i++) {
678 std::vector<bool> &vec = prop->
value();
679 vec.resize(xml_value.
size());
681 for(
size_t i=0; i<vec.size(); i++) {
706 Eigen::VectorXd &vec = prop->
value();
707 vec.resize(xml_value.
size());
709 for(
size_t i=0; i<vec.size(); i++) {
734 Eigen::VectorXf &vec = prop->
value();
735 vec.resize(xml_value.
size());
737 for(
size_t i=0; i<vec.size(); i++) {
754 for(XmlRpc::XmlRpcValue::ValueStruct::iterator it = xml_value_struct.
begin();
755 it != xml_value_struct.
end();
775 for (
int idx = 0; idx < xml_value.
size(); ++idx) {
776 base::PropertyBase* sub_prop_base = prop->
set().getProperty(
"Element" + boost::lexical_cast<std::string>(idx));
788 bool xmlParamToProp<RTT::PropertyBag>(
886 const std::string ¶m_name,
887 const unsigned int policy)
891 const std::string resolved_name = resolvedName(
894 return this->getParam(resolved_name, param_name);
898 const std::string &ros_name,
899 const std::string &rtt_name)
927 return getParams(service, ros_name);
943 return getParams(this->getOwner()->provides(), resolvedName(std::string(), policy));
948 const std::string& ns)
974 for (RTT::Service::ProviderNames::const_iterator it = names.begin(); it != names.end(); ++it)
978 std::string sub_ns = sub->getName();
980 getParams(sub, sub_ns);
bool xmlParamStructToProp(const XmlRpc::XmlRpcValue &xml_value, RTT::Property< RTT::PropertyBag > *prop)
static bool assign(const XMLRPCType &xml_value, PropertyType &prop_value)
bool getParamsComponentAbsolute()
const std::string & getMessage() const
virtual result_t get() const =0
ROSParamService(TaskContext *owner)
XmlRpc::XmlRpcValue rttPropertySequenceToXmlParam(RTT::base::PropertyBase *prop, const RTT::PropertyBag &bag)
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)
bool propertyIsSequence(RTT::base::PropertyBase *prop)
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 resize(base::DataSourceBase::shared_ptr arg, int size) const
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".
#define ADD_ROSPARAM_PROPERTY_OPERATION(return_type_str, return_type, func)
bool setParamsComponentRelative()
virtual bool isAssignable() const
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)
Property< T > & addRosParamProperty(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.
boost::intrusive_ptr< DataSource< T > > shared_ptr
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)
base::PropertyBase * getProperty(const std::string &name) const
static DataSource< T > * narrow(base::DataSourceBase *db)
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
bool xmlParamArrayToProp(const XmlRpc::XmlRpcValue &xml_value, RTT::Property< RTT::PropertyBag > *prop)
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)
boost::intrusive_ptr< DataSourceBase > shared_ptr
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)
virtual DataSourceBase::shared_ptr getDataSource() const =0
std::vector< base::PropertyBase * > Properties
void setParamImpl(const std::string &ros_param_name, const T &value)
Component resolution: "name" -> "/COMPONENT_NAME/name".
virtual const types::TypeInfo * getTypeInfo() const =0