base_hands.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2013, Tokyo Opensource Robotics Kyokai Association
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
00019 #    names of its contributors may be used to endorse or promote products
00020 #    derived from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 #
00035 # Author: Isaac Isao Saito
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     # TODO: Unittest is needed!!
00046 
00047     # Since NEXTAGE is expected to be dual-arm, arm indicator can be defined
00048     # at the top level of hierarchy.
00049     HAND_L = '1'  # '0' is expected to be "Both hands".
00050     HAND_R = '2'
00051 
00052     _DIO_ASSIGN_ON = 1
00053     _DIO_ASSIGN_OFF = 0
00054     _DIO_MASK = 0   # Masking value remains "0" regardless the design on the
00055                     # robot; masking logic is defined in hrpsys, while robot
00056                     # makers can decide DIO logic.
00057 
00058     # DIO pin numbers. It's convenient to be overridden and renamed in the
00059     # derived classes to represent the specific purpose of each pin.
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  # TODO: Replace with throwing exception
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         # 32 bit arrays used in write methods in hrpsys/hrpsys_config.py
00125         dout = []
00126         for i in range(32):
00127             dout.append(padding)
00128             # At the end of this loop, dout contains list of 32 'padding's.
00129             # eg. [ 0, 0,...,0] if padding == 0
00130         mask = []
00131         for i in range(32):
00132             mask.append(self._DIO_MASK)
00133             # At the end of this loop, mask contains list of 32 '0's.
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         # Assign commanded bits
00140         for i in digitalout_indices:
00141             dout[i - 1] = signal_alternate
00142 
00143         # Assign unmasked, effective bits
00144         for i in dio_assignments:
00145             # For masking, alternate symbol is always 1 regarless the design
00146             # on robot's side.
00147             mask[i - 1] = 1
00148 
00149         # BEGIN; For convenience only; to show array number.
00150         print_index = []
00151         for i in range(10):
00152             # For masking, alternate symbol is always 1.
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         # END; For convenience only; to show array number.
00161 
00162         # # For some reason rospy.loginfo not print anything.
00163         # # With this print formatting, you can copy the output and paste
00164         # # directly into writeDigitalOutputWithMask method if you wish.
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         # TODO: The behavior might not be optimized. Ask Hajime-san and
00183         #       Nagashima-san to take a look.
00184 
00185         # 10/24/2013 OUT19, 24 are alternated; When they turned to '1', they
00186         # are ON. So hands won't fall upon this function call.
00187         # 2/1/2014 Due to the change of DIO assingment, OUT19, 24 need to be
00188         # alternated;
00189 
00190         dout = mask = []
00191         # Use all slots from 17 to 32.
00192         for i in range(16, 32):
00193             mask.append(i)
00194 
00195         self._dio_writer(dout, mask, self._DIO_ASSIGN_ON)
00196 
00197     # The following are common hand commands set by default.
00198     # Depending on the configuration some / all of these don't necessarily
00199     # have to be implemented.
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)


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed May 15 2019 04:45:36