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

rostopic pub: "required argument is not a float" while sending Float32MultiArray.

asked 2019-05-24 10:18:55 -0500

Shanika gravatar image

updated 2019-05-24 10:21:11 -0500

gvdhoorn gravatar image

I would like to run one of my robot's wheel with a ros command in a terminal.
The function I use need two parameters so I wanted to use Float32MultiArray.

My arduino code ressembles to the following one:

float x,y;
void cmd(const std_msgs::Float32MultiArray& array){
  x =[0];  
  y =[1];,y); }
ros::Subscriber<std_msgs::float32multiarray> sub("cmd", &cmd);

In a terminal, I type the following command:

rostopic pub /cmd std_msgs/Float32MultiArray "layout:
 - label: "run"
 size: 2
 stride: 1
data:[100 100]" --once 

However, I have the following error:

[WARN] [..]: Inbound TCP/IP connection failed: <class 'struct.error'="">: 'required argument is not a float' when writing 'label: run
size: 2

Thank you in advance for your help.

Kindest regards,

edit retag flag offensive close merge delete


Could you precise what does your (x, y) variables stand for? If they are velocities, we could come up with a more natural/coherent way to publish them.

Jasmin gravatar image Jasmin  ( 2019-05-28 11:29:19 -0500 )edit

In fact, (x,y) variables stands for the position (degrees) the robot has to reach and its speed (rpm)

Shanika gravatar image Shanika  ( 2019-05-29 03:23:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-28 11:25:17 -0500

Jasmin gravatar image

The following command will publish your data and give you access to your two parameters.

rostopic pub /cmd std_msgs/Float32MultiArray '{data: [100, 100]}' --once

You're not using the layout in your code so we don't need to set it in this use case. The error you had is mainly because the published data is not formatted correctly.

edit flag offensive delete link more


Indeed, it was the cause of the error. Thank you Jasmin :)

Shanika gravatar image Shanika  ( 2019-05-29 02:57:10 -0500 )edit

Question Tools


Asked: 2019-05-24 10:18:55 -0500

Seen: 2,523 times

Last updated: May 28 '19