ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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:

joint_state.name.append(str(name))

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

edit flag offensive delete link more

Question Tools

Stats

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

Seen: 376 times

Last updated: Apr 02 '13