param_modi.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "ros/param.h"
29 #include "ros/master.h"
30 #include "ros/xmlrpc_manager.h"
31 #include "ros/this_node.h"
32 #include "ros/names.h"
33 
34 #include <ros/console.h>
35 
36 #include <mutex>
37 
38 #include <vector>
39 #include <map>
40 
41 namespace roswrap
42 {
43 
44 namespace param
45 {
46 
47 typedef std::map<std::string, XmlRpc::XmlRpcValue> M_Param;
49 std::mutex g_params_mutex;
51 
52 void invalidateParentParams(const std::string& key)
53 {
54  std::string ns_key = names::parentNamespace(key);
55  while (ns_key != "" && ns_key != "/")
56  {
57  if (g_subscribed_params.find(ns_key) != g_subscribed_params.end())
58  {
59  // by erasing the key the parameter will be re-queried
60  g_params.erase(ns_key);
61  }
62  ns_key = names::parentNamespace(ns_key);
63  }
64 }
65 
66 void set(const std::string& key, const XmlRpc::XmlRpcValue& v)
67 {
68  std::string mapped_key = ros::names::resolve(key);
69 
70  XmlRpc::XmlRpcValue params, result, payload;
71  params[0] = this_node::getName();
72  params[1] = mapped_key;
73  params[2] = v;
74 
75  {
76  // Lock around the execute to the master in case we get a parameter update on this value between
77  // executing on the master and setting the parameter in the g_params list.
78  std::lock_guard<std::mutex> lock(g_params_mutex);
79 
80  if (master::execute("setParam", params, result, payload, true))
81  {
82  // Update our cached params list now so that if get() is called immediately after param::set()
83  // we already have the cached state and our value will be correct
84  if (g_subscribed_params.find(mapped_key) != g_subscribed_params.end())
85  {
86  g_params[mapped_key] = v;
87  }
88  invalidateParentParams(mapped_key);
89  }
90  }
91 }
92 
93 void set(const std::string& key, const std::string& s)
94 {
95  // construct xmlrpc_c::value object of the std::string and
96  // call param::set(key, xmlvalue);
98  ros::param::set(key, v);
99 }
100 
101 void set(const std::string& key, const char* s)
102 {
103  // construct xmlrpc_c::value object of the std::string and
104  // call param::set(key, xmlvalue);
105  std::string sxx = std::string(s);
106  XmlRpc::XmlRpcValue v(sxx);
107  ros::param::set(key, v);
108 }
109 
110 void set(const std::string& key, double d)
111 {
113  ros::param::set(key, v);
114 }
115 
116 void set(const std::string& key, int i)
117 {
118  XmlRpc::XmlRpcValue v(i);
119  ros::param::set(key, v);
120 }
121 
122 void set(const std::string& key, bool b)
123 {
124  XmlRpc::XmlRpcValue v(b);
125  ros::param::set(key, v);
126 }
127 
128 template <class T>
129  void setImpl(const std::string& key, const std::vector<T>& vec)
130 {
131  // Note: the XmlRpcValue starts off as "invalid" and assertArray turns it
132  // into an array type with the given size
133  XmlRpc::XmlRpcValue xml_vec;
134  xml_vec.setSize(vec.size());
135 
136  // Copy the contents into the XmlRpcValue
137  for(size_t i=0; i < vec.size(); i++) {
138  xml_vec[i] = vec.at(i);
139  }
140 
141  ros::param::set(key, xml_vec);
142 }
143 
144 void set(const std::string& key, const std::vector<std::string>& vec)
145 {
146  setImpl(key, vec);
147 }
148 
149 void set(const std::string& key, const std::vector<double>& vec)
150 {
151  setImpl(key, vec);
152 }
153 
154 void set(const std::string& key, const std::vector<float>& vec)
155 {
156  setImpl(key, vec);
157 }
158 
159 void set(const std::string& key, const std::vector<int>& vec)
160 {
161  setImpl(key, vec);
162 }
163 
164 void set(const std::string& key, const std::vector<bool>& vec)
165 {
166  setImpl(key, vec);
167 }
168 
169 template <class T>
170  void setImpl(const std::string& key, const std::map<std::string, T>& map)
171 {
172  // Note: the XmlRpcValue starts off as "invalid" and assertStruct turns it
173  // into a struct type
174  XmlRpc::XmlRpcValue xml_value;
175  xml_value.begin();
176 
177  // Copy the contents into the XmlRpcValue
178  for(typename std::map<std::string, T>::const_iterator it = map.begin(); it != map.end(); ++it) {
179  xml_value[it->first] = it->second;
180  }
181 
182  ros::param::set(key, xml_value);
183 }
184 
185 void set(const std::string& key, const std::map<std::string, std::string>& map)
186 {
187  setImpl(key, map);
188 }
189 
190 void set(const std::string& key, const std::map<std::string, double>& map)
191 {
192  setImpl(key, map);
193 }
194 
195 void set(const std::string& key, const std::map<std::string, float>& map)
196 {
197  setImpl(key, map);
198 }
199 
200 void set(const std::string& key, const std::map<std::string, int>& map)
201 {
202  setImpl(key, map);
203 }
204 
205 void set(const std::string& key, const std::map<std::string, bool>& map)
206 {
207  setImpl(key, map);
208 }
209 
210 bool has(const std::string& key)
211 {
212  XmlRpc::XmlRpcValue params, result, payload;
213  params[0] = this_node::getName();
214  params[1] = ros::names::resolve(key);
215  //params[1] = key;
216  // We don't loop here, because validateXmlrpcResponse() returns false
217  // both when we can't contact the master and when the master says, "I
218  // don't have that param."
219  if (!master::execute("hasParam", params, result, payload, false))
220  {
221  return false;
222  }
223 
224  return payload;
225 }
226 
227 bool del(const std::string& key)
228 {
229  std::string mapped_key = ros::names::resolve(key);
230 
231  {
232  std::lock_guard<std::mutex> lock(g_params_mutex);
233 
234  g_subscribed_params.erase(mapped_key);
235  g_params.erase(mapped_key);
236  }
237 
238  XmlRpc::XmlRpcValue params, result, payload;
239  params[0] = this_node::getName();
240  params[1] = mapped_key;
241  // We don't loop here, because validateXmlrpcResponse() returns false
242  // both when we can't contact the master and when the master says, "I
243  // don't have that param."
244  if (!master::execute("deleteParam", params, result, payload, false))
245  {
246  return false;
247  }
248 
249  return true;
250 }
251 
252 bool getImpl(const std::string& key, XmlRpc::XmlRpcValue& v, bool use_cache)
253 {
254  std::string mapped_key = ros::names::resolve(key);
255  if (mapped_key.empty()) mapped_key = "/";
256 
257  if (use_cache)
258  {
259  std::lock_guard<std::mutex> lock(g_params_mutex);
260 
261  if (g_subscribed_params.find(mapped_key) != g_subscribed_params.end())
262  {
263  M_Param::iterator it = g_params.find(mapped_key);
264  if (it != g_params.end())
265  {
266  if (it->second.valid())
267  {
268  ROS_DEBUG_NAMED("cached_parameters", "Using cached parameter value for key [%s]", mapped_key.c_str());
269 
270  v = it->second;
271  return true;
272  }
273  else
274  {
275  ROS_DEBUG_NAMED("cached_parameters", "Cached parameter is invalid for key [%s]", mapped_key.c_str());
276  return false;
277  }
278  }
279  }
280  else
281  {
282  // parameter we've never seen before, register for update from the master
283  if (g_subscribed_params.insert(mapped_key).second)
284  {
285  XmlRpc::XmlRpcValue params, result, payload;
286  params[0] = this_node::getName();
287  params[1] = XMLRPCManager::instance()->getServerURI();
288  params[2] = mapped_key;
289 
290  if (!master::execute("subscribeParam", params, result, payload, false))
291  {
292  ROS_DEBUG_NAMED("cached_parameters", "Subscribe to parameter [%s]: call to the master failed", mapped_key.c_str());
293  g_subscribed_params.erase(mapped_key);
294  use_cache = false;
295  }
296  else
297  {
298  ROS_DEBUG_NAMED("cached_parameters", "Subscribed to parameter [%s]", mapped_key.c_str());
299  }
300  }
301  }
302  }
303 
304  XmlRpc::XmlRpcValue params, result;
305  params[0] = this_node::getName();
306  params[1] = mapped_key;
307 
308  // We don't loop here, because validateXmlrpcResponse() returns false
309  // both when we can't contact the master and when the master says, "I
310  // don't have that param."
311  bool ret = master::execute("getParam", params, result, v, false);
312 
313  if (use_cache)
314  {
315  std::lock_guard<std::mutex> lock(g_params_mutex);
316 
317  ROS_DEBUG_NAMED("cached_parameters", "Caching parameter [%s] with value type [%d]", mapped_key.c_str(), v.getType());
318  g_params[mapped_key] = v;
319  }
320 
321  return ret;
322 }
323 
324 bool getImpl(const std::string& key, std::string& s, bool use_cache)
325 {
327  if (!getImpl(key, v, use_cache))
328  return false;
330  return false;
331  s = std::string(v);
332  return true;
333 }
334 
335 bool getImpl(const std::string& key, double& d, bool use_cache)
336 {
338  if (!getImpl(key, v, use_cache))
339  {
340  return false;
341  }
342 
344  {
345  d = (int)v;
346  }
348  {
349  return false;
350  }
351  else
352  {
353  d = v;
354  }
355 
356  return true;
357 }
358 
359 bool getImpl(const std::string& key, float& f, bool use_cache)
360 {
361  double d = static_cast<double>(f);
362  bool result = getImpl(key, d, use_cache);
363  if (result)
364  f = static_cast<float>(d);
365  return result;
366 }
367 
368 bool getImpl(const std::string& key, int& i, bool use_cache)
369 {
371  if (!getImpl(key, v, use_cache))
372  {
373  return false;
374  }
375 
377  {
378  double d = v;
379 
380  if (fmod(d, 1.0) < 0.5)
381  {
382  d = floor(d);
383  }
384  else
385  {
386  d = ceil(d);
387  }
388 
389  i = d;
390  }
391  else if (v.getType() != XmlRpc::XmlRpcValue::TypeInt)
392  {
393  return false;
394  }
395  else
396  {
397  i = v;
398  }
399 
400  return true;
401 }
402 
403 bool getImpl(const std::string& key, bool& b, bool use_cache)
404 {
406  if (!getImpl(key, v, use_cache))
407  return false;
409  return false;
410  b = v;
411  return true;
412 }
413 
414 bool get(const std::string& key, std::string& s)
415 {
416  return getImpl(key, s, false);
417 }
418 
419 bool get(const std::string& key, double& d)
420 {
421  return getImpl(key, d, false);
422 }
423 
424 bool get(const std::string& key, float& f)
425 {
426  return getImpl(key, f, false);
427 }
428 
429 bool get(const std::string& key, int& i)
430 {
431  return getImpl(key, i, false);
432 }
433 
434 bool get(const std::string& key, bool& b)
435 {
436  return getImpl(key, b, false);
437 }
438 
439 bool get(const std::string& key, XmlRpc::XmlRpcValue& v)
440 {
441  return getImpl(key, v, false);
442 }
443 
444 bool getCached(const std::string& key, std::string& s)
445 {
446  return getImpl(key, s, true);
447 }
448 
449 bool getCached(const std::string& key, double& d)
450 {
451  return getImpl(key, d, true);
452 }
453 
454 bool getCached(const std::string& key, float& f)
455 {
456  return getImpl(key, f, true);
457 }
458 
459 bool getCached(const std::string& key, int& i)
460 {
461  return getImpl(key, i, true);
462 }
463 
464 bool getCached(const std::string& key, bool& b)
465 {
466  return getImpl(key, b, true);
467 }
468 
469 bool getCached(const std::string& key, XmlRpc::XmlRpcValue& v)
470 {
471  return getImpl(key, v, true);
472 }
473 
474 template <class T> T xml_cast(XmlRpc::XmlRpcValue xml_value)
475 {
476  return static_cast<T>(xml_value);
477 }
478 
479 template <class T> bool xml_castable(int XmlType)
480 {
481  return false;
482 }
483 
484 template<> bool xml_castable<std::string>(int XmlType)
485 {
486  return XmlType == XmlRpc::XmlRpcValue::TypeString;
487 }
488 
489 template<> bool xml_castable<double>(int XmlType)
490 {
491  return (
492  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
493  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
495 }
496 
497 template<> bool xml_castable<float>(int XmlType)
498 {
499  return (
500  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
501  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
503 }
504 
505 template<> bool xml_castable<int>(int XmlType)
506 {
507  return (
508  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
509  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
511 }
512 
513 template<> bool xml_castable<bool>(int XmlType)
514 {
515  return (
516  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
517  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
519 }
520 
521 template<> double xml_cast(XmlRpc::XmlRpcValue xml_value)
522 {
523  using namespace XmlRpc;
524  switch(xml_value.getType()) {
525  case XmlRpcValue::TypeDouble:
526  return static_cast<double>(xml_value);
527  case XmlRpcValue::TypeInt:
528  return static_cast<double>(static_cast<int>(xml_value));
529  case XmlRpcValue::TypeBoolean:
530  return static_cast<double>(static_cast<bool>(xml_value));
531  default:
532  return 0.0;
533  };
534 }
535 
536 template<> float xml_cast(XmlRpc::XmlRpcValue xml_value)
537 {
538  using namespace XmlRpc;
539  switch(xml_value.getType()) {
540  case XmlRpcValue::TypeDouble:
541  return static_cast<float>(static_cast<double>(xml_value));
542  case XmlRpcValue::TypeInt:
543  return static_cast<float>(static_cast<int>(xml_value));
544  case XmlRpcValue::TypeBoolean:
545  return static_cast<float>(static_cast<bool>(xml_value));
546  default:
547  return 0.0f;
548  };
549 }
550 
551 template<> int xml_cast(XmlRpc::XmlRpcValue xml_value)
552 {
553  using namespace XmlRpc;
554  switch(xml_value.getType()) {
555  case XmlRpcValue::TypeDouble:
556  return static_cast<int>(static_cast<double>(xml_value));
557  case XmlRpcValue::TypeInt:
558  return static_cast<int>(xml_value);
559  case XmlRpcValue::TypeBoolean:
560  return static_cast<int>(static_cast<bool>(xml_value));
561  default:
562  return 0;
563  };
564 }
565 
566 template<> bool xml_cast(XmlRpc::XmlRpcValue xml_value)
567 {
568  using namespace XmlRpc;
569  switch(xml_value.getType()) {
570  case XmlRpcValue::TypeDouble:
571  return static_cast<bool>(static_cast<double>(xml_value));
572  case XmlRpcValue::TypeInt:
573  return static_cast<bool>(static_cast<int>(xml_value));
574  case XmlRpcValue::TypeBoolean:
575  return static_cast<bool>(xml_value);
576  default:
577  return false;
578  };
579 }
580 
581 template <class T>
582  bool getImpl(const std::string& key, std::vector<T>& vec, bool cached)
583 {
584  XmlRpc::XmlRpcValue xml_array;
585  if(!getImpl(key, xml_array, cached)) {
586  return false;
587  }
588 
589  // Make sure it's an array type
590  if(xml_array.getType() != XmlRpc::XmlRpcValue::TypeArray) {
591  return false;
592  }
593 
594  // Resize the target vector (destructive)
595  vec.resize(xml_array.size());
596 
597  // Fill the vector with stuff
598  for (int i = 0; i < xml_array.size(); i++) {
599  if(!xml_castable<T>(xml_array[i].getType())) {
600  return false;
601  }
602 
603  vec[i] = xml_cast<T>(xml_array[i]);
604  }
605 
606  return true;
607 }
608 
609 bool get(const std::string& key, std::vector<std::string>& vec)
610 {
611  return getImpl(key, vec, false);
612 }
613 bool get(const std::string& key, std::vector<double>& vec)
614 {
615  return getImpl(key, vec, false);
616 }
617 bool get(const std::string& key, std::vector<float>& vec)
618 {
619  return getImpl(key, vec, false);
620 }
621 bool get(const std::string& key, std::vector<int>& vec)
622 {
623  return getImpl(key, vec, false);
624 }
625 bool get(const std::string& key, std::vector<bool>& vec)
626 {
627  return getImpl(key, vec, false);
628 }
629 
630 bool getCached(const std::string& key, std::vector<std::string>& vec)
631 {
632  return getImpl(key, vec, true);
633 }
634 bool getCached(const std::string& key, std::vector<double>& vec)
635 {
636  return getImpl(key, vec, true);
637 }
638 bool getCached(const std::string& key, std::vector<float>& vec)
639 {
640  return getImpl(key, vec, true);
641 }
642 bool getCached(const std::string& key, std::vector<int>& vec)
643 {
644  return getImpl(key, vec, true);
645 }
646 bool getCached(const std::string& key, std::vector<bool>& vec)
647 {
648  return getImpl(key, vec, true);
649 }
650 
651 template <class T>
652  bool getImpl(const std::string& key, std::map<std::string, T>& map, bool cached)
653 {
654  XmlRpc::XmlRpcValue xml_value;
655  if(!getImpl(key, xml_value, cached)) {
656  return false;
657  }
658 
659  // Make sure it's a struct type
660  if(xml_value.getType() != XmlRpc::XmlRpcValue::TypeStruct) {
661  return false;
662  }
663 
664  // Fill the map with stuff
665  for (XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = xml_value.begin();
666  it != xml_value.end();
667  ++it)
668  {
669  // Make sure this element is the right type
670  if(!xml_castable<T>(it->second.getType())) {
671  return false;
672  }
673  // Store the element
674  map[it->first] = xml_cast<T>(it->second);
675  }
676 
677  return true;
678 }
679 
680 bool get(const std::string& key, std::map<std::string, std::string>& map)
681 {
682  return getImpl(key, map, false);
683 }
684 bool get(const std::string& key, std::map<std::string, double>& map)
685 {
686  return getImpl(key, map, false);
687 }
688 bool get(const std::string& key, std::map<std::string, float>& map)
689 {
690  return getImpl(key, map, false);
691 }
692 bool get(const std::string& key, std::map<std::string, int>& map)
693 {
694  return getImpl(key, map, false);
695 }
696 bool get(const std::string& key, std::map<std::string, bool>& map)
697 {
698  return getImpl(key, map, false);
699 }
700 
701 bool getCached(const std::string& key, std::map<std::string, std::string>& map)
702 {
703  return getImpl(key, map, true);
704 }
705 bool getCached(const std::string& key, std::map<std::string, double>& map)
706 {
707  return getImpl(key, map, true);
708 }
709 bool getCached(const std::string& key, std::map<std::string, float>& map)
710 {
711  return getImpl(key, map, true);
712 }
713 bool getCached(const std::string& key, std::map<std::string, int>& map)
714 {
715  return getImpl(key, map, true);
716 }
717 bool getCached(const std::string& key, std::map<std::string, bool>& map)
718 {
719  return getImpl(key, map, true);
720 }
721 
722 bool getParamNames(std::vector<std::string>& keys)
723 {
724  XmlRpc::XmlRpcValue params, result, payload;
725  params[0] = this_node::getName();
726  if (!master::execute("getParamNames", params, result, payload, false)) {
727  return false;
728  }
729  // Make sure it's an array type
730  if (result.getType() != XmlRpc::XmlRpcValue::TypeArray) {
731  return false;
732  }
733  // Make sure it returned 3 elements
734  if (result.size() != 3) {
735  return false;
736  }
737  // Get the actual parameter keys
738  XmlRpc::XmlRpcValue parameters = result[2];
739  // Resize the output
740  keys.resize(parameters.size());
741 
742  // Fill the output vector with the answer
743  for (int i = 0; i < parameters.size(); ++i) {
744  if (parameters[i].getType() != XmlRpc::XmlRpcValue::TypeString) {
745  return false;
746  }
747  keys[i] = std::string(parameters[i]);
748  }
749  return true;
750 }
751 
752 bool search(const std::string& key, std::string& result_out)
753 {
754  return search(this_node::getName(), key, result_out);
755 }
756 
757 bool search(const std::string& ns, const std::string& key, std::string& result_out)
758 {
759  XmlRpc::XmlRpcValue params, result, payload;
760  params[0] = ns;
761 
762  // searchParam needs a separate form of remapping -- remapping on the unresolved name, rather than the
763  // resolved one.
764 
765  std::string remapped = key;
766  M_string::const_iterator it = names::getUnresolvedRemappings().find(key);
767  if (it != names::getUnresolvedRemappings().end())
768  {
769  remapped = it->second;
770  }
771 
772  params[1] = remapped;
773  // We don't loop here, because validateXmlrpcResponse() returns false
774  // both when we can't contact the master and when the master says, "I
775  // don't have that param."
776  if (!master::execute("searchParam", params, result, payload, false))
777  {
778  return false;
779  }
780 
781  result_out = (std::string)payload;
782 
783  return true;
784 }
785 
786 void update(const std::string& key, const XmlRpc::XmlRpcValue& v)
787 {
788  std::string clean_key = names::clean(key);
789  ROS_DEBUG_NAMED("cached_parameters", "Received parameter update for key [%s]", clean_key.c_str());
790 
791  std::lock_guard<std::mutex> lock(g_params_mutex);
792 
793  if (g_subscribed_params.find(clean_key) != g_subscribed_params.end())
794  {
795  g_params[clean_key] = v;
796  }
797  invalidateParentParams(clean_key);
798 }
799 
801 {
802  result[0] = 1;
803  result[1] = std::string("");
804  result[2] = 0;
805 
806  ros::param::update((std::string)params[1], params[2]);
807 }
808 
809 void init(const M_string& remappings)
810 {
811  M_string::const_iterator it = remappings.begin();
812  M_string::const_iterator end = remappings.end();
813  for (; it != end; ++it)
814  {
815  const std::string& name = it->first;
816  const std::string& param = it->second;
817 
818  if (name.size() < 2)
819  {
820  continue;
821  }
822 
823  if (name[0] == '_' && name[1] != '_')
824  {
825  std::string local_name = "~" + name.substr(1);
826  /*
827  bool success = false;
828  try
829  {
830  int32_t i = boost::lexical_cast<int32_t>(param);
831  ros::param::set(names::resolve(local_name), i);
832  success = true;
833  }
834  catch (boost::bad_lexical_cast&)
835  {
836  }
837  if (success)
838  {
839  continue;
840  }
841  try
842  {
843  double d = boost::lexical_cast<double>(param);
844  ros::param::set(names::resolve(local_name), d);
845  success = true;
846  }
847  catch (boost::bad_lexical_cast&)
848  {
849  }
850  if (success)
851  {
852  continue;
853  }
854  */
855  int32_t i = 0;
856  double d = 0;
857  if(sscanf(param.c_str(),"%d", &i) == 1)
858  {
859  ros::param::set(names::resolve(local_name), i);
860  }
861  else if(sscanf(param.c_str(),"%lf", &d) == 1)
862  {
863  ros::param::set(names::resolve(local_name), d);
864  }
865  else if (param == "true" || param == "True" || param == "TRUE")
866  {
867  ros::param::set(names::resolve(local_name), true);
868  }
869  else if (param == "false" || param == "False" || param == "FALSE")
870  {
871  ros::param::set(names::resolve(local_name), false);
872  }
873  else
874  {
875  ros::param::set(names::resolve(local_name), param);
876  }
877  }
878  }
879 
880  XMLRPCManager::instance()->bind("paramUpdate", paramUpdateCallback);
881 }
882 
883 } // namespace param
884 
885 } // namespace roswrap
XmlRpc::XmlRpcValue::size
int size() const
roswrap::names::resolve
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
Resolve a graph resource name into a fully qualified graph resource name.
roswrap::param::setImpl
void setImpl(const std::string &key, const std::vector< T > &vec)
Definition: param_modi.cpp:129
roswrap::param::has
bool has(const std::string &key)
Check whether a parameter exists on the parameter server.
Definition: param_modi.cpp:210
roswrap::param::xml_castable< float >
bool xml_castable< float >(int XmlType)
Definition: param_modi.cpp:497
roswrap::param::update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
Definition: param_modi.cpp:786
roswrap::param::get
bool get(const std::string &key, std::string &s)
Get a string value from the parameter server.
Definition: param_modi.cpp:414
s
XmlRpcServer s
roswrap::master::execute
ROSCPP_DECL bool execute(const std::string &method, const XmlRpc::XmlRpcValue &request, XmlRpc::XmlRpcValue &response, XmlRpc::XmlRpcValue &payload, bool wait_for_master)
Execute an XMLRPC call on the master.
roswrap::names::clean
ROSCPP_DECL std::string clean(const std::string &name)
Cleans a graph resource name: removes double slashes, trailing slash.
sick_ldmrs_driver::param
bool param(rosNodePtr node, const std::string &param_name, T &value, const T &default_value)
Definition: sick_ldmrs_config.hpp:71
roswrap::param::xml_castable< double >
bool xml_castable< double >(int XmlType)
Definition: param_modi.cpp:489
roswrap::M_string
std::map< std::string, std::string > M_string
Definition: datatypes.h:46
XmlRpc::XmlRpcValue::TypeInt
TypeInt
XmlRpc
roswrap::param::getCached
bool getCached(const std::string &key, std::string &s)
Get a string value from the parameter server, with local caching.
Definition: param_modi.cpp:444
roswrap::param::set
void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
Set an arbitrary XML/RPC value on the parameter server.
Definition: param_modi.cpp:66
roswrap::param::invalidateParentParams
void invalidateParentParams(const std::string &key)
Definition: param_modi.cpp:52
roswrap::param::paramUpdateCallback
void paramUpdateCallback(XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
Definition: param_modi.cpp:800
roswrap::param::del
bool del(const std::string &key)
Delete a parameter from the parameter server.
Definition: param_modi.cpp:227
roswrap::param::xml_castable< bool >
bool xml_castable< bool >(int XmlType)
Definition: param_modi.cpp:513
ros::names::resolve
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
Resolve a graph resource name into a fully qualified graph resource name.
XmlRpc::XmlRpcValue::TypeStruct
TypeStruct
f
f
roswrap::names::parentNamespace
ROSCPP_DECL std::string parentNamespace(const std::string &name)
Get the parent namespace of a name.
roswrap::param::getImpl
bool getImpl(const std::string &key, XmlRpc::XmlRpcValue &v, bool use_cache)
Definition: param_modi.cpp:252
roswrap::param::xml_castable< int >
bool xml_castable< int >(int XmlType)
Definition: param_modi.cpp:505
roswrap::param::g_params_mutex
std::mutex g_params_mutex
Definition: param_modi.cpp:49
roswrap::param::init
void init(const M_string &remappings)
Definition: param_modi.cpp:809
pcap_json_converter.payload
string payload
Definition: pcap_json_converter.py:130
XmlRpc::XmlRpcValue::TypeDouble
TypeDouble
roswrap::S_string
std::set< std::string > S_string
Definition: datatypes.h:45
api.setup.name
name
Definition: python/api/setup.py:12
ros::param::update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
roswrap::param::g_subscribed_params
S_string g_subscribed_params
Definition: param_modi.cpp:50
ROS_DEBUG_NAMED
#define ROS_DEBUG_NAMED(name,...)
Definition: macros_generated.h:61
XmlRpc::XmlRpcValue::TypeString
TypeString
d
d
roswrap
Definition: param_modi.cpp:41
roswrap::param::M_Param
std::map< std::string, XmlRpc::XmlRpcValue > M_Param
Definition: param_modi.cpp:47
roswrap::param::search
bool search(const std::string &key, std::string &result_out)
Search up the tree for a parameter with a given key. This version defaults to starting in the current...
Definition: param_modi.cpp:752
XmlRpc::XmlRpcValue::end
iterator end()
XmlRpc::XmlRpcValue::getType
const Type & getType() const
roswrap::param::xml_castable
bool xml_castable(int XmlType)
Definition: param_modi.cpp:479
XmlRpc::XmlRpcValue::TypeArray
TypeArray
roswrap::names::getUnresolvedRemappings
const ROSCPP_DECL M_string & getUnresolvedRemappings()
ros::param::set
ROSCPP_DECL void set(const std::string &key, bool b)
XmlRpc::XmlRpcValue::setSize
void setSize(int size)
roswrap::param::g_params
M_Param g_params
Definition: param_modi.cpp:48
roswrap::this_node::getName
const ROSCPP_DECL std::string & getName()
Returns the name of the current node.
Definition: rossimu.cpp:343
roswrap::param::getParamNames
bool getParamNames(std::vector< std::string > &keys)
Get the list of all the parameters in the server.
Definition: param_modi.cpp:722
XmlRpc::XmlRpcValue::begin
iterator begin()
XmlRpc::XmlRpcValue::TypeBoolean
TypeBoolean
roswrap::param::xml_cast
T xml_cast(XmlRpc::XmlRpcValue xml_value)
Definition: param_modi.cpp:474
roswrap::param::param
bool param(const std::string &param_name, T &param_val, const T &default_val)
Assign value from parameter server, with default.
Definition: param_modi.h:609
roswrap::XMLRPCManager::instance
static const XMLRPCManagerPtr & instance()
Definition: xmlrpc_manager.cpp:100
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:25


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:09