base_hands.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2013, Tokyo Opensource Robotics Kyokai Association
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
19 # names of its contributors may be used to endorse or promote products
20 # derived from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Author: Isaac Isao Saito
36 
37 import rospy
38 
39 
40 class BaseHands(object):
41  '''
42  This class provides methods that are generic for the hands of
43  Kawada Industries' dual-arm robot called Nextage Open.
44  '''
45  # TODO: Unittest is needed!!
46 
47  # Since NEXTAGE is expected to be dual-arm, arm indicator can be defined
48  # at the top level of hierarchy.
49  HAND_L = '1' # '0' is expected to be "Both hands".
50  HAND_R = '2'
51 
52  _DIO_ASSIGN_ON = 1
53  _DIO_ASSIGN_OFF = 0
54  _DIO_MASK = 0 # Masking value remains "0" regardless the design on the
55  # robot; masking logic is defined in hrpsys, while robot
56  # makers can decide DIO logic.
57 
58  # DIO pin numbers. It's convenient to be overridden and renamed in the
59  # derived classes to represent the specific purpose of each pin.
60  DIO_17 = 17
61  DIO_18 = 18
62  DIO_19 = 19
63  DIO_20 = 20
64  DIO_21 = 21
65  DIO_22 = 22
66  DIO_23 = 23
67  DIO_24 = 24
68  DIO_25 = 25
69  DIO_26 = 26
70  DIO_27 = 27
71  DIO_28 = 28
72 
73  _MSG_ERR_NOTIMPLEMENTED = 'The method is not implemented in the derived class'
74 
75  def __init__(self, parent):
76  '''
77  Since this class operates requires an access to
78  hrpsys.hrpsys_config.HrpsysConfigurator, valid 'parent' is a must.
79  Otherwise __init__ returns without doing anything.
80 
81  @type parent: hrpsys.hrpsys_config.HrpsysConfigurator
82  @param parent: derived class of HrpsysConfigurator.
83  '''
84  if not parent:
85  return # TODO: Replace with throwing exception
86  self._parent = parent
87 
88  def _dio_writer(self, digitalout_indices, dio_assignments,
89  padding=_DIO_ASSIGN_OFF):
90  '''
91  This private method calls HrpsysConfigurator.writeDigitalOutputWithMask,
92  which this class expects to be available via self._parent.
93 
94  According to the current (Oct 2013) hardware spec, numbering rule
95  differs regarding 0 (numeric figure) in dout and mask as follows:
96 
97  * 0 is "OFF" in the digital output.
98  * 2/1/2014 Assignment modified 0:ON --> 0:OFF
99  * 0 is "masked" and not used in mask. Since using '0' is defined in
100  hrpsys and not in the robots side, we'll always use '0' for
101  masking.
102 
103  @type digitalout_indices: int[]
104  @param digitalout_indices: Array of indices of digital output that NEED to be
105  flagged as 1.
106  eg. If you're targetting on 25 and 26th places in
107  the DIO array but only 25th is 1, then the
108  array becomes [24].
109  @type dio_assignments: int[]
110  @param dio_assignments: range(32). Also called as "masking bits" or
111  just "mask". This number corresponds to the
112  assigned digital pin of the robot.
113 
114  eg. If the target pins are 25 and 26,
115  dio_assignments = [24, 25]
116  @param padding: Either 0 or 1. DIO bit array will be populated with
117  this value.
118  Usually this method assumes to be called when turning
119  something "on". Therefore by default this value is ON.
120  @rtype: bool
121  @return: True if dout was writable to the register. False otherwise.
122  '''
123 
124  # 32 bit arrays used in write methods in hrpsys/hrpsys_config.py
125  dout = []
126  for i in range(32):
127  dout.append(padding)
128  # At the end of this loop, dout contains list of 32 'padding's.
129  # eg. [ 0, 0,...,0] if padding == 0
130  mask = []
131  for i in range(32):
132  mask.append(self._DIO_MASK)
133  # At the end of this loop, mask contains list of 32 '0's.
134 
135  signal_alternate = self._DIO_ASSIGN_ON
136  if padding == self._DIO_ASSIGN_ON:
137  signal_alternate = self._DIO_ASSIGN_OFF
138  rospy.logdebug('digitalout_indices={}'.format(digitalout_indices))
139  # Assign commanded bits
140  for i in digitalout_indices:
141  dout[i - 1] = signal_alternate
142 
143  # Assign unmasked, effective bits
144  for i in dio_assignments:
145  # For masking, alternate symbol is always 1 regarless the design
146  # on robot's side.
147  mask[i - 1] = 1
148 
149  # BEGIN; For convenience only; to show array number.
150  print_index = []
151  for i in range(10):
152  # For masking, alternate symbol is always 1.
153  n = i + 1
154  if 10 == n:
155  n = 0
156  print_index.append(n)
157  print_index.extend(print_index)
158  print_index.extend(print_index)
159  del print_index[-8:]
160  # END; For convenience only; to show array number.
161 
162  # # For some reason rospy.loginfo not print anything.
163  # # With this print formatting, you can copy the output and paste
164  # # directly into writeDigitalOutputWithMask method if you wish.
165  print('dout, mask:\n{},\n{}\n{}'.format(dout, mask, print_index))
166 
167  is_written_dout = False
168  try:
169  is_written_dout = self._parent.writeDigitalOutputWithMask(dout,
170  mask)
171  except AttributeError as e:
172  rospy.logerr('AttributeError from robot.\nTODO: Needs handled.')
173  rospy.logerr('\t{}'.format("Device was not found. Maybe you're" +
174  "on simulator?"))
175  return is_written_dout
176 
177  def init_dio(self):
178  '''
179  Initialize dio. All channels will be set '0' (off), EXCEPT for
180  tool changers (channel 19 and 24) so that attached tools won't fall.
181  '''
182  # TODO: The behavior might not be optimized. Ask Hajime-san and
183  # Nagashima-san to take a look.
184 
185  # 10/24/2013 OUT19, 24 are alternated; When they turned to '1', they
186  # are ON. So hands won't fall upon this function call.
187  # 2/1/2014 Due to the change of DIO assingment, OUT19, 24 need to be
188  # alternated;
189 
190  dout = mask = []
191  # Use all slots from 17 to 32.
192  for i in range(16, 32):
193  mask.append(i)
194 
195  self._dio_writer(dout, mask, self._DIO_ASSIGN_ON)
196 
197  # The following are common hand commands set by default.
198  # Depending on the configuration some / all of these don't necessarily
199  # have to be implemented.
200  def airhand_l_drawin(self):
201  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
202 
203  def airhand_r_drawin(self):
204  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
205 
206  def airhand_l_keep(self):
207  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
208 
209  def airhand_r_keep(self):
210  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
211 
212  def airhand_l_release(self):
213  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
214 
215  def airhand_r_release(self):
216  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
217 
218  def gripper_l_close(self):
219  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
220 
221  def gripper_r_close(self):
222  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
223 
224  def gripper_l_open(self):
225  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
226 
227  def gripper_r_open(self):
228  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
229 
230  def handlight_r(self, is_on=True):
231  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
232 
233  def handlight_l(self, is_on=True):
234  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
235 
236  def handlight_both(self, is_on=True):
237  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
238 
239  def handtool_l_eject(self):
240  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
241 
242  def handtool_r_eject(self):
243  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
244 
245  def handtool_l_attach(self):
246  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
247 
248  def handtool_r_attach(self):
249  raise NotImplementedError(self._MSG_ERR_NOTIMPLEMENTED)
def handlight_both(self, is_on=True)
Definition: base_hands.py:236
def _dio_writer(self, digitalout_indices, dio_assignments, padding=_DIO_ASSIGN_OFF)
Definition: base_hands.py:89


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47