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
00046
00047
00048
00049 HAND_L = '1'
00050 HAND_R = '2'
00051
00052 _DIO_ASSIGN_ON = 1
00053 _DIO_ASSIGN_OFF = 0
00054 _DIO_MASK = 0
00055
00056
00057
00058
00059
00060 DIO_17 = 17
00061 DIO_18 = 18
00062 DIO_19 = 19
00063 DIO_20 = 20
00064 DIO_21 = 21
00065 DIO_22 = 22
00066 DIO_23 = 23
00067 DIO_24 = 24
00068 DIO_25 = 25
00069 DIO_26 = 26
00070 DIO_27 = 27
00071 DIO_28 = 28
00072
00073 _MSG_ERR_NOTIMPLEMENTED = 'The method is not implemented in the derived class'
00074
00075 def __init__(self, parent):
00076 '''
00077 Since this class operates requires an access to
00078 hrpsys.hrpsys_config.HrpsysConfigurator, valid 'parent' is a must.
00079 Otherwise __init__ returns without doing anything.
00080
00081 @type parent: hrpsys.hrpsys_config.HrpsysConfigurator
00082 @param parent: derived class of HrpsysConfigurator.
00083 '''
00084 if not parent:
00085 return
00086 self._parent = parent
00087
00088 def _dio_writer(self, digitalout_indices, dio_assignments,
00089 padding=_DIO_ASSIGN_OFF):
00090 '''
00091 This private method calls HrpsysConfigurator.writeDigitalOutputWithMask,
00092 which this class expects to be available via self._parent.
00093
00094 According to the current (Oct 2013) hardware spec, numbering rule
00095 differs regarding 0 (numeric figure) in dout and mask as follows:
00096
00097 * 0 is "OFF" in the digital output.
00098 * 2/1/2014 Assignment modified 0:ON --> 0:OFF
00099 * 0 is "masked" and not used in mask. Since using '0' is defined in
00100 hrpsys and not in the robots side, we'll always use '0' for
00101 masking.
00102
00103 @type digitalout_indices: int[]
00104 @param digitalout_indices: Array of indices of digital output that NEED to be
00105 flagged as 1.
00106 eg. If you're targetting on 25 and 26th places in
00107 the DIO array but only 25th is 1, then the
00108 array becomes [24].
00109 @type dio_assignments: int[]
00110 @param dio_assignments: range(32). Also called as "masking bits" or
00111 just "mask". This number corresponds to the
00112 assigned digital pin of the robot.
00113
00114 eg. If the target pins are 25 and 26,
00115 dio_assignments = [24, 25]
00116 @param padding: Either 0 or 1. DIO bit array will be populated with
00117 this value.
00118 Usually this method assumes to be called when turning
00119 something "on". Therefore by default this value is ON.
00120 @rtype: bool
00121 @return: True if dout was writable to the register. False otherwise.
00122 '''
00123
00124
00125 dout = []
00126 for i in range(32):
00127 dout.append(padding)
00128
00129
00130 mask = []
00131 for i in range(32):
00132 mask.append(self._DIO_MASK)
00133
00134
00135 signal_alternate = self._DIO_ASSIGN_ON
00136 if padding == self._DIO_ASSIGN_ON:
00137 signal_alternate = self._DIO_ASSIGN_OFF
00138 rospy.logdebug('digitalout_indices={}'.format(digitalout_indices))
00139
00140 for i in digitalout_indices:
00141 dout[i - 1] = signal_alternate
00142
00143
00144 for i in dio_assignments:
00145
00146
00147 mask[i - 1] = 1
00148
00149
00150 print_index = []
00151 for i in range(10):
00152
00153 n = i + 1
00154 if 10 == n:
00155 n = 0
00156 print_index.append(n)
00157 print_index.extend(print_index)
00158 print_index.extend(print_index)
00159 del print_index[-8:]
00160
00161
00162
00163
00164
00165 print('dout, mask:\n{},\n{}\n{}'.format(dout, mask, print_index))
00166
00167 is_written_dout = False
00168 try:
00169 is_written_dout = self._parent.writeDigitalOutputWithMask(dout,
00170 mask)
00171 except AttributeError as e:
00172 rospy.logerr('AttributeError from robot.\nTODO: Needs handled.')
00173 rospy.logerr('\t{}'.format("Device was not found. Maybe you're" +
00174 "on simulator?"))
00175 return is_written_dout
00176
00177 def init_dio(self):
00178 '''
00179 Initialize dio. All channels will be set '0' (off), EXCEPT for
00180 tool changers (channel 19 and 24) so that attached tools won't fall.
00181 '''
00182
00183
00184
00185
00186
00187
00188
00189
00190 dout = mask = []
00191
00192 for i in range(16, 32):
00193 mask.append(i)
00194
00195 self._dio_writer(dout, mask, self._DIO_ASSIGN_ON)
00196
00197
00198
00199
00200 def airhand_l_drawin(self):
00201 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00202
00203 def airhand_r_drawin(self):
00204 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00205
00206 def airhand_l_keep(self):
00207 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00208
00209 def airhand_r_keep(self):
00210 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00211
00212 def airhand_l_release(self):
00213 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00214
00215 def airhand_r_release(self):
00216 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00217
00218 def gripper_l_close(self):
00219 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00220
00221 def gripper_r_close(self):
00222 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00223
00224 def gripper_l_open(self):
00225 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00226
00227 def gripper_r_open(self):
00228 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00229
00230 def handlight_r(self, is_on=True):
00231 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00232
00233 def handlight_l(self, is_on=True):
00234 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00235
00236 def handlight_both(self, is_on=True):
00237 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00238
00239 def handtool_l_eject(self):
00240 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00241
00242 def handtool_r_eject(self):
00243 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00244
00245 def handtool_l_attach(self):
00246 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
00247
00248 def handtool_r_attach(self):
00249 raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)