37 __author__ =
'Antons Rebguns' 38 __copyright__ =
'Copyright (c) 2010-2011 Antons Rebguns' 41 __maintainer__ =
'Antons Rebguns' 42 __email__ =
'anton@email.arizona.edu' 46 from optparse
import OptionParser
49 roslib.load_manifest(
'dynamixel_driver')
51 from dynamixel_driver
import dynamixel_io
53 if __name__ ==
'__main__':
54 usage_msg =
'Usage: %prog [options] ID [On|Off]' 55 desc_msg =
'Turns the torque of specified Dynamixel servo motor on or off.' 56 epi_msg =
'Example: %s --port=/dev/ttyUSB1 --baud=57600 1 Off' % sys.argv[0]
58 parser = OptionParser(usage=usage_msg, description=desc_msg, epilog=epi_msg)
59 parser.add_option(
'-p',
'--port', metavar=
'PORT', default=
'/dev/ttyUSB0',
60 help=
'motors of specified controllers are connected to PORT [default: %default]')
61 parser.add_option(
'-b',
'--baud', metavar=
'BAUD', type=
"int", default=1000000,
62 help=
'connection to serial port will be established at BAUD bps [default: %default]')
64 (options, args) = parser.parse_args(sys.argv)
71 baudrate = options.baud
72 motor_id = int(args[1])
76 dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
77 except dynamixel_io.SerialOpenError, soe:
80 print 'Turning torque %s for motor %d' % (torque_on, motor_id)
81 if dxl_io.ping(motor_id):
82 if torque_on.lower() ==
'off':
84 elif torque_on.lower() ==
'on':
89 dxl_io.set_torque_enabled(motor_id, torque_on)
92 print 'ERROR: motor %d did not respond. Make sure to specify the correct baudrate.' % motor_id