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 time
00038 import threading
00039
00040 import rospy
00041
00042 from abs_hand_command import AbsractHandCommand
00043
00044
00045 class AirhandReleaseThread(threading.Thread):
00046 '''
00047 With airhand, to release by blowing air needs to be stopped after certain
00048 amount of time. Usually a few seconds, not too short for the air compressor
00049 to have ample time for a reaction, is a good idea. This thread is used
00050 in order to do so without letting the computer program halt.
00051 '''
00052 def __init__(self, command, sleeptime):
00053 '''
00054 @type command: AirhandCommand
00055 '''
00056 threading.Thread.__init__(self)
00057 self._command = command
00058 self._sleeptime = sleeptime
00059
00060 def run(self):
00061 time.sleep(self._sleeptime)
00062 self._command.execute(self._command.AIRHAND_KEEP)
00063
00064
00065 class AirhandCommand(AbsractHandCommand):
00066 '''dio_writer
00067 Following Command design pattern, this class represents command for
00068 an Airhand of NEXTAGE OPEN.
00069
00070 As of 2/1/2014, it's only implemented for a right arm (since there's no
00071 testing environment for left arm).
00072 '''
00073
00074
00075
00076 AIRHAND_DRAWIN = 'drawin'
00077 AIRHAND_KEEP = 'keep'
00078 AIRHAND_RELEASE = 'release'
00079
00080
00081
00082 AIRHAND_DANGER = 'danger'
00083
00084 def __init__(self, hands, hand):
00085 '''
00086 @see nextage_ros_bridge.command.abs_hand_command.AbsractHandCommand
00087 @type hands: nextage_ros_bridge.base_hands.BaseHands
00088 @type hand: str
00089 @param hand: Side of hand. Variables that are defined in
00090 nextage_ros_bridge.base_hands.BaseHands can be used { HAND_L, HAND_R }.
00091 '''
00092 super(AirhandCommand, self).__init__(hands, hand)
00093 self._SLEEP_POST_RELEASE = 3.0
00094
00095 def _assign_dio_names(self):
00096 '''
00097 @see abs_hand_command.AbsractHandCommand._assign_dio_names
00098 '''
00099
00100 self._DIO_SUCTION_R_1 = self._DIO_22
00101 self._DIO_SUCTION_R_2 = self._DIO_23
00102 self._DIO_SUCTION_L_1 = self._DIO_27
00103 self._DIO_SUCTION_L_2 = self._DIO_28
00104
00105 def execute(self, operation):
00106 '''
00107 @see abs_hand_command.AbsractHandCommand.execute
00108 '''
00109 dout = []
00110 mask = [self._DIO_SUCTION_R_1, self._DIO_SUCTION_R_2]
00111
00112
00113 if self.AIRHAND_DRAWIN == operation:
00114 if self._hands.HAND_L == self._hand:
00115 dout = [self._DIO_SUCTION_L_1]
00116 elif self._hands.HAND_R == self._hand:
00117 dout = [self._DIO_SUCTION_R_1]
00118 elif self.AIRHAND_KEEP == operation:
00119 if self._hands.HAND_L == self._hand:
00120 pass
00121 elif self._hands.HAND_R == self._hand:
00122 pass
00123 elif self.AIRHAND_RELEASE == operation:
00124 if self._hands.HAND_L == self._hand:
00125 dout = [self._DIO_SUCTION_L_2]
00126 elif self._hands.HAND_R == self._hand:
00127 dout = [self._DIO_SUCTION_R_2]
00128
00129
00130
00131 thread = AirhandReleaseThread(self, self._SLEEP_POST_RELEASE)
00132 thread.start()
00133 else:
00134
00135 rospy.logwarn('No gripper specified. Do nothing.')
00136 return
00137 self._hands._dio_writer(dout, mask)