nextage_client.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 from hironx_ros_bridge.hironx_client import HIRONX
00038 
00039 from nextage_ros_bridge.iros13_hands import Iros13Hands
00040 from nextage_ros_bridge.hands_05 import Hands05
00041 
00042 
00043 class NextageClient(HIRONX, object):
00044     # The 2nd arg 'object' is passed to work around the issue raised because
00045     # HrpsysConfigurator is "old-style" python class.
00046     # See http://stackoverflow.com/a/18392639/577001
00047     '''
00048     This class holds methods that are specific to Kawada Industries' dual-arm
00049     robot called Nextage Open.
00050     '''
00051     # TODO: Unittest s'il vous plait!
00052 
00053     ''' Overriding a variable in the superclass to set the arms at higher
00054     positions.'''
00055     OffPose = [[0], [0, 0],
00056                [25, -140, -150, 45, 0, 0],
00057                [-25, -140, -150, -45, 0, 0],
00058                [0, 0, 0, 0],
00059                [0, 0, 0, 0]]
00060 
00061     # Default digital input groups defined by manufacturer, Kawada, as of
00062     # July 2014. This may change per the robot in the future and in then
00063     # need modified. See also readDinGroup method.
00064     _DI_PORTS_L = [25, 21, 22, 23, 24]
00065     _DI_PORTS_R = [20, 16, 17, 18, 19]
00066 
00067     HAND_VER_0_4_2 = '0.4.2'
00068     HAND_VER_0_5_1 = '0.5.1'
00069 
00070     def __init__(self):
00071         '''
00072         Do not get confused that there is also a method called
00073         'init' (without trailing underscores) that is succeeded from the
00074         super class as the tradition there.
00075         '''
00076         super(NextageClient, self).__init__()
00077         self.set_hand_version(self.HAND_VER_0_5_1)
00078 
00079     def init(self, robotname="HiroNX(Robot)0", url=""):
00080         '''
00081         Calls init from its superclass, which tries to connect RTCManager,
00082         looks for ModelLoader, and starts necessary RTC components. Also runs
00083         config, logger.
00084         Also internally calls setSelfGroups().
00085 
00086         @type robotname: str
00087         @type url: str
00088         '''
00089         HIRONX.init(self, robotname=robotname, url=url)
00090 
00091     def get_hand_version(self):
00092         '''
00093         @rtype: str
00094         '''
00095         if not self._hand_version:
00096             return 'Hand module not set yet.'
00097         else:
00098             return self._hand_version
00099 
00100     def set_hand_version(self, version=HAND_VER_0_5_1):
00101         self._hand_version = version
00102         if self.HAND_VER_0_4_2 == self._hand_version:
00103             self._hands = Iros13Hands(self)
00104         elif self.HAND_VER_0_5_1 == self._hand_version:
00105             self._hands = Hands05(self)
00106 
00107     def handlight_r(self, is_on=True):
00108         '''
00109         @deprecated: Won't be functional after package version 0.5.1.
00110                      Use self._hands.%FUNCTION_NAME% instead.
00111         '''
00112         return self._hands.handlight_r(is_on)
00113 
00114     def handlight_l(self, is_on=True):
00115         '''
00116         @deprecated: Won't be functional after package version 0.5.1.
00117                      Use self._hands.%FUNCTION_NAME% instead.
00118         '''
00119         return self._hands.handlight_r(is_on)
00120 
00121     def handlight_both(self, is_on=True):
00122         '''
00123         @deprecated: Won't be functional after package version 0.5.1.
00124                      Use self._hands.%FUNCTION_NAME% instead.
00125         '''
00126         return self._hands.handlight_both(is_on)
00127 
00128     def handtool_l_eject(self):
00129         '''
00130         @deprecated: Won't be functional after package version 0.5.1.
00131                      Use self._hands.%FUNCTION_NAME% instead.
00132         '''
00133         return self._hands.toolchanger_l_command.execute(
00134             self._hands.toolchanger_l_command.HAND_TOOLCHANGE_OFF)
00135 
00136     def handtool_r_eject(self):
00137         '''
00138         @deprecated: Won't be functional after package version 0.5.1.
00139                      Use self._hands.%FUNCTION_NAME% instead.
00140         '''
00141         return self._hands.toolchanger_r_command.execute(
00142             self._hands.toolchanger_r_command.HAND_TOOLCHANGE_OFF)
00143 
00144     def handtool_l_attach(self):
00145         '''
00146         @deprecated: Won't be functional after package version 0.5.1.
00147                      Use self._hands.%FUNCTION_NAME% instead.
00148         '''
00149         return self._hands.toolchanger_l_command.execute(
00150             self._hands.toolchanger_l_command.HAND_TOOLCHANGE_ON)
00151 
00152     def handtool_r_attach(self):
00153         '''
00154         @deprecated: Won't be functional after package version 0.5.1.
00155                      Use self._hands.%FUNCTION_NAME% instead.
00156         '''
00157         return self._hands.toolchanger_r_command.execute(
00158             self._hands.toolchanger_r_command.HAND_TOOLCHANGE_ON)
00159 
00160     def gripper_l_close(self):
00161         '''
00162         @deprecated: Won't be functional after package version 0.5.1.
00163                      Use self._hands.%FUNCTION_NAME% instead.
00164         '''
00165         return self._hands.gripper_l_command.execute(
00166             self._hands.gripper_l_command.GRIPPER_CLOSE)
00167 
00168     def gripper_r_close(self):
00169         '''
00170         @deprecated: Won't be functional after package version 0.5.1.
00171                      Use self._hands.%FUNCTION_NAME% instead.
00172         '''
00173         return self._hands.gripper_r_command.execute(
00174             self._hands.gripper_r_command.GRIPPER_CLOSE)
00175 
00176     def gripper_l_open(self):
00177         '''
00178         @deprecated: Won't be functional after package version 0.5.1.
00179                      Use self._hands.%FUNCTION_NAME% instead.
00180         '''
00181         return self._hands.gripper_l_command.execute(
00182             self._hands.gripper_r_command.GRIPPER_OPEN)
00183 
00184     def gripper_r_open(self):
00185         '''
00186         @deprecated: Won't be functional after package version 0.5.1.
00187                      Use self._hands.%FUNCTION_NAME% instead.
00188         '''
00189         return self._hands.gripper_r_command.execute(
00190             self._hands.gripper_r_command.GRIPPER_OPEN)
00191 
00192     def airhand_l_drawin(self):
00193         '''
00194         @deprecated: Won't be functional after package version 0.5.1.
00195                      Use self._hands.%FUNCTION_NAME% instead.
00196         '''
00197         return self._hands.airhand_l_command.execute(
00198             self._hands.airhand_l_command.AIRHAND_DRAWIN)
00199 
00200     def airhand_r_drawin(self):
00201         '''
00202         @deprecated: Won't be functional after package version 0.5.1.
00203                      Use self._hands.%FUNCTION_NAME% instead.
00204         '''
00205         return self._hands.airhand_r_command.execute(
00206             self._hands.airhand_r_command.AIRHAND_DRAWIN)
00207 
00208     def airhand_l_keep(self):
00209         '''
00210         @deprecated: Won't be functional after package version 0.5.1.
00211                      Use self._hands.%FUNCTION_NAME% instead.
00212         '''
00213         return self._hands.airhand_l_command.execute(
00214             self._hands.airhand_l_command.AIRHAND_KEEP)
00215 
00216     def airhand_r_keep(self):
00217         '''
00218         @deprecated: Won't be functional after package version 0.5.1.
00219                      Use self._hands.%FUNCTION_NAME% instead.
00220         '''
00221         return self._hands.airhand_r_command.execute(
00222             self._hands.airhand_r_command.AIRHAND_KEEP)
00223 
00224     def airhand_l_release(self):
00225         '''
00226         @deprecated: Won't be functional after package version 0.5.1.
00227                      Use self._hands.%FUNCTION_NAME% instead.
00228         '''
00229         return self._hands.airhand_l_command.execute(
00230             self._hands.airhand_l_command.AIRHAND_RELEASE)
00231 
00232     def airhand_r_release(self):
00233         '''
00234         @deprecated: Won't be functional after package version 0.5.1.
00235                      Use self._hands.%FUNCTION_NAME% instead.
00236         '''
00237         return self._hands.airhand_r_command.execute(
00238             self._hands.airhand_r_command.AIRHAND_RELEASE)
00239 
00240     def initialize_hand_dio(self):
00241         '''
00242         @deprecated: Won't be functional after package version 0.5.1.
00243                      Use self._hands.%FUNCTION_NAME% instead.
00244 
00245         Reset all DIO channels to "off" state except for toolchanger lockers
00246         (if they are turned off the attached tools will fall).
00247         '''
00248         self._hands.init_dio()
00249 
00250     def getRTCList(self):
00251         '''
00252         Overwriting HrpsysConfigurator.getRTCList
00253         Returning predefined list of RT components.
00254         @rtype [[str]]
00255         @rerutrn List of available components. Each element consists of a list
00256                  of abbreviated and full names of the component.
00257         '''
00258         return [
00259             ['seq', "SequencePlayer"],
00260             ['sh', "StateHolder"],
00261             ['fk', "ForwardKinematics"],
00262             ['el', "SoftErrorLimiter"],
00263             # ['co', "CollisionDetector"],
00264             # ['sc', "ServoController"],
00265             ['log', "DataLogger"]
00266             ]
00267 
00268     def goInitial(self, tm=7, wait=True, init_pose_type=0):
00269         '''
00270         @see: HIRONX.goInitial
00271         '''
00272         if not init_pose_type:
00273             # Set the pose where eefs level with the tabletop by default.
00274             init_pose_type = HIRONX.INITPOS_TYPE_EVEN
00275         return HIRONX.goInitial(self, tm, wait, init_pose_type)
00276 
00277     def readDinGroup(self, ports, dumpFlag=True):
00278         '''
00279         Print the currently set values of digital input registry. Print output order is tailored 
00280         for the hands' functional group; DIO spec that is disloseable as of 7/17/2014 is:
00281 
00282              Left hand: 
00283                   DI26: Tool changer attached or not.
00284                   DI22, 23: Fingers.
00285                   DI24, 25: Compliance.
00286 
00287              Right hand: 
00288                   DI21: Tool changer attached or not.
00289                   DI17, 18: Fingers.
00290                   DI19, 20: Compliance.
00291 
00292         Example output, for the right hand: 
00293 
00294             No hand attached:
00295 
00296                 In [1]: robot.printDin([20, 16, 17, 18, 19])
00297                 DI21 is 0
00298                 DI17 is 0
00299                 DI18 is 0
00300                 DI19 is 0
00301                 DI20 is 0
00302                 Out[1]: [(20, 0), (16, 0), (17, 0), (18, 0), (19, 0)]
00303     
00304             Hand attached, fingers closed:
00305 
00306                 In [1]: robot.printDin([20, 16, 17, 18, 19])
00307                 DI21 is 1
00308                 DI17 is 1
00309                 DI18 is 0
00310                 DI19 is 0
00311                 DI20 is 0
00312                 Out[1]: [(20, 0), (16, 0), (17, 0), (18, 0), (19, 0)]
00313     
00314         @author: Koichi Nagashima
00315         @since: 0.2.16
00316         @type ports: int or [int].
00317         @param dumpFlag: Print each pin if True.
00318         @param ports: A port number or a list of port numbers in D-in registry.
00319         @rtype: [(int, int)]
00320         @return: List of tuples of port and din value. If the arg ports was an int value, 
00321                  this could be a list with single tuple in it.
00322         '''
00323         if isinstance(ports, int):
00324             ports = [ports];
00325             pass;
00326         #din = self.rh_svc.readDigitalInput()[1];
00327         ## rh_svc.readDigitalInput() returns tuple, of which 1st element is not needed here.
00328         din = self.readDigitalInput();
00329         resAry=[];
00330         for port in ports:
00331             res = din[port]
00332             if (dumpFlag): print("DI%02d is %d"%(port+1,res));
00333             resAry.append((port, res));
00334             pass;
00335         return resAry;
00336 
00337     def readDinGroupL(self, dumpFlag=True):
00338         return self.readDinGroup(self._DI_PORTS_L, dumpFlag)
00339 
00340     def readDinGroupR(self, dumpFlag=True):
00341         return self.readDinGroup(self._DI_PORTS_R, dumpFlag)
00342 


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Fri Aug 28 2015 12:55:59