/usr/lib/dynamic_reconfigure/dynparam is in python-dynamic-reconfigure 1.5.49-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | #! /usr/bin/env python
#
# Software License Agreement (BSD License)
#
# Copyright (c) 2009, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$
from __future__ import print_function
NAME='dynparam'
import roslib; roslib.load_manifest('dynamic_reconfigure')
import rospy
import optparse
import sys
import yaml
import dynamic_reconfigure.client
def do_list():
connect()
list = dynamic_reconfigure.find_reconfigure_services()
for s in list:
print(s)
def do_set_from_parameters():
usage = """Usage: %prog set_from_parameters [options] node
Example command line:
dynparam set_from_parameters wge100_camera _camera_url:=foo
Example launch file:
<launch>
<node name="$(anon adjust-wge100_camera)" pkg="dynamic_reconfigure" type="dynparam" args="set_from_parameters wge100_camera">
<param name="camera_url" value="foo" />
<param name="brightness" value="58" />
</node>
</launch>"""
parser = optparse.OptionParser(usage=usage, prog=NAME)
add_timeout_option(parser)
options, args = parser.parse_args(myargv[2:])
if len(args) == 0:
parser.error("invalid arguments. Please specify a node name")
elif len(args) > 1:
parser.error("too many arguments")
node = args[0]
connect()
try:
params = rospy.get_param("~")
except KeyError:
print >> sys.stderr, 'error updating parameters: no parameters found on parameter server'
return
set_params(node, params, timeout=options.timeout)
def do_set():
usage = """Usage: %prog set [options] node parameter value
or: %prog set [options] node values
Examples:
dynparam set wge100_camera camera_url foo
dynparam set wge100_camera "{'camera_url':'foo', 'brightness':58}" """
args, optparse_args = [], []
for s in myargv[2:]:
if s.startswith('-'):
if len(s) > 1 and ord(s[1]) >= ord('0') and ord(s[1]) <= ord('9'):
args.append(s)
else:
optparse_args.append(s)
else:
args.append(s)
parser = optparse.OptionParser(usage=usage, prog=NAME)
add_timeout_option(parser)
options, _ = parser.parse_args(optparse_args)
if len(args) > 3:
parser.error("too many arguments")
elif len(args) < 2:
parser.error("invalid arguments. Please specify either a node name, parameter name and parameter value, or a node name and a YAML dictionary")
node = args[0]
if len(args) == 2:
node, value = args[0], args[1]
values_dict = yaml.load(value)
if type(values_dict) != dict:
parser.error('invalid arguments. Please specify either a node name, parameter name and parameter value, or a node name and a YAML dictionary')
elif len(args) == 3:
node, parameter, value = args[0], args[1], args[2]
values_dict = { parameter : value }
connect()
try:
set_params(node, values_dict, timeout=options.timeout)
except rospy.service.ServiceException:
print('couldn\'t set parameters at node %s' % node)
except rospy.exceptions.ROSException:
print('couldn\'t set parameters at node %s' % node)
def do_get():
usage = "Usage: %prog get [options] node"
parser = optparse.OptionParser(usage=usage, prog=NAME)
add_timeout_option(parser)
options, args = parser.parse_args(myargv[2:])
if len(args) == 0:
parser.error("invalid arguments. Please specify a node name")
elif len(args) > 1:
parser.error("too many arguments")
node = args[0]
connect()
params = get_params(node, timeout=options.timeout)
if params is not None:
print(params)
def do_load():
usage = "Usage: %prog load [options] node file"
parser = optparse.OptionParser(usage=usage, prog=NAME)
add_timeout_option(parser)
options, args = parser.parse_args(myargv[2:])
if len(args) == 0:
parser.error("invalid arguments. Please specify a node name")
elif len(args) == 1:
parser.error("invalid arguments. Please specify an input file")
elif len(args) > 2:
parser.error("too many arguments")
node, path = args[0], args[1]
f = file(path, 'r')
try:
params = {}
for doc in yaml.load_all(f.read()):
params.update(doc)
finally:
f.close()
connect()
set_params(node, params, timeout=options.timeout)
def do_dump():
usage = "Usage: %prog dump [options] node file"
parser = optparse.OptionParser(usage=usage, prog=NAME)
add_timeout_option(parser)
options, args = parser.parse_args(myargv[2:])
if len(args) == 0:
parser.error("invalid arguments. Please specify a node name")
elif len(args) == 1:
parser.error("invalid arguments. Please specify an output file")
elif len(args) > 2:
parser.error("too many arguments")
node, path = args[0], args[1]
connect()
params = get_params(node, timeout=options.timeout)
if params is not None:
f = file(path, 'w')
try:
yaml.dump(params, f)
return
finally:
f.close()
print("couldn't get parameters from node %s" % node)
def get_params(node, timeout=None):
client = dynamic_reconfigure.client.Client(node, timeout=timeout)
return client.get_configuration(timeout=timeout)
def set_params(node, params, timeout=None):
client = dynamic_reconfigure.client.Client(node, timeout=timeout)
try:
client.update_configuration(params)
except dynamic_reconfigure.DynamicReconfigureParameterException as e:
print('error updating parameters: ' + str(e))
def add_timeout_option(parser):
parser.add_option('-t', '--timeout', action='store', type='float', default=None, help='timeout in secs')
def print_usage():
print("""dynparam is a command-line tool for getting, setting, and
deleting parameters of a dynamically configurable node.
Commands:
\tdynparam set configure node
\tdynparam set_from_parameters copy configuration from parameter server
\tdynparam get get node configuration
\tdynparam load load configuration from file
\tdynparam dump dump configuration to file
\tdynparam list list configurable nodes
Type dynparam <command> -h for more detailed usage, e.g. 'dynparam get -h'
""")
sys.exit(1)
def connect():
rospy.init_node('dynparam', anonymous=True)
if __name__ == '__main__':
myargv = rospy.myargv()
if len(myargv) == 1:
print_usage()
else:
cmd = myargv[1]
try:
if cmd == 'list': do_list()
elif cmd == 'set_from_parameters': do_set_from_parameters()
elif cmd == 'set': do_set()
elif cmd == 'get': do_get()
elif cmd == 'load': do_load()
elif cmd == 'dump': do_dump()
else: print_usage()
except rospy.exceptions.ROSInterruptException:
pass
|