convert-tactile-to-urdf.py
Go to the documentation of this file.
1 import xmltodict
2 from collections import namedtuple
3 import numpy as np
4 import rospy
5 import roslib
6 
7 Pose = namedtuple('Pose', ['xyz', 'rpy'], verbose=True)
8 
9 def get_pose_array(filter_array, palm, rpy=[0,0,0]):
10  pa = []
11 
12  for i in range(len(filter_array)):
13  loc_string = filter_array[i]['@params'].split(',')
14  loc = np.array(loc_string, dtype=float)
15 
16  xyz = np.mean(loc.reshape((2,3)),0)/1000
17  if palm:
18  #0.08 eyeballed - could be entirely wrong
19  #Based off of bh_base_link transform
20  xyz = [xyz[0], xyz[1], 0.075]
21  else:
22  xyz = [xyz[1], xyz[0], xyz[2]]
23 
24  pa.append(Pose(xyz=xyz, rpy=rpy))
25 
26  return pa
27 
28 def get_path(package_name, resource_name):
29  resources = roslib.packages.find_resource(package_name, resource_name)
30  if len(resources) == 0:
31  rospy.logerr("Failed to find resource %s in package %s"%(resource_name, package_name))
32  return ""
33  else:
34  return resources[0]
35 
36 tactile_filename = get_path('graspit', 'BarrettBH8_280_Tactile.xml')
37 
38 with open(tactile_filename) as fd:
39  doc = xmltodict.parse(fd.read())
40 
41 palm_sensors = get_pose_array(doc['robot']['filter'], True)
42 
43 barrett_sensors = {}
44 barrett_sensors['palm'] = palm_sensors
45 
46 for index, chain_num in enumerate(range(len(doc['robot']['chain'])), 1):
47 
48  finger_sensors = get_pose_array(doc['robot']['chain'][chain_num]['filter'], False)
49  barrett_sensors['link{}'.format(index)] = finger_sensors
50 
51 
52 text_poses = ""
53 for i, pose in enumerate(barrett_sensors['palm'], 1):
54  text_poses += '<joint name="${{name}}_palm_sensor{}_joint" type="fixed">\n'.format(i)
55  text_poses += '\t<origin xyz="{} {} {}" rpy="{} {} {}"/>\n'.format(pose.xyz[0], pose.xyz[1], pose.xyz[2], pose.rpy[0], pose.rpy[1], pose.rpy[2])
56  text_poses += '\t<parent link="${name}_base_link"/>\n'
57  text_poses += '\t<child link="${{name}}_palm_sensor_{}_link"/>\n'.format(i)
58  text_poses += '</joint>\n'
59  text_poses += '<link name="${{name}}_palm_sensor_{}_link"/>\n'.format(i)
60 
61 for link_num in range(1, 4):
62  for i, pose in enumerate(barrett_sensors['link{}'.format(link_num)], 1):
63  text_poses += '<joint name="${{name}}_link{}_sensor{}_joint" type="fixed">\n'.format(link_num, i)
64  text_poses += '\t<origin xyz="{} {} {}" rpy="{} {} {}"/>\n'.format(pose.xyz[0], pose.xyz[1], pose.xyz[2], pose.rpy[0], pose.rpy[1], pose.rpy[2])
65  text_poses += '\t<parent link="bh_finger_{}4_link"/>\n'.format(link_num)
66  text_poses += '\t<child link="${{name}}_link{}_sensor{}_link"/>\n'.format(link_num, i)
67  text_poses += '</joint>\n'
68  text_poses += '<link name="${{name}}_link{}_sensor{}_link"/>\n'.format(link_num, i)
69 
70 
71 import pyperclip
72 pyperclip.copy(text_poses)
def get_path(package_name, resource_name)
def get_pose_array(filter_array, palm, rpy=[0)


barrett_hand_description
Author(s):
autogenerated on Wed Jul 24 2019 03:26:17