set_torque.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  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]
57 
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]')
63 
64  (options, args) = parser.parse_args(sys.argv)
65 
66  if len(args) < 3:
67  parser.print_help()
68  exit(1)
69 
70  port = options.port
71  baudrate = options.baud
72  motor_id = int(args[1])
73  torque_on = args[2]
74 
75  try:
76  dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
77  except dynamixel_io.SerialOpenError, soe:
78  print 'ERROR:', soe
79  else:
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':
83  torque_on = False
84  elif torque_on.lower() == 'on':
85  torque_on = True
86  else:
87  parser.print_help()
88  exit(1)
89  dxl_io.set_torque_enabled(motor_id, torque_on)
90  print 'done'
91  else:
92  print 'ERROR: motor %d did not respond. Make sure to specify the correct baudrate.' % motor_id
93 


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