arm_finder.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2015 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 import rospy
18 from urdf_parser_py.urdf import URDF
19 from hand_finder import HandJoints
20 
21 
22 class ArmConfig(object):
23 
24  def __init__(self, mapping, joint_prefix):
25  """
26  Initializes arm configuration
27  """
28  self.mapping = mapping
29  self.joint_prefix = joint_prefix
30 
31 
32 class ArmFinder(object):
33  """
34  The ArmFinder is a utility library for detecting arms running on
35  the system. The idea is to make it easier to write generic code,
36  using this library to handle prefixes, joint prefixes etc...
37  """
38 
39  def __init__(self):
40  """
41  Parses the parameter server to extract the necessary information.
42  """
43  if not rospy.has_param("arm"):
44  rospy.logerr("No arm param defined.")
45  arm_parameters = {'joint_prefix': {}, 'mapping': {}}
46  else:
47  arm_parameters = rospy.get_param("arm")
48 
49  # TODO(@anyone): This parameter is never set. This script needs to be modified to find available
50  # arms from robot_description and present them appropriately. (sr_core issue #74)
51 
52  self.arm_config = ArmConfig(arm_parameters["mapping"], arm_parameters["joint_prefix"])
53  self.arm_joints = {}
54 
55  if rospy.has_param('robot_description'):
56 
57  robot_description = rospy.get_param('robot_description')
58  robot_urdf = URDF.from_xml_string(robot_description)
59 
60  hand_default_joints = HandJoints.get_default_joints()
61  possible_arm_joints = []
62 
63  for joint in robot_urdf.joints:
64  if joint.type != 'fixed' and joint.name not in hand_default_joints:
65  match_suffix = False
66  for hand_default_joint_name in hand_default_joints:
67  if joint.name.endswith('_' + hand_default_joint_name):
68  match_suffix = True
69  break
70 
71  if not match_suffix:
72  possible_arm_joints.append(joint.name)
73 
74  for arm_id, arm_mapping in self.arm_config.mapping.iteritems():
75  self.arm_joints[arm_mapping] = []
76  arm_joint_prefix = self.arm_config.joint_prefix[arm_id]
77  for joint_name in possible_arm_joints:
78  if joint_name.startswith(arm_joint_prefix):
79  self.arm_joints[arm_mapping].append(joint_name)
80  else:
81  rospy.logwarn("No robot_description found on parameter server. Assuming that there is no arm.")
82 
83  def get_arm_joints(self):
84  return self.arm_joints
85 
86  def get_arm_parameters(self):
87  return self.arm_config
def __init__(self, mapping, joint_prefix)
Definition: arm_finder.py:24


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:19