change_id.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2010-2011, Antons Rebguns.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of University of Arizona nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 
36 
37 __author__ = 'Antons Rebguns'
38 __copyright__ = 'Copyright (c) 2010-2011 Antons Rebguns'
39 
40 __license__ = 'BSD'
41 __maintainer__ = 'Antons Rebguns'
42 __email__ = 'anton@email.arizona.edu'
43 
44 
45 import sys
46 from optparse import OptionParser
47 
48 import roslib
49 roslib.load_manifest('dynamixel_driver')
50 
51 from dynamixel_driver import dynamixel_io
52 
53 if __name__ == '__main__':
54  parser = OptionParser(usage='Usage: %prog [options] OLD_ID NEW_ID', description='Changes the unique ID of a Dynamixel servo motor.')
55  parser.add_option('-p', '--port', metavar='PORT', default='/dev/ttyUSB0',
56  help='motors of specified controllers are connected to PORT [default: %default]')
57  parser.add_option('-b', '--baud', metavar='BAUD', type="int", default=1000000,
58  help='connection to serial port will be established at BAUD bps [default: %default]')
59 
60  (options, args) = parser.parse_args(sys.argv)
61 
62  if len(args) < 3:
63  parser.print_help()
64  exit(1)
65 
66  port = options.port
67  baudrate = options.baud
68  old_id = int(args[1])
69  new_id = int(args[2])
70 
71  try:
72  dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
73  except dynamixel_io.SerialOpenError, soe:
74  print 'ERROR:', soe
75  else:
76  print 'Changing motor id from %d to %d...' %(old_id, new_id),
77  if dxl_io.ping(old_id):
78  dxl_io.set_id(old_id, new_id)
79  print ' done'
80  print 'Verifying new id...' ,
81  if dxl_io.ping(new_id):
82  print ' done'
83  else:
84  print 'ERROR: The motor did not respond to a ping to its new id.'
85  else:
86  print 'ERROR: The specified motor did not respond to id %d. Make sure to specify the correct baudrate.' % old_id


dynamixel_driver
Author(s): Antons Rebguns, Cody Jorgensen
autogenerated on Tue May 12 2020 03:10:57