16 import xml.etree.ElementTree
as ET
18 from geometry_msgs.msg
import Pose
23 DEFAULT_BLEND_RADIUS = 0.01
27 BLEND_RADIUS_STR =
"blend_radius" 29 START_POS_STR =
"startPos" 30 END_POS_STR =
"endPos" 31 PLANNING_GROUP_STR =
"planningGroup" 32 LINK_NAME_STR =
"targetLink" 33 INTERIM_POS_STR =
"interimPos" 34 CENTER_POS_STR =
"centerPos" 35 AUXILIARY_POS_STR =
"auxiliaryPos" 36 DEFAULT_LINK_NAME =
"prbt_tcp" 41 _PATH_TO_JOINTS =
"./poses/pos[@name='{pose_name}']/group[@name='{group_name}']/joints" 42 _PATH_TO_POSE =
"./poses/pos[@name='{pose_name}']/group[@name='{group_name}']/xyzQuat" 43 _PATH_TO_PTP =
"./ptps/ptp[@name='{name_of_cmd}']" 44 _PATH_TO_LIN =
"./lins/lin[@name='{name_of_cmd}']" 45 _PATH_TO_CIRC =
"./circs/circ[@name='{name_of_cmd}']" 46 _PATH_TO_SEQUENCE =
"./sequences/sequence[@name='{name_of_cmd}']" 52 self.
_tree = ET.parse(path_to_xml_file)
53 self.
_root = self._tree.getroot()
57 joint_node = self._root.find(_PATH_TO_JOINTS.format(pose_name=pose_name, group_name=group_name))
58 if joint_node
is None:
60 return [eval(elem)
for elem
in re.split(
r'[^\S\n\t]+', joint_node.text)]
63 node = self._root.find(_PATH_TO_POSE.format(pose_name=pose_name, group_name=group_name))
66 pose_list = [eval(elem)
for elem
in re.split(
r'[^\S\n\t]+', node.text)]
68 pose.position.x = pose_list[0]
69 pose.position.y = pose_list[1]
70 pose.position.z = pose_list[2]
71 pose.orientation.x = pose_list[3]
72 pose.orientation.y = pose_list[4]
73 pose.orientation.z = pose_list[5]
74 pose.orientation.w = pose_list[6]
81 return self.
_get_cmd(_PATH_TO_PTP, name_of_cmd)
87 return self.
_get_cmd(_PATH_TO_LIN, name_of_cmd)
94 def get_circ(self, name_of_cmd, auxiliaray_pos_type=INTERIM_POS_STR):
95 cmdRes = self.
_get_cmd(_PATH_TO_CIRC, name_of_cmd)
99 cmdNode = self._root.find(_PATH_TO_CIRC.format(name_of_cmd=name_of_cmd))
102 auxiliaryNode = cmdNode.find(
"./{}".format(auxiliaray_pos_type))
103 if auxiliaryNode
is None:
106 return {START_POS_STR: cmdRes[START_POS_STR], auxiliaray_pos_type: auxiliaryNode.text,
107 END_POS_STR: cmdRes[END_POS_STR], VEL_STR: cmdRes[VEL_STR], ACC_STR: cmdRes[ACC_STR],
108 PLANNING_GROUP_STR: cmdRes[PLANNING_GROUP_STR], LINK_NAME_STR: cmdRes[LINK_NAME_STR]}
115 sequenceNode = self._root.find(_PATH_TO_SEQUENCE.format(name_of_cmd=name_of_cmd))
116 if sequenceNode
is None:
121 for sequenceCmdNode
in sequenceNode.getchildren():
122 cmd_name = sequenceCmdNode.get(NAME_STR)
126 cmd_type = sequenceCmdNode.get(TYPE_STR)
130 blend_radius = sequenceCmdNode.get(BLEND_RADIUS_STR, DEFAULT_BLEND_RADIUS)
131 sequenceCmds.append({NAME_STR: cmd_name, TYPE_STR: cmd_type, BLEND_RADIUS_STR: blend_radius})
140 cmd_node = self._root.find(path_to_cmd_type.format(name_of_cmd=name_of_cmd))
144 start_pos_node = cmd_node.find(
"./{}".format(START_POS_STR))
145 if start_pos_node
is None:
148 end_pos_node = cmd_node.find(
"./{}".format(END_POS_STR))
149 if end_pos_node
is None:
152 planning_group_node = cmd_node.find(
"./{}".format(PLANNING_GROUP_STR))
153 if planning_group_node
is None:
157 vel_node = cmd_node.find(
"./{}".format(VEL_STR))
158 vel = DEFAULT_VEL
if vel_node
is None else float(vel_node.text)
160 acc_node = cmd_node.find(
"./{}".format(ACC_STR))
161 acc = DEFAULT_ACC
if acc_node
is None else float(acc_node.text)
163 target_link_node = cmd_node.find(
"./{}".format(LINK_NAME_STR))
164 target_link_name = DEFAULT_LINK_NAME
if target_link_node
is None else target_link_node.text
166 return {START_POS_STR: start_pos_node.text, END_POS_STR: end_pos_node.text, VEL_STR: vel, ACC_STR: acc,
167 PLANNING_GROUP_STR: planning_group_node.text, LINK_NAME_STR: target_link_name}
def __init__(self, path_to_xml_file)
def get_sequence(self, name_of_cmd)
def get_joints(self, pose_name, group_name)
def get_ptp(self, name_of_cmd)
def _get_cmd(self, path_to_cmd_type, name_of_cmd)
def get_pose(self, pose_name, group_name)
def get_circ(self, name_of_cmd, auxiliaray_pos_type=INTERIM_POS_STR)
def get_lin(self, name_of_cmd)