Ask Your Question

The get joints for a URDF trouble

asked 2013-03-31 18:16:05 -0500

Rizqa gravatar image

updated 2013-03-31 21:08:39 -0500


I try to get joints command parses a URDF description of the robot to get all the non-fixed 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:
    if child.localName == 'joint':
        jtype = child.getAttribute('type')
        if jtype == 'fixed':
        name = child.getAttribute('name')

        if jtype == 'continuous':
            minval = -pi
            maxval = pi
            limit = child.getElementsByTagName('limit')[0]
            minval = float(limit.getAttribute('lower'))
            maxval = float(limit.getAttribute('upper'))

        if name in dependent_joints:
        if minval > 0 or maxval < 0:
            zeroval = (maxval + minval)/2
            zeroval = 0

        joint = {'min':minval, 'max':maxval, 'zero':zeroval, 'value':zeroval }
        free_joints[name] = joint

joint_state = JointState()
joint_state.header.stamp =

# Add Free Joints.
for (name, joint) in free_joints.items():

return joint_state

but When I run the script in terminal.. there is problem

File "/home/rizqa/BISMILLAH_TUGAS_AKHIR/roboteleop/bin/", 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..

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-04-02 00:27:02 -0500

felix k gravatar image

As the error message in detail explains, you cannot e.g. append to a list if the list isn't existent.

The line:

You have to setup the message with empty lists above the loop.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-31 18:16:05 -0500

Seen: 242 times

Last updated: Apr 02 '13