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

failed to parse a URDF description

asked 2013-04-03 08:10:41 -0500

Rizqa gravatar image

updated 2013-04-05 02:51:47 -0500

I try to rosrun a node in terminal.. I get this error in terminal

>File "/home/rizqa/robocop/bin/code2.py", line 37, in __init__ self.kirim_ke_servo = >self.get_joints()
>File "/home/rizqa/robocop/robocop/bin/code2.py", line 95, in get_joints self.send_ke_servo_pub.publish(self.send_ke_servo)
>AttributeError: tracksendi instance has no attribute 'send_ke_servo'

How to fix the problem ?? -__-

This is the source code :

#!/usr/bin/env python

import roslib; roslib.load_manifest('robocop')

import rospy

from sensor_msgs.msg import JointState

from robocop.msg import Skeleton

import PyKDL

import xml.dom.minidom


class tracksendi():

    def __init__(self):
        rospy.init_node('track_sendi')
        rospy.on_shutdown(self.shutdown)
        rospy.loginfo("Init..")

        rate = rospy.Rate(10)
        rospy.Subscriber('skeleton', Skeleton, self.update_skeleton)

        self.send_ke_servo =self.get_joints()
        self.save_send_ke_servo = self.get_joints()

    def get_joints(self):
        """ This function is taken from the joint_state_publisher package written by David Lu!!
            http://www.ros.org/wiki/joint_state_publisher
        """
        description = rospy.get_param("robot_description")
        robot = xml.dom.minidom.parseString(description).getElementsByTagName('robot')[0]
        self.free_joints = {}
        self.joint_list = [] # for maintaining the original order of the joints
        self.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 self.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 }
                    self.free_joints[name] = joint
                    self.joint_list.append(name)

        joint_state = JointState()
        joint_state.header.stamp = rospy.Time.now()

            # Add Free Joints.
            for (name, joint) in self.free_joints.items():
                joint_state.name.append(str(name))
                joint_state.position.append(joint['value'])
                joint_state.velocity.append(0)

            return joint_state

        while not rospy.is_shutdown():

              self.get_joints()
              self.send_ke_servo_pub.publish(self.kirim_ke_servo)
              self.send_ke_servo.header.stamp = rospy.Time.now()
              self.save_send_ke_servo = self.kirim_ke_servo
    def joint_state_handler(self, msg):
            for joint in msg.name:  
                self.kirim_ke_urdf = msg

    def shutdown(self):
            rospy.loginfo('Shutting down Tracker Node.')



if __name__ == '__main__':

    try:

        tracksendi()

    except rospy.ROSInterruptException:

        pass
edit retag flag offensive close merge delete

Comments

It doesn't seem like the example code you posted matches the error message. In particular, I can't find the line "self.send_ke_servo_pub.publish(self.send_ke_servo)" anywhere in your posted source-code. Please update the code (or error message) to match.

Jeremy Zoss gravatar image Jeremy Zoss  ( 2013-04-04 05:44:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-04-11 05:31:11 -0500

David Lu gravatar image

You don't initialize send_ke_servo_pub anywhere. You need to initialize it as a rospy.Publisher.

edit flag offensive delete link more

Comments

Thanks @David Lu it works.. ^_^

Rizqa gravatar image Rizqa  ( 2013-04-11 06:33:21 -0500 )edit

Question Tools

Stats

Asked: 2013-04-03 08:10:41 -0500

Seen: 315 times

Last updated: Apr 11 '13