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
00078 if len(args) < 2:
00079 parser.print_help()
00080 exit(1)
00081
00082 port = options.port
00083 baudrate = options.baud
00084 motor_ids = args[1:]
00085
00086 try:
00087 dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
00088 except dynamixel_io.SerialOpenError, soe:
00089 print 'ERROR:', soe
00090 else:
00091 for motor_id in motor_ids:
00092 motor_id = int(motor_id)
00093 print 'Configuring Dynamixel motor with ID %d' % motor_id
00094 if dxl_io.ping(motor_id):
00095 if options.baud_rate:
00096 print 'Setting baud rate to %d bps' % int(2000000.0/(options.baud_rate + 1))
00097 dxl_io.set_baud_rate(motor_id, options.baud_rate)
00098 if options.return_delay:
00099 print 'Setting return delay time to %d us' % options.return_delay * 2
00100 dxl_io.set_return_delay_time(motor_id, options.return_delay)
00101 if options.cw_angle_limit:
00102 print 'Setting CW angle limit to %d' % options.cw_angle_limit
00103 dxl_io.set_angle_limit_cw(motor_id, options.cw_angle_limit)
00104 if options.ccw_angle_limit:
00105 print 'Setting CCW angle limit to %d' % options.ccw_angle_limit
00106 dxl_io.set_angle_limit_ccw(motor_id, options.ccw_angle_limit)
00107 if options.min_voltage_limit:
00108 print 'Setting minimum voltage limit to %d' % options.min_voltage_limit
00109 dxl_io.set_voltage_limit_min(motor_id, options.min_voltage_limit)
00110 if options.max_voltage_limit:
00111 print 'Setting maximum voltage limit to %d' % options.min_voltage_limit
00112 dxl_io.set_voltage_limit_max(motor_id, options.max_voltage_limit)
00113 print 'done'
00114 else:
00115 print 'Unable to connect to Dynamixel motor with ID %d' % motor_id
00116