Error publishing data to topic
Hello! I was working on a small python program to control a robot arm in Gazebo. My goal with this small program is to make the arm do an oscillating motion and I use /joint_group_pos_controller/command to publish the joint states.
This is the code:
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
from std_msgs.msg import Float64MultiArray
#from trajectory_msgs import JointTrajectory
def talker():
pub = rospy.Publisher('/joint_group_pos_controller/command', Float64MultiArray, queue_size=10)
rospy.init_node('arm_move_control', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
data = [0.0, -2.0, 0.0, -1.57, 0.0, -0.5]
pub.publish(1,data)
rospy.sleep(4)
data = [0.0, -1.57, 0.0, -2.0, 0.0, -1.5]
pub.publish(1,data)
rospy.sleep(4)
if rospy.is_shutdown():
rospy.loginfo("---- SHUTTING DOWN ----")
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
So when I run the code I get this error:
[INFO] [1631362769.809577, 0.000000]: hello world 0.0
Traceback (most recent call last):
File "/home/hdani-ros/catkin_ws/src/ur_keyboard_teleop/scripts/ur_keyboard_teleop.py", line 28, in <module>
talker()
File "/home/hdani-ros/catkin_ws/src/ur_keyboard_teleop/scripts/ur_keyboard_teleop.py", line 17, in talker
pub.publish(data)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 879, in publish
data = args_kwds_to_message(self.data_class, args, kwds)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/msg.py", line 122, in args_kwds_to_message
return data_class(*args)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/std_msgs/msg/_Float64MultiArray.py", line 74, in __init__
super(Float64MultiArray, self).__init__(*args, **kwds)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/message.py", line 344, in __init__
raise TypeError('Invalid number of arguments, args should be %s' % str(self.__slots__) + ' args are' + str(args))
TypeError: Invalid number of arguments, args should be ['layout', 'data'] args are([0.0, -2.0, 0.0, -1.57, 0.0, -0.5],)
Can someone clarify as to what I need to change in order to send just the joint states? Thanks in advance!