@@ -55,10 +55,14 @@ class ROSParamService: public RTT::Service
55
55
this ->addOperation (" setAll" , &ROSParamService::setParamsComponentPrivate, this )
56
56
.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()." );
57
57
58
- this ->addOperation (" get" , &ROSParamService::getParam , this )
58
+ this ->addOperation (" get" , &ROSParamService::get , this )
59
59
.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." )
60
60
.arg (" name" , " Name of the property / service / parameter." )
61
61
.arg (" policy" , " ROS parameter namespace resolution policy." );
62
+ this ->addOperation (" getParam" , &ROSParamService::getParam, this )
63
+ .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." )
64
+ .arg (" param_name" , " Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution." )
65
+ .arg (" name" , " Name of the RTT property or service." );
62
66
63
67
this ->addOperation (" getRelative" , &ROSParamService::getParamRelative, this )
64
68
.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." )
@@ -73,10 +77,14 @@ class ROSParamService: public RTT::Service
73
77
.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." )
74
78
.arg (" name" , " Name of the property / service / parameter." );
75
79
76
- this ->addOperation (" set" , &ROSParamService::setParam , this )
80
+ this ->addOperation (" set" , &ROSParamService::set , this )
77
81
.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." )
78
82
.arg (" name" , " Name of the property / service / parameter." )
79
83
.arg (" policy" , " ROS parameter namespace resolution policy." );
84
+ this ->addOperation (" setParam" , &ROSParamService::setParam, this )
85
+ .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." )
86
+ .arg (" param_name" , " Name of the ROS parameter. Use '~' and '/' leaders for private or absolute resolution." )
87
+ .arg (" name" , " Name of the RTT property or service." );
80
88
81
89
this ->addOperation (" setRelative" , &ROSParamService::setParamRelative, this )
82
90
.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." )
@@ -99,55 +107,72 @@ class ROSParamService: public RTT::Service
99
107
const std::string ¶m_name,
100
108
const ROSParamService::ResolutionPolicy policy);
101
109
102
- bool getParams (RTT::Service::shared_ptr service, const std::string& ns, const ROSParamService::ResolutionPolicy policy );
110
+ bool getParams (RTT::Service::shared_ptr service, const std::string& ns);
103
111
bool getParams (const ROSParamService::ResolutionPolicy policy);
104
112
bool getParamsRelative () { return getParams (RELATIVE); }
105
113
bool getParamsAbsolute () { return getParams (ABSOLUTE); }
106
114
bool getParamsPrivate () { return getParams (PRIVATE); }
107
115
bool getParamsComponentPrivate () { return getParams (COMPONENT); }
108
116
109
- bool getParam (
117
+ bool get (
110
118
const std::string ¶m_name,
111
119
const unsigned int policy = (unsigned int )ROSParamService::COMPONENT);
112
- bool getParamRelative (const std::string &name) { return getParam (name, RELATIVE); }
113
- bool getParamAbsolute (const std::string &name) { return getParam (name, ABSOLUTE); }
114
- bool getParamPrivate (const std::string &name) { return getParam (name, PRIVATE); }
115
- bool getParamComponentPrivate (const std::string &name) { return getParam (name, COMPONENT); }
116
-
117
- bool setParams (RTT::Service::shared_ptr service, const std::string& ns, const ROSParamService::ResolutionPolicy policy);
120
+ bool getParam (
121
+ const std::string &ros_name,
122
+ const std::string &rtt_name);
123
+ bool getParamRelative (const std::string &name) { return get (name, RELATIVE); }
124
+ bool getParamAbsolute (const std::string &name) { return get (name, ABSOLUTE); }
125
+ bool getParamPrivate (const std::string &name) { return get (name, PRIVATE); }
126
+ bool getParamComponentPrivate (const std::string &name) { return get (name, COMPONENT); }
127
+
128
+ bool setParams (RTT::Service::shared_ptr service, const std::string& ns);
118
129
bool setParams (const ROSParamService::ResolutionPolicy policy);
119
130
bool setParamsRelative () { return setParams (RELATIVE); }
120
131
bool setParamsAbsolute () { return setParams (ABSOLUTE); }
121
132
bool setParamsPrivate () { return setParams (PRIVATE); }
122
133
bool setParamsComponentPrivate () { return setParams (COMPONENT); }
123
134
124
- bool setParam (
135
+ bool set (
125
136
const std::string ¶m_name,
126
137
const unsigned int policy = (unsigned int )ROSParamService::COMPONENT);
127
- bool setParamRelative (const std::string &name) { return setParam (name, RELATIVE); }
128
- bool setParamAbsolute (const std::string &name) { return setParam (name, ABSOLUTE); }
129
- bool setParamPrivate (const std::string &name) { return setParam (name, PRIVATE); }
130
- bool setParamComponentPrivate (const std::string &name) { return setParam (name, COMPONENT); }
138
+ bool setParam (
139
+ const std::string &ros_name,
140
+ const std::string &rtt_name);
141
+ bool setParamRelative (const std::string &name) { return set (name, RELATIVE); }
142
+ bool setParamAbsolute (const std::string &name) { return set (name, ABSOLUTE); }
143
+ bool setParamPrivate (const std::string &name) { return set (name, PRIVATE); }
144
+ bool setParamComponentPrivate (const std::string &name) { return set (name, COMPONENT); }
131
145
};
132
146
133
147
const std::string ROSParamService::resolvedName (
134
148
const std::string ¶m_name,
135
149
const ROSParamService::ResolutionPolicy policy)
136
150
{
137
- std::string resolved_name = param_name;
151
+ std::string leader = " " ;
152
+ std::string resolved_name = " " ;
153
+
154
+ if (param_name.length () > 0 ) {
155
+ leader = param_name[0 ];
156
+ }
157
+
138
158
switch (policy) {
139
159
case ROSParamService::RELATIVE:
140
- return param_name;
160
+ resolved_name = param_name;
161
+ break ;
141
162
case ROSParamService::ABSOLUTE:
142
- return std::string (" /" ) + param_name;
163
+ resolved_name = (leader == " /" ) ? param_name : std::string (" /" ) + param_name;
164
+ break ;
143
165
case ROSParamService::PRIVATE:
144
- return std::string (" ~" ) + param_name;
166
+ resolved_name = (leader == " ~" ) ? param_name : std::string (" ~" ) + param_name;
167
+ break ;
145
168
case ROSParamService::COMPONENT:
146
- return std::string (" ~" ) + this ->getOwner ()->getName () + " /" + param_name;
169
+ resolved_name = std::string (" ~" ) + ros::names::append (this ->getOwner ()->getName (),param_name);
170
+ break ;
147
171
};
148
172
149
- // Relative by default
150
- return param_name;
173
+ RTT::log (RTT::Debug) << " [" <<this ->getOwner ()->getName ()<<" ] Resolving ROS param \" " <<param_name<<" \" to \" " <<resolved_name<<" \" " << RTT::endlog ();
174
+
175
+ return resolved_name;
151
176
}
152
177
153
178
@@ -308,48 +333,63 @@ XmlRpc::XmlRpcValue rttPropertyBaseToXmlParam(RTT::base::PropertyBase *prop)
308
333
}
309
334
310
335
311
- bool ROSParamService::setParam (
336
+ bool ROSParamService::set (
312
337
const std::string ¶m_name,
313
338
const unsigned int policy)
314
339
{
340
+ RTT::Logger::In in (" ROSParamService::set" );
341
+
342
+ const std::string resolved_name = resolvedName (param_name,ResolutionPolicy (policy));
343
+
344
+ return this ->setParam (resolved_name, param_name);
345
+ }
346
+
347
+ bool ROSParamService::setParam (
348
+ const std::string &ros_name,
349
+ const std::string &rtt_name)
350
+ {
351
+ RTT::Logger::In in (" ROSParamService::setParam" );
352
+
315
353
XmlRpc::XmlRpcValue xml_value;
316
354
317
- // Try to find a property named param_name
318
- RTT::base::PropertyBase *property = this ->getOwner ()->getProperty (param_name );
355
+ // Try to find a property named rtt_name
356
+ RTT::base::PropertyBase *property = this ->getOwner ()->getProperty (rtt_name );
319
357
if (property) {
320
- xml_value = rttPropertyBaseToXmlParam (this ->getOwner ()->getProperty (param_name ));
321
- ros::param::set (resolvedName (param_name, ResolutionPolicy (policy)) , xml_value);
358
+ xml_value = rttPropertyBaseToXmlParam (this ->getOwner ()->getProperty (rtt_name ));
359
+ ros::param::set (ros_name , xml_value);
322
360
return true ;
323
361
}
324
362
325
- // Try to find a sub-service named param_name
326
- RTT::Service::shared_ptr service = this ->getOwner ()->provides ()->getService (param_name );
363
+ // Try to find a sub-service named rtt_name
364
+ RTT::Service::shared_ptr service = this ->getOwner ()->provides ()->getService (rtt_name );
327
365
if (service) {
328
366
// Set all parameters of the sub-service
329
- return setParams (service, service-> getName (), ResolutionPolicy (policy) );
367
+ return setParams (service, ros_name );
330
368
}
331
369
332
- RTT::log (RTT::Debug) << " RTT component does not have a property or service named \" " << param_name << " \" " << RTT::endlog ();
370
+ RTT::log (RTT::Debug) << " RTT component does not have a property or service named \" " << rtt_name << " \" " << RTT::endlog ();
333
371
return false ;
334
372
}
335
373
336
374
bool ROSParamService::setParams (const ROSParamService::ResolutionPolicy policy)
337
375
{
338
- return setParams (this ->getOwner ()->provides (), std::string (), policy);
376
+ return setParams (this ->getOwner ()->provides (), resolvedName ( std::string (), policy) );
339
377
}
340
378
341
- bool ROSParamService::setParams (RTT::Service::shared_ptr service, const std::string& ns, const ROSParamService::ResolutionPolicy policy) {
379
+ bool ROSParamService::setParams (
380
+ RTT::Service::shared_ptr service,
381
+ const std::string& ns) {
342
382
XmlRpc::XmlRpcValue xml_value;
343
383
xml_value = rttPropertyToXmlParam (*(service->properties ()));
344
- ros::param::set (resolvedName (ns, policy) , xml_value);
384
+ ros::param::set (ns , xml_value);
345
385
346
386
// Recurse into sub-services
347
387
RTT::Service::ProviderNames names = service->getProviderNames ();
348
388
for (RTT::Service::ProviderNames::const_iterator it = names.begin (); it != names.end (); ++it)
349
389
{
350
390
RTT::Service::shared_ptr sub (service->getService (*it));
351
391
if (sub) {
352
- if (!setParams (sub, ns + " / " + sub->getName (), policy )) return false ;
392
+ if (!setParams (sub, ros::names::append (ns, sub->getName ()) )) return false ;
353
393
}
354
394
}
355
395
@@ -610,64 +650,78 @@ bool xmlParamToProp(
610
650
return false ;
611
651
}
612
652
613
- bool ROSParamService::getParam (
653
+ bool ROSParamService::get (
614
654
const std::string ¶m_name,
615
655
const unsigned int policy)
656
+ {
657
+ RTT::Logger::In in (" ROSParamService::get" );
658
+
659
+ const std::string resolved_name = resolvedName (
660
+ param_name,ResolutionPolicy (policy));
661
+
662
+ return this ->getParam (resolved_name, param_name);
663
+ }
664
+
665
+ bool ROSParamService::getParam (
666
+ const std::string &ros_name,
667
+ const std::string &rtt_name)
616
668
{
617
669
RTT::Logger::In in (" ROSParamService::getParam" );
618
670
619
671
try {
620
672
// Get the parameter
621
673
XmlRpc::XmlRpcValue xml_value;
622
674
623
- const std::string resolved_name = resolvedName (param_name,ResolutionPolicy (policy));
624
- if (!ros::param::get (resolved_name, xml_value)) {
625
- RTT::log (RTT::Debug) << " ROS Parameter \" " << resolved_name << " \" not found on the parameter server!" << RTT::endlog ();
675
+ if (!ros::param::get (ros_name, xml_value)) {
676
+ RTT::log (RTT::Debug) << " ROS Parameter \" " << ros_name << " \" not found on the parameter server!" << RTT::endlog ();
626
677
return false ;
627
678
}
628
679
629
680
// Try to get the property if it exists
630
- RTT::base::PropertyBase *prop_base = this ->getOwner ()->getProperty (param_name );
681
+ RTT::base::PropertyBase *prop_base = this ->getOwner ()->getProperty (rtt_name );
631
682
if (prop_base) {
632
683
// Deal with the xml value
633
684
bool ret = xmlParamToProp (xml_value, prop_base);
634
685
if (!ret) {
635
- RTT::log (RTT::Warning) << " Could not convert \" " << resolved_name << " \" from an XMLRPC value to an RTT property." << RTT::endlog ();
686
+ RTT::log (RTT::Warning) << " Could not convert \" " << ros_name << " \" from an XMLRPC value to an RTT property." << RTT::endlog ();
636
687
}
637
688
return ret;
638
689
}
639
690
640
691
// Try to get the properties of a sub-service if it exists
641
- RTT::Service::shared_ptr service = this ->getOwner ()->provides ()->getService (param_name );
692
+ RTT::Service::shared_ptr service = this ->getOwner ()->provides ()->getService (rtt_name );
642
693
if (service) {
643
694
// Get all parameters of the sub-service
644
- return getParams (service, service-> getName (), ResolutionPolicy (policy) );
695
+ return getParams (service, ros_name );
645
696
}
646
697
647
- RTT::log (RTT::Debug) << " RTT component does not have a property or service named \" " << param_name << " \" " << RTT::endlog ();
648
- return false ;
698
+ RTT::log (RTT::Debug) << " RTT component does not have a property or service named \" " << rtt_name << " \" " << RTT::endlog ();
699
+
649
700
} catch (XmlRpc::XmlRpcException &err) {
650
- RTT::log (RTT::Error) << " XmlRpcException when getting ROS parameter \" " <<param_name <<" \" : " << err.getMessage () << RTT::endlog ();
701
+ RTT::log (RTT::Error) << " XmlRpcException when getting ROS parameter \" " <<ros_name <<" \" : " << err.getMessage () << RTT::endlog ();
651
702
RTT::log (RTT::Debug) << " -- Make sure your parameters are the right primitive type." << RTT::endlog ();
652
- return false ;
653
703
}
704
+
705
+ return false ;
654
706
}
655
707
708
+
656
709
bool ROSParamService::getParams (const ROSParamService::ResolutionPolicy policy)
657
710
{
658
- return getParams (this ->getOwner ()->provides (), std::string (), policy);
711
+ return getParams (this ->getOwner ()->provides (), resolvedName ( std::string (), policy) );
659
712
}
660
713
661
- bool ROSParamService::getParams (RTT::Service::shared_ptr service, const std::string& ns, const ROSParamService::ResolutionPolicy policy)
714
+ bool ROSParamService::getParams (
715
+ RTT::Service::shared_ptr service,
716
+ const std::string& ns)
662
717
{
663
718
RTT::Logger::In in (" ROSParamService::getParams" );
664
719
665
720
// Get the parameter
666
721
XmlRpc::XmlRpcValue xml_value;
667
722
668
- const std::string resolved_name = resolvedName (ns, policy);
669
- if (!ros::param::get (resolved_name, xml_value)) {
670
- RTT::log (RTT::Debug) << " ROS Parameter \" " << resolved_name << " \" not found on the parameter server!" << RTT::endlog ();
723
+ if (!ros::param::get (ns, xml_value)) {
724
+ RTT::log (RTT::Debug) << " ROS Parameter namespace \" " << ns << " \" not found on the parameter server!" << RTT::endlog ();
671
725
return false ;
672
726
}
673
727
@@ -679,7 +733,7 @@ bool ROSParamService::getParams(RTT::Service::shared_ptr service, const std::str
679
733
// Deal with the xml value
680
734
bool ret = xmlParamToProp (xml_value, &prop);
681
735
if (!ret) {
682
- RTT::log (RTT::Warning) << " Could not convert \" " << resolved_name << " \" from an XMLRPC value to an RTT property." << RTT::endlog ();
736
+ RTT::log (RTT::Warning) << " Could not convert \" " << ns << " \" from an XMLRPC value to an RTT property." << RTT::endlog ();
683
737
return false ;
684
738
}
685
739
@@ -690,8 +744,8 @@ bool ROSParamService::getParams(RTT::Service::shared_ptr service, const std::str
690
744
RTT::Service::shared_ptr sub (service->getService (*it));
691
745
if (sub) {
692
746
std::string sub_ns = sub->getName ();
693
- if (!ns.empty ()) sub_ns = ns + " / " + sub_ns;
694
- getParams (sub, sub_ns, policy );
747
+ if (!ns.empty ()) sub_ns = ros::names::append (ns, sub_ns) ;
748
+ getParams (sub, sub_ns);
695
749
}
696
750
}
697
751
0 commit comments