Rosanswers logo


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:
    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 = rospy.Time.now()

# 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/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..

Originally posted by Rizqa on ROS Answers with karma: 45 on 2013-03-31

Post score: 0


1 Answer 1


Rosanswers logo

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.

Originally posted by felix k with karma: 1650 on 2013-04-02

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.