00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 __author__ = 'Antons Rebguns'
00038 __copyright__ = 'Copyright (c) 2010-2011 Antons Rebguns'
00039
00040 __license__ = 'BSD'
00041 __maintainer__ = 'Antons Rebguns'
00042 __email__ = 'anton@email.arizona.edu'
00043
00044
00045 import sys
00046 from optparse import OptionParser
00047
00048 import roslib
00049 roslib.load_manifest('dynamixel_driver')
00050
00051 from dynamixel_driver import dynamixel_io
00052
00053 if __name__ == '__main__':
00054 usage_msg = 'Usage: %prog [options] MOTOR_IDs'
00055 desc_msg = 'Sets various configuration options of specified Dynamixel servo motor.'
00056 epi_msg = 'Example: %s --port=/dev/ttyUSB1 --baud=57600 --baud-rate=1 --return-delay=1 5 9 23' % sys.argv[0]
00057
00058 parser = OptionParser(usage=usage_msg, description=desc_msg, epilog=epi_msg)
00059 parser.add_option('-p', '--port', metavar='PORT', default='/dev/ttyUSB0',
00060 help='motors of specified controllers are connected to PORT [default: %default]')
00061 parser.add_option('-b', '--baud', metavar='BAUD', type='int', default=1000000,
00062 help='connection to serial port will be established at BAUD bps [default: %default]')
00063 parser.add_option('-r', '--baud-rate', type='int', metavar='RATE', dest='baud_rate',
00064 help='set servo motor communication speed')
00065 parser.add_option('-d', '--return-delay', type='int', metavar='DELAY', dest='return_delay',
00066 help='set servo motor return packet delay time')
00067 parser.add_option('--cw-angle-limit', type='int', metavar='CW_ANGLE', dest='cw_angle_limit',
00068 help='set servo motor CW angle limit')
00069 parser.add_option('--ccw-angle-limit', type='int', metavar='CCW_ANGLE', dest='ccw_angle_limit',
00070 help='set servo motor CCW angle limit')
00071 parser.add_option('--min-voltage-limit', type='int', metavar='MIN_VOLTAGE', dest='min_voltage_limit',
00072 help='set servo motor minimum voltage limit')
00073 parser.add_option('--max-voltage-limit', type='int', metavar='MAX_VOLTAGE', dest='max_voltage_limit',
00074 help='set servo motor maximum voltage limit')
00075
00076 (options, args) = parser.parse_args(sys.argv)
00077 print options
00078
00079 if len(args) < 2:
00080 parser.print_help()
00081 exit(1)
00082
00083 port = options.port
00084 baudrate = options.baud
00085 motor_ids = args[1:]
00086
00087 try:
00088 dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
00089 except dynamixel_io.SerialOpenError, soe:
00090 print 'ERROR:', soe
00091 else:
00092 for motor_id in motor_ids:
00093 motor_id = int(motor_id)
00094 print 'Configuring Dynamixel motor with ID %d' % motor_id
00095 if dxl_io.ping(motor_id):
00096
00097 if options.baud_rate:
00098 valid_rates = (1,3,4,7,9,16,34,103,207,250,251,252)
00099
00100 if options.baud_rate not in valid_rates:
00101 print 'Requested baud rate is invalid, please use one of the following: %s' % str(valid_rates)
00102
00103 if options.baud_rate <= 207:
00104 print 'Setting baud rate to %d bps' % int(2000000.0/(options.baud_rate + 1))
00105 elif options.baud_rate == 250:
00106 print 'Setting baud rate to %d bps' % 2250000
00107 elif options.baud_rate == 251:
00108 print 'Setting baud rate to %d bps' % 2500000
00109 elif options.baud_rate == 252:
00110 print 'Setting baud rate to %d bps' % 3000000
00111
00112 dxl_io.set_baud_rate(motor_id, options.baud_rate)
00113
00114
00115 if options.return_delay is not None:
00116 if options.return_delay < 0 or options.return_delay > 254:
00117 print 'Requested return delay time is out of valie range (0 - 254)'
00118
00119 print 'Setting return delay time to %d us' % (options.return_delay * 2)
00120 dxl_io.set_return_delay_time(motor_id, options.return_delay)
00121
00122
00123 if options.cw_angle_limit is not None:
00124 print 'Setting CW angle limit to %d' % options.cw_angle_limit
00125 dxl_io.set_angle_limit_cw(motor_id, options.cw_angle_limit)
00126
00127
00128 if options.ccw_angle_limit is not None:
00129 print 'Setting CCW angle limit to %d' % options.ccw_angle_limit
00130 dxl_io.set_angle_limit_ccw(motor_id, options.ccw_angle_limit)
00131
00132
00133 if options.min_voltage_limit:
00134 print 'Setting minimum voltage limit to %d' % options.min_voltage_limit
00135 dxl_io.set_voltage_limit_min(motor_id, options.min_voltage_limit)
00136
00137
00138 if options.max_voltage_limit:
00139 print 'Setting maximum voltage limit to %d' % options.max_voltage_limit
00140 dxl_io.set_voltage_limit_max(motor_id, options.max_voltage_limit)
00141
00142 print 'done'
00143 else:
00144 print 'Unable to connect to Dynamixel motor with ID %d' % motor_id