nextage_client.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 sys
38 
39 import rospy
40 from hironx_ros_bridge.hironx_client import HIRONX
41 
42 from nextage_ros_bridge.iros13_hands import Iros13Hands
43 from nextage_ros_bridge.hands_05 import Hands05
44 
45 
46 class NextageClient(HIRONX, object):
47  # The 2nd arg 'object' is passed to work around the issue raised because
48  # HrpsysConfigurator is "old-style" python class.
49  # See http://stackoverflow.com/a/18392639/577001
50  '''
51  This class holds methods that are specific to Kawada Industries' dual-arm
52  robot called Nextage Open.
53  '''
54  # TODO: Unittest s'il vous plait!
55 
56  ''' Overriding a variable in the superclass to set the arms at higher
57  positions.'''
58  OffPose = [[0], [0, 0],
59  [25, -140, -150, 45, 0, 0],
60  [-25, -140, -150, -45, 0, 0],
61  [0, 0, 0, 0],
62  [0, 0, 0, 0]]
63 
64  # Default digital input groups defined by manufacturer, Kawada, as of
65  # July 2014. This may change per the robot in the future and in then
66  # need modified. See also readDinGroup method.
67  _DI_PORTS_L = [25, 21, 22, 23, 24]
68  _DI_PORTS_R = [20, 16, 17, 18, 19]
69 
70  HAND_VER_0_4_2 = '0.4.2'
71  HAND_VER_0_5_1 = '0.5.1'
72 
73  use_gazebo = False
74 
75  def __init__(self):
76  '''
77  Do not get confused that there is also a method called
78  'init' (without trailing underscores) that is succeeded from the
79  super class as the tradition there.
80  '''
81  try:
82  if rospy.has_param('/gazebo'):
83  self.use_gazebo = True
84  print("\033[32m[INFO] Assuming Gazebo Simulator, so do not connect to CORBA systmes\033[0m")
85  # When there's no ros master running, underlining code,
86  # socket.create_connection more specifically, returns the simplest
87  # 'error' that is hard to be explicitly caught at exception block.
88  # See https://github.com/tork-a/rtmros_nextage/issues/262#issue-182487549
89  except:
90  print("ROS Master not found running. If you intended to use it (either for rosbridge or for Gazebo purposes, make sure you run necessary nodes.")
91 
92  if not self.use_gazebo:
93  super(NextageClient, self).__init__()
94  else:
95  self.configurator_name = "gazebo(Nextage)"
97 
98  def init(self, robotname="HiroNX(Robot)0", url=""):
99  '''
100  Calls init from its superclass, which tries to connect RTCManager,
101  looks for ModelLoader, and starts necessary RTC components. Also runs
102  config, logger.
103  Also internally calls setSelfGroups().
104 
105  @type robotname: str
106  @type url: str
107  '''
108  if not self.use_gazebo:
109  HIRONX.init(self, robotname=robotname, url=url)
110 
111  def get_hand_version(self):
112  '''
113  @rtype: str
114  '''
115  if not self._hand_version:
116  return 'Hand module not set yet.'
117  else:
118  return self._hand_version
119 
120  def set_hand_version(self, version=HAND_VER_0_5_1):
121  self._hand_version = version
122  if self.HAND_VER_0_4_2 == self._hand_version:
123  self._hands = Iros13Hands(self)
124  elif self.HAND_VER_0_5_1 == self._hand_version:
125  self._hands = Hands05(self)
126 
127  def _print_msg_deprecated_dio_methods(self, name_method=None):
128  '''
129  @type name_method: str
130  @param name_method: Name of the method that calls this method if available.
131  '''
132  rospy.logerr("You're likely to have called a deprecated method." +
133  " Use self._hands.{} instead".format(name_method))
134 
135  def handlight_r(self, is_on=True):
136  '''
137  @deprecated: Won't be functional after package version 0.5.1.
138  Use self._hands.%FUNCTION_NAME% instead.
139  '''
140  try:
141  return self._hands.handlight_r(is_on)
142  except AttributeError:
143  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
144 
145  def handlight_l(self, is_on=True):
146  '''
147  @deprecated: Won't be functional after package version 0.5.1.
148  Use self._hands.%FUNCTION_NAME% instead.
149  '''
150  try:
151  return self._hands.handlight_r(is_on)
152  except AttributeError:
153  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
154 
155  def handlight_both(self, is_on=True):
156  '''
157  @deprecated: Won't be functional after package version 0.5.1.
158  Use self._hands.%FUNCTION_NAME% instead.
159  '''
160  try:
161  return self._hands.handlight_both(is_on)
162  except AttributeError:
163  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
164 
165  def handtool_l_eject(self):
166  '''
167  @deprecated: Won't be functional after package version 0.5.1.
168  Use self._hands.%FUNCTION_NAME% instead.
169  '''
170  try:
171  return self._hands.toolchanger_l_command.execute(
172  self._hands.toolchanger_l_command.HAND_TOOLCHANGE_OFF)
173  except AttributeError:
174  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
175 
176  def handtool_r_eject(self):
177  '''
178  @deprecated: Won't be functional after package version 0.5.1.
179  Use self._hands.%FUNCTION_NAME% instead.
180  '''
181  try:
182  return self._hands.toolchanger_r_command.execute(
183  self._hands.toolchanger_r_command.HAND_TOOLCHANGE_OFF)
184  except AttributeError:
185  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
186 
187  def handtool_l_attach(self):
188  '''
189  @deprecated: Won't be functional after package version 0.5.1.
190  Use self._hands.%FUNCTION_NAME% instead.
191  '''
192  try:
193  return self._hands.toolchanger_l_command.execute(
194  self._hands.toolchanger_l_command.HAND_TOOLCHANGE_ON)
195  except AttributeError:
196  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
197 
198  def handtool_r_attach(self):
199  '''
200  @deprecated: Won't be functional after package version 0.5.1.
201  Use self._hands.%FUNCTION_NAME% instead.
202  '''
203  try:
204  return self._hands.toolchanger_r_command.execute(
205  self._hands.toolchanger_r_command.HAND_TOOLCHANGE_ON)
206  except AttributeError:
207  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
208 
209  def gripper_l_close(self):
210  '''
211  @deprecated: Won't be functional after package version 0.5.1.
212  Use self._hands.%FUNCTION_NAME% instead.
213  '''
214  try:
215  return self._hands.gripper_l_command.execute(
216  self._hands.gripper_l_command.GRIPPER_CLOSE)
217  except AttributeError:
218  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
219 
220  def gripper_r_close(self):
221  '''
222  @deprecated: Won't be functional after package version 0.5.1.
223  Use self._hands.%FUNCTION_NAME% instead.
224  '''
225  try:
226  return self._hands.gripper_r_command.execute(
227  self._hands.gripper_r_command.GRIPPER_CLOSE)
228  except AttributeError:
229  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
230 
231  def gripper_l_open(self):
232  '''
233  @deprecated: Won't be functional after package version 0.5.1.
234  Use self._hands.%FUNCTION_NAME% instead.
235  '''
236  try:
237  return self._hands.gripper_l_command.execute(
238  self._hands.gripper_r_command.GRIPPER_OPEN)
239  except AttributeError:
240  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
241 
242  def gripper_r_open(self):
243  '''
244  @deprecated: Won't be functional after package version 0.5.1.
245  Use self._hands.%FUNCTION_NAME% instead.
246  '''
247  try:
248  return self._hands.gripper_r_command.execute(
249  self._hands.gripper_r_command.GRIPPER_OPEN)
250  except AttributeError:
251  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
252 
253  def airhand_l_drawin(self):
254  '''
255  @deprecated: Won't be functional after package version 0.5.1.
256  Use self._hands.%FUNCTION_NAME% instead.
257  '''
258  try:
259  return self._hands.airhand_l_command.execute(
260  self._hands.airhand_l_command.AIRHAND_DRAWIN)
261  except AttributeError:
262  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
263 
264  def airhand_r_drawin(self):
265  '''
266  @deprecated: Won't be functional after package version 0.5.1.
267  Use self._hands.%FUNCTION_NAME% instead.
268  '''
269  try:
270  return self._hands.airhand_r_command.execute(
271  self._hands.airhand_r_command.AIRHAND_DRAWIN)
272  except AttributeError:
273  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
274 
275  def airhand_l_keep(self):
276  '''
277  @deprecated: Won't be functional after package version 0.5.1.
278  Use self._hands.%FUNCTION_NAME% instead.
279  '''
280  try:
281  return self._hands.airhand_l_command.execute(
282  self._hands.airhand_l_command.AIRHAND_KEEP)
283  except AttributeError:
284  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
285 
286  def airhand_r_keep(self):
287  '''
288  @deprecated: Won't be functional after package version 0.5.1.
289  Use self._hands.%FUNCTION_NAME% instead.
290  '''
291  try:
292  return self._hands.airhand_r_command.execute(
293  self._hands.airhand_r_command.AIRHAND_KEEP)
294  except AttributeError:
295  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
296 
297  def airhand_l_release(self):
298  '''
299  @deprecated: Won't be functional after package version 0.5.1.
300  Use self._hands.%FUNCTION_NAME% instead.
301  '''
302  try:
303  return self._hands.airhand_l_command.execute(
304  self._hands.airhand_l_command.AIRHAND_RELEASE)
305  except AttributeError:
306  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
307 
308  def airhand_r_release(self):
309  '''
310  @deprecated: Won't be functional after package version 0.5.1.
311  Use self._hands.%FUNCTION_NAME% instead.
312  '''
313  try:
314  return self._hands.airhand_r_command.execute(
315  self._hands.airhand_r_command.AIRHAND_RELEASE)
316  except AttributeError:
317  self._print_msg_deprecated_dio_methods(sys._getframe().f_code.co_name)
318 
320  '''
321  @deprecated: Won't be functional after package version 0.5.1.
322  Use self._hands.%FUNCTION_NAME% instead.
323 
324  Reset all DIO channels to "off" state except for toolchanger lockers
325  (if they are turned off the attached tools will fall).
326  '''
327  self._hands.init_dio()
328 
329  def getRTCList(self):
330  '''
331  Overwriting HrpsysConfigurator.getRTCList
332  Returning predefined list of RT components.
333  @rtype [[str]]
334  @return List of available components. Each element consists of a list
335  of abbreviated and full names of the component.
336  '''
337  return [
338  ['seq', "SequencePlayer"],
339  ['sh', "StateHolder"],
340  ['fk', "ForwardKinematics"],
341  ['el', "SoftErrorLimiter"],
342  # ['co', "CollisionDetector"],
343  # ['sc', "ServoController"],
344  ['ic', "ImpedanceController"],
345  ['log', "DataLogger"]
346  ]
347 
348  def goInitial(self, tm=7, wait=True, init_pose_type=0):
349  '''
350  @see: HIRONX.goInitial
351  '''
352  if not init_pose_type:
353  # Set the pose where eefs level with the tabletop by default.
354  init_pose_type = HIRONX.INITPOS_TYPE_EVEN
355  return HIRONX.goInitial(self, tm, wait, init_pose_type)
356 
357  def readDinGroup(self, ports, dumpFlag=True):
358  '''
359  Print the currently set values of digital input registry. Print output order is tailored
360  for the hands' functional group; DIO spec that is disloseable as of 7/17/2014 is:
361 
362  Left hand:
363  DI26: Tool changer attached or not.
364  DI22, 23: Fingers.
365  DI24, 25: Compliance.
366 
367  Right hand:
368  DI21: Tool changer attached or not.
369  DI17, 18: Fingers.
370  DI19, 20: Compliance.
371 
372  Example output, for the right hand:
373 
374  No hand attached:
375 
376  In [1]: robot.printDin([20, 16, 17, 18, 19])
377  DI21 is 0
378  DI17 is 0
379  DI18 is 0
380  DI19 is 0
381  DI20 is 0
382  Out[1]: [(20, 0), (16, 0), (17, 0), (18, 0), (19, 0)]
383 
384  Hand attached, fingers closed:
385 
386  In [1]: robot.printDin([20, 16, 17, 18, 19])
387  DI21 is 1
388  DI17 is 1
389  DI18 is 0
390  DI19 is 0
391  DI20 is 0
392  Out[1]: [(20, 0), (16, 0), (17, 0), (18, 0), (19, 0)]
393 
394  @author: Koichi Nagashima
395  @since: 0.2.16
396  @type ports: int or [int].
397  @param dumpFlag: Print each pin if True.
398  @param ports: A port number or a list of port numbers in D-in registry.
399  @rtype: [(int, int)]
400  @return: List of tuples of port and din value. If the arg ports was an int value,
401  this could be a list with single tuple in it.
402  '''
403  if isinstance(ports, int):
404  ports = [ports];
405  pass;
406  #din = self.rh_svc.readDigitalInput()[1];
407  ## rh_svc.readDigitalInput() returns tuple, of which 1st element is not needed here.
408  din = self.readDigitalInput();
409  resAry=[];
410  for port in ports:
411  res = din[port]
412  if (dumpFlag): print("DI%02d is %d"%(port+1,res));
413  resAry.append((port, res));
414  pass;
415  return resAry;
416 
417  def readDinGroupL(self, dumpFlag=True):
418  return self.readDinGroup(self._DI_PORTS_L, dumpFlag)
419 
420  def readDinGroupR(self, dumpFlag=True):
421  return self.readDinGroup(self._DI_PORTS_R, dumpFlag)
422 
def readDinGroup(self, ports, dumpFlag=True)
def init(self, robotname="HiroNX(Robot)0", url="")
def set_hand_version(self, version=HAND_VER_0_5_1)
def _print_msg_deprecated_dio_methods(self, name_method=None)
def goInitial(self, tm=7, wait=True, init_pose_type=0)


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