robot_tool_interface.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # FSRobo-R Package BSDL
4 # ---------
5 # Copyright (C) 2019 FUJISOFT. All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation and/or
13 # other materials provided with the distribution.
14 # 3. Neither the name of the copyright holder nor the names of its contributors
15 # may be used to endorse or promote products derived from this software without
16 # specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # --------
29 
30 import rospy
31 from control_msgs.msg import GripperCommandAction, GripperCommandGoal, GripperCommand
32 import actionlib
33 import moveit_commander
34 from fsrobo_r_driver.geometry_util import GeometryUtil
35 import tf
36 import math
37 
39  def __init__(self, tool_name=None):
40  if tool_name:
41  self.ns = '/' + tool_name + '/'
42  else:
43  self.ns = '/'
44  self._offset = rospy.get_param(self.ns + 'tool/offset', [0, 0, 0, 0, 0, 0])
45  self._action_ns = rospy.get_param(self.ns + 'tool/action_ns', None)
46  print(self._action_ns)
47  self._origin_link = rospy.get_param(self.ns + 'tool/origin_link', None)
48  self._planning_group = rospy.get_param(self.ns + 'tool/planning_group', None)
49 
51 
52  if self._action_ns:
53  self._open_param = rospy.get_param(self.ns + 'tool/open_param')
54  self._close_param = rospy.get_param(self.ns + 'tool/close_param')
55  self._client = actionlib.SimpleActionClient(self._action_ns, GripperCommandAction)
56  else:
57  self._open_param = None
58  self._close_param = None
59  self._client = None
60 
61  if self._origin_link and self._planning_group:
62  self._move_group = moveit_commander.MoveGroupCommander(self._planning_group)
63  ee_link = self._move_group.get_end_effector_link()
64  pose = self._geometry_util.get_current_pose(self._origin_link, ee_link)
65  tool_pos = map(lambda x: x * 1000.0, pose[0])
66  tool_ori = map(lambda x: math.degrees(x),tf.transformations.euler_from_quaternion(pose[1], axes='rzyx'))
67  self._offset = tool_pos + tool_ori
68  else:
69  self._offset = [0, 0, 0, 0, 0, 0]
70 
71  def open(self, wait=True):
72  if self._client and self._client.wait_for_server(rospy.Duration(5)):
73  goal = GripperCommandGoal()
74  goal.command.position = self._open_param[0]
75  goal.command.max_effort = self._open_param[1]
76  self._client.send_goal(goal)
77  if wait:
78  return self._client.wait_for_result(rospy.Duration(5))
79  else:
80  rospy.sleep(3)
81  return True
82  else:
83  return False
84 
85  def close(self, wait=True):
86  if self._client and self._client.wait_for_server(rospy.Duration(5)):
87  goal = GripperCommandGoal()
88  goal.command.position = self._close_param[0]
89  goal.command.max_effort = self._close_param[1]
90  self._client.send_goal(goal)
91  if wait:
92  return self._client.wait_for_result(rospy.Duration(5))
93  else:
94  rospy.sleep(3)
95  return True
96  else:
97  return False
98 
99  def get_offset(self, index=0):
100  return self._offset
101 
102 if __name__ == '__main__':
103  rospy.init_node('test', anonymous=True)
104  #tool = RobotToolInterface('arm2/tool2')
105  #tool = RobotToolInterface('generic_hand')
106  tool = RobotToolInterface('tool1')
107  print(tool.get_offset())
108  #print tool.open(wait=False)
109  #print tool.close(wait=False)


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29