info_dump.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, Cody Jorgensen, 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__ = 'Cody Jorgensen, Antons Rebguns'
38 __copyright__ = 'Copyright (c) 2010-2011 Cody Jorgensen, 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
53 
54 def print_data(values):
55  ''' Takes a dictionary with all the motor values and does a formatted print.
56  '''
57  if values['freespin']:
58  print '''\
59  Motor %(id)d is connected:
60  Freespin: True
61  Model ------------------- %(model)s
62  Current Speed ----------- %(speed)d
63  Current Temperature ----- %(temperature)d%(degree_symbol)sC
64  Current Voltage --------- %(voltage).1fv
65  Current Load ------------ %(load)d
66  Moving ------------------ %(moving)s
67 ''' %values
68  else:
69  print '''\
70  Motor %(id)d is connected:
71  Freespin: False
72  Model ------------------- %(model)s
73  Min Angle --------------- %(min)d
74  Max Angle --------------- %(max)d
75  Current Position -------- %(position)d
76  Current Speed ----------- %(speed)d
77  Current Temperature ----- %(temperature)d%(degree_symbol)sC
78  Current Voltage --------- %(voltage).1fv
79  Current Load ------------ %(load)d
80  Moving ------------------ %(moving)s
81 ''' %values
82 
83 if __name__ == '__main__':
84  usage_msg = 'Usage: %prog [options] IDs'
85  desc_msg = 'Prints the current status of specified Dynamixel servo motors.'
86  epi_msg = 'Example: %s --port=/dev/ttyUSB1 --baud=57600 1 2 3 4 5' % sys.argv[0]
87 
88  parser = OptionParser(usage=usage_msg, description=desc_msg, epilog=epi_msg)
89  parser.add_option('-p', '--port', metavar='PORT', default='/dev/ttyUSB0',
90  help='motors of specified controllers are connected to PORT [default: %default]')
91  parser.add_option('-b', '--baud', metavar='BAUD', type="int", default=1000000,
92  help='connection to serial port will be established at BAUD bps [default: %default]')
93 
94  (options, args) = parser.parse_args(sys.argv)
95 
96  if len(args) < 2:
97  parser.print_help()
98  exit(1)
99 
100  port = options.port
101  baudrate = options.baud
102  motor_ids = args[1:]
103 
104  try:
105  dxl_io = dynamixel_io.DynamixelIO(port, baudrate)
106  except dynamixel_io.SerialOpenError, soe:
107  print 'ERROR:', soe
108  else:
109  responses = 0
110  print 'Pinging motors:'
111  for motor_id in motor_ids:
112  motor_id = int(motor_id)
113  print '%d ...' % motor_id,
114  p = dxl_io.ping(motor_id)
115  if p:
116  responses += 1
117  values = dxl_io.get_feedback(motor_id)
118  angles = dxl_io.get_angle_limits(motor_id)
119  model = dxl_io.get_model_number(motor_id)
120  firmware = dxl_io.get_firmware_version(motor_id)
121  values['model'] = '%s (firmware version: %d)' % (DXL_MODEL_TO_PARAMS[model]['name'], firmware)
122  values['degree_symbol'] = u"\u00B0"
123  values['min'] = angles['min']
124  values['max'] = angles['max']
125  values['voltage'] = values['voltage']
126  values['moving'] = str(values['moving'])
127  print 'done'
128  if angles['max'] == 0 and angles['min'] == 0:
129  values['freespin'] = True
130  else:
131  values['freespin'] = False
132  print_data(values)
133  else:
134  print 'error'
135  if responses == 0:
136  print 'ERROR: None of the specified motors responded. Make sure to specify the correct baudrate.'
137 
def print_data(values)
Definition: info_dump.py:54


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