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

panserzap's profile - activity

2021-09-02 12:09:20 -0500 received badge  Famous Question (source)
2021-07-26 06:30:43 -0500 received badge  Notable Question (source)
2021-06-23 15:09:48 -0500 received badge  Popular Question (source)
2021-06-23 03:35:49 -0500 commented answer Unable to Publish Float64MultiArray in python

Thank you for the guidance. I now understand what I am doing wrong. I have already read the documentation though, but I

2021-06-23 03:27:28 -0500 marked best answer Unable to Publish Float64MultiArray in python

Hello everyone,

I am trying to publish a Float64MultiArray using python, this is what I have so far.

Code:

import rospy
from std_msgs.msg import Float64MultiArray    

TOPIC_NAME = 'waypoints'
NODE_NAME = 'waypoints_publisher'

def post_coordinates():
    pub = rospy.Publisher('waypoints', Float64MultiArray, queue_size=10) # TOPIC
    rospy.init_node('waypoints_publisher', anonymous=True)
    rate = rospy.Rate(1) # 10hz

while not rospy.is_shutdown():
    my_msg = Float64MultiArray()
    d=[[1.2354567, 99.7890, 67.654236], [67.875, 90.6543, 76.5689], [65.3452, 45.873, 67.8956]]
    my_msg.data = d
    pub.publish(my_msg)

    rospy.loginfo('SEND DATA: \n%s', my_msg)
    rate.sleep()

 if __name__ == '__main__':
    try:
       post_coordinates()
    except rospy.ROSInterruptException:
       pass

I get the following error when trying to run the code:

 Traceback (most recent call last):
 File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/_Float64MultiArray.py", line 112, in serialize
    buff.write(struct.Struct(pattern).pack(*self.data))
struct.error: required argument is not a float



During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 882, in publish
    self.impl.publish(data)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 1066, in publish
    serialize_message(b, self.seq, message)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 152, in serialize_message
    msg.serialize(b)
  File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/_Float64MultiArray.py", line 113, in serialize
    except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), 
str(locals().get('_x', self)))))
  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 393, in _check_types
    check_type(n, t, getattr(self, n))
  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 314, in check_type
    check_type(field_name + '[]', base_type, v)
  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 273, in check_type
    raise SerializationError('field %s must be float type' % field_name)
genpy.message.SerializationError: field data[] must be float type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/catkin_ws/devel/lib/robotics_demo/waypoint_publisher.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/home/ubuntu/catkin_ws/src/robotics_demo/scripts/waypoint_publisher.py", line 25, in <module>
   post_coordinates()
  File "/home/ubuntu/catkin_ws/src/robotics_demo/scripts/waypoint_publisher.py", line 18, in post_coordinates
   pub.publish(my_msg)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 886, in publish
    raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field data[] must be float type

I already tried adding this:

d=[[float(d[i][j]) for j in range(len(d))] for i in range(len(d[0]))]

exactly before :

 my_msg.data = d

the error remains the same. What am I doing wrong?

This is my endpoint.py

#!/usr/bin/env python

import rospy

from ros_tcp_endpoint import TcpServer, RosSubscriber
from std_msgs.msg import Float64MultiArray


def main():
    ros_node_name = rospy.get_param("/TCP_NODE_NAME", 'TCPServer')
    buffer_size = rospy.get_param("/TCP_BUFFER_SIZE", 1024)
    connections = rospy.get_param("/TCP_CONNECTIONS", 10)
    tcp_server = TcpServer(ros_node_name, buffer_size, connections)
    rospy.init_node(ros_node_name, anonymous=True)

    tcp_server ...
(more)
2021-06-23 03:27:28 -0500 received badge  Scholar (source)
2021-06-23 02:05:13 -0500 commented answer Unable to Publish Float64MultiArray in python

Thank you for the guidance. I now understand what I am doing wrong. I have already read the documentation though, but I

2021-06-23 01:30:45 -0500 edited question Unable to Publish Float64MultiArray in python

Unable to Publish Float64MultiArray in python Hello everyone, I am trying to publish a Float64MultiArray using python,

2021-06-23 01:30:45 -0500 received badge  Editor (source)
2021-06-23 01:30:38 -0500 edited question Unable to Publish Float64MultiArray in python

Unable to Publish Float64MultiArray in python Hello everyone, I am trying to publish a Float64MultiArray using python,

2021-06-23 01:26:26 -0500 asked a question Unable to Publish Float64MultiArray in python

Unable to Publish Float64MultiArray in python Hello everyone, I am trying to publish a Float64MultiArray using python,

2021-06-22 08:04:56 -0500 commented question Unable to Publish Float32MultiArray in .cpp

Were you able to solve this? If yes, do you remember how? I am trying to publish the same thing using python.

2021-05-10 00:45:44 -0500 received badge  Enthusiast
2021-05-05 13:55:10 -0500 commented answer Transfer trajectory from ROS to Unity

Yes, that is what I am currently looking at. Unity package ROS-TCP-Connector and ROS package ROS-TCP-Endpoint will prob

2021-05-05 13:54:27 -0500 received badge  Supporter (source)
2021-05-05 10:54:52 -0500 answered a question Transfer trajectory from ROS to Unity

This is kind of an old post and i am not answering any questions , but where you able to find the solution?