Go to the documentation of this file.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 import rospy
00038
00039
00040 class BaseHands(object):
00041 '''
00042 This class provides methods that are generic for the hands of
00043 Kawada Industries' dual-arm robot called Nextage Open.
00044
00045 DIO pin numbers are set in
00046 nextage_ros_bridge.abs_hand_command.AbsractHandCommand
00047 '''
00048
00049
00050
00051
00052 HAND_L = '1'
00053 HAND_R = '2'
00054
00055 _DIO_ASSIGN_ON = 1
00056 _DIO_ASSIGN_OFF = 0
00057 _DIO_MASK = 0
00058
00059
00060
00061 def __init__(self, parent):
00062 '''
00063 Since this class operates requires an access to
00064 hrpsys.hrpsys_config.HrpsysConfigurator, valid 'parent' is a must.
00065 Otherwise __init__ returns without doing anything.
00066
00067 @type parent: hrpsys.hrpsys_config.HrpsysConfigurator
00068 @param parent: derived class of HrpsysConfigurator.
00069 '''
00070 if not parent:
00071 return
00072 self._parent = parent
00073
00074 def _dio_writer(self, digitalout_indices, dio_assignments,
00075 padding=_DIO_ASSIGN_OFF):
00076 '''
00077 This private method calls HrpsysConfigurator.writeDigitalOutputWithMask,
00078 which this class expects to be available via self._parent.
00079
00080 According to the current (Oct 2013) hardware spec, numbering rule
00081 differs regarding 0 (numeric figure) in dout and mask as follows:
00082
00083 * 0 is "OFF" in the digital output.
00084 * 2/1/2014 Assignment modified 0:ON --> 0:OFF
00085 * 0 is "masked" and not used in mask. Since using '0' is defined in
00086 hrpsys and not in the robots side, we'll always use '0' for
00087 masking.
00088
00089 @type digitalout_indices: int[]
00090 @param digitalout_indices: Array of indices of digital output that NEED to be
00091 flagged as 1.
00092 eg. If you're targetting on 25 and 26th places in
00093 the DIO array but only 25th is 1, then the
00094 array becomes [24].
00095 @type dio_assignments: int[]
00096 @param dio_assignments: range(32). Also called as "masking bits" or
00097 just "mask". This number corresponds to the
00098 assigned digital pin of the robot.
00099
00100 eg. If the target pins are 25 and 26,
00101 dio_assignments = [24, 25]
00102 @param padding: Either 0 or 1. DIO bit array will be populated with
00103 this value.
00104 Usually this method assumes to be called when turning
00105 something "on". Therefore by default this value is ON.
00106 '''
00107
00108
00109 dout = []
00110 for i in range(32):
00111 dout.append(padding)
00112
00113
00114 mask = []
00115 for i in range(32):
00116 mask.append(self._DIO_MASK)
00117
00118
00119 signal_alternate = self._DIO_ASSIGN_ON
00120 if padding == self._DIO_ASSIGN_ON:
00121 signal_alternate = self._DIO_ASSIGN_OFF
00122 rospy.logdebug('digitalout_indices={}'.format(digitalout_indices))
00123
00124 for i in digitalout_indices:
00125 dout[i - 1] = signal_alternate
00126
00127
00128 for i in dio_assignments:
00129
00130
00131 mask[i - 1] = 1
00132
00133
00134 print_index = []
00135 for i in range(10):
00136
00137 n = i + 1
00138 if 10 == n:
00139 n = 0
00140 print_index.append(n)
00141 print_index.extend(print_index)
00142 print_index.extend(print_index)
00143 del print_index[-8:]
00144
00145
00146
00147
00148
00149 print('dout, mask:\n{},\n{}\n{}'.format(dout, mask, print_index))
00150
00151 try:
00152 self._parent.writeDigitalOutputWithMask(dout, mask)
00153 except AttributeError as e:
00154 rospy.logerr('AttributeError from robot.\nTODO: Needs handled.')
00155 rospy.logerr('\t{}'.format("Device was not found. Maybe you're" +
00156 "on simulator?"))
00157
00158 def init_dio(self):
00159 '''
00160 Initialize dio. All channels will be set '0' (off), EXCEPT for
00161 tool changers (channel 19 and 24) so that attached tools won't fall.
00162 '''
00163
00164
00165
00166
00167
00168
00169
00170
00171 dout = mask = []
00172
00173 for i in range(16, 32):
00174 mask.append(i)
00175
00176 self._dio_writer(dout, mask, self._DIO_ASSIGN_ON)