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

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():

        rospy.loginfo(str(x))


        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 = rospy.Time.now()
        vel.header.frame_id = ''
        vel.header.seq=1
        rospy.loginfo(vel.velocity[1])
        rospy.loginfo("Velocity will be transmitted")
        velPub.publish(vel)
        rospy.loginfo("Velocity has been transmitted")
        rate.sleep()


if __name__ == '__main__':
  try:
      talker()
  #velocity_talker()
  except rospy.ROSInterruptException:
      pass
edit retag flag offensive close merge delete

Comments

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
1

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

Stats

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

Seen: 813 times

Last updated: Dec 04 '17