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

Simple Command to robot fails

asked 2017-12-01 09:23:20 -0500

Smoerebroed gravatar image

updated 2017-12-01 15:16:43 -0500

jayess gravatar image

I have a problem writing a simple node that publishes messages of a type called JointVelocity which has 2 objects called velocity of the type JointQuantity and header of the type Header. When I run the following code I get the message:

TypeError: unbound method serialize() must be called with JointVelocity instance as first agrugment (got  String0 instance instead)

Thanks for your help! Code:

#!/usr/bin/env python

import rospy
from std_msgs.msg import String
from std_msgs.msg import Header
from std_msgs.msg import Float32
from iiwa_msgs.msg import JointVelocity

def talker():
    velPub = rospy.Publisher('iiwa/command/JointVelocity',JointVelocity ,queue_size=10)
    rospy.init_node('Velocity_Transmitter', anonymous =False)

    rate = rospy.Rate(0.5) # 10hz
    x = 0
    rospy.loginfo("Talker gestartet")
    while not rospy.is_shutdown():


        x = x + 1

        vel = JointVelocity

        vel.velocity = [Float32(0.1),Float32(0.2),Float32(0.1),Float32(0.1),Float32(0.1),Float32(0.1),Float32(0.1)]

        vel.header= Header()
        vel.header.stamp =
        vel.header.frame_id = ''
        rospy.loginfo("Velocity will be transmitted")
        rospy.loginfo("Velocity has been transmitted")

if __name__ == '__main__':
  except rospy.ROSInterruptException:
edit retag flag offensive close merge delete


What's the full error? Many times there's an indication to what line is giving you problems. Also, is this all of your code? I just ran it and got no errors.

jayess gravatar image jayess  ( 2017-12-01 15:12:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-12-04 02:06:13 -0500

Humpelstilzchen gravatar image

updated 2017-12-04 02:06:48 -0500

You have:

vel = JointVelocity
vel.velocity = [Float32(0.1),Float32(0.2),Float32(0.1),Float32(0.1),Float32(0.1),Float32(0.1),Float32(0.1)]

Where you try to feet the velocity values in the JointVelocity class itself. What you want is to create an instance first (Note the braces):

vel = JointVelocity()
vel.velocity = [...]

Also you usually don't need to cast to Float32, so you can simply write

vel.velocity = [0.1, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1]
edit flag offensive delete link more

Question Tools


Asked: 2017-12-01 09:23:20 -0500

Seen: 801 times

Last updated: Dec 04 '17