set_params.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import rospy
5 from gazebo_msgs.srv import *
6 
7 from ddynamic_reconfigure_python.ddynamic_reconfigure import DDynamicReconfigure
8 
10  rospy.wait_for_service('/gazebo/advertise_joint_params')
11 
12  try:
13  advertise_params = rospy.ServiceProxy('/gazebo/advertise_joint_params', ParamListRequest)
14  res = advertise_params()
15  return res.params
16  except rospy.ServiceException, e:
17  print "Service call failed: %s"%e
18 
19 
20 def set_param(service_name, value):
21  rospy.wait_for_service("gazebo/" + service_name)
22  try:
23  set_param_ = rospy.ServiceProxy("gazebo/" + service_name, SetParamFloat)
24  res = set_param_(value)
25  return res.success
26  except rospy.ServiceException, e:
27  print "Service call failed: %s"%e
28 
29 def set_params(value):
30  services = get_services()
31  for service_name in services:
32  set_param(service_name, value)
33 
34 def dyn_rec_callback(config, level, param_ns):
35  # print(config)
36  # print(level)
37  # print(param_ns)
38 
39  for key in config:
40  if key == "groups":
41  continue
42  # service_name = key.replace("___", "/")
43  service_name = ''.join([param_ns,"/", key])
44  print service_name, key, config[key]
45  set_param(service_name, config[key])
46 
47  # rospy.loginfo("Received reconf call: " + str(config))
48  return config
49 
50 if __name__ == '__main__':
51  rospy.init_node('ddynrec')
52 
53  print("init ok")
54 
55  # Create a D(ynamic)DynamicReconfigure
56  # ddynrec = DDynamicReconfigure("/kosekhar/kosegav")
57 
58  # print("ddyn ok")
59 
60  ddyns = {}
61 
62  services = get_services()
63 
64  services = rospy.get_param("/optimizable_params")
65 
66  # print services
67 
68  # exit()
69 
70  print services
71 
72  for service_name in services:
73 
74  # service_name = ''.join(["/", service_name])
75 
76  index = service_name.rfind("/")
77  param_ns = service_name[:index]
78  param_name = service_name[index+1:]
79 
80 
81 
82  # param_name = service_name.replace("/", "___")
83 
84  if param_ns not in ddyns:
85  ddyns[param_ns] = DDynamicReconfigure(param_ns)
86 
87  ddynrec = ddyns[param_ns]
88 
89  ddynrec.add_variable(param_name, service_name, 0.0, 0.0, 10.0)
90 
91  # fs = {}
92 
93  for param_ns in ddyns:
94  def _dyn_rec_callback(config, level, _param_ns = param_ns):
95  return dyn_rec_callback(config, level, _param_ns)
96 
97  # fs[param_ns] = _dyn_rec_callback
98 
99  ddynrec = ddyns[param_ns]
100  ddynrec.start(_dyn_rec_callback)
101 
102 
103  # print "start printing"
104  # for _, f in fs.items():
105  # f("", "")
106 
107  # print ddyns
108 
109  # Add variables (name, description, default value, min, max, edit_method)
110  # ddynrec.add_variable("decimal", "float/double variable", 0.0, -1.0, 1.0)
111  # ddynrec.add_variable("integer", "integer variable", 0., -1., 1.)
112  # ddynrec.add_variable("bool", "bool variable", True)
113  # ddynrec.add_variable("string", "string variable", "string dynamic variable")
114  # enum_method = ddynrec.enum([ ddynrec.const("Small", "int", 0, "A small constant"),
115  # ddynrec.const("Medium", "int", 1, "A medium constant"),
116  # ddynrec.const("Large", "int", 2, "A large constant"),
117  # ddynrec.const("ExtraLarge", "int", 3, "An extra large constant")],
118  # "An enum example")
119  # ddynrec.add_variable("enumerate", "enumerate variable", 1, 0, 3, edit_method=enum_method)
120 
121  # Start the server
122 
123 
124  rospy.spin()
def set_param(service_name, value)
Definition: set_params.py:20
def set_params(value)
Definition: set_params.py:29
def _dyn_rec_callback(config, level, _param_ns=param_ns)
Definition: set_params.py:94
def dyn_rec_callback(config, level, param_ns)
Definition: set_params.py:34


dyn_tune
Author(s):
autogenerated on Mon Jun 10 2019 13:03:17