The get joints for a URDF trouble
Hi..
I try to get joints command parses a URDF description of the robot to get all the non-fixed joints..so I add a function is taken from the joint_state_publisher package written by David Lu..
I try to call the function self.send_to_urdf = self.get_joints()
def get_joints():
description = rospy.get_param("robot_description")
robot = xml.dom.minidom.parseString(description).getElementsByTagName('robot')[0]
free_joints = {}
joint_list = [] # for maintaining the original order of the joints
dependent_joints = rospy.get_param("dependent_joints", {})
# Find all non-fixed joints.
for child in robot.childNodes:
if child.nodeType is child.TEXT_NODE:
continue
if child.localName == 'joint':
jtype = child.getAttribute('type')
if jtype == 'fixed':
continue
name = child.getAttribute('name')
if jtype == 'continuous':
minval = -pi
maxval = pi
else:
limit = child.getElementsByTagName('limit')[0]
minval = float(limit.getAttribute('lower'))
maxval = float(limit.getAttribute('upper'))
if name in dependent_joints:
continue
if minval > 0 or maxval < 0:
zeroval = (maxval + minval)/2
else:
zeroval = 0
joint = {'min':minval, 'max':maxval, 'zero':zeroval, 'value':zeroval }
free_joints[name] = joint
joint_list.append(name)
joint_state = JointState()
joint_state.header.stamp = rospy.Time.now()
# Add Free Joints.
for (name, joint) in free_joints.items():
joint_state.name.append(str(name))
joint_state.position.append(joint['value'])
joint_state.velocity.append(0)
return joint_state
but When I run the script in terminal.. there is problem
File "/home/rizqa/BISMILLAH_TUGAS_AKHIR/roboteleop/bin/bismillah_code2.py", line 73, in get_joints if name in dependent_joints: UnboundLocalError: local variable 'name' referenced before assignment
How this problem solved..?? thanks for your time..