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

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

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

Shanika gravatar image

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

gvdhoorn gravatar image

Hello,
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;
----------
/*callback*/
void cmd(const std_msgs::Float32MultiArray& array){
  x = a.data[0];  
  y = a.data[1];  
  motor1.run(x,y); }
----------
/*suscriber*/
ros::Subscriber<std_msgs::float32multiarray> sub("cmd", &cmd);


In a terminal, I type the following command:

rostopic pub /cmd std_msgs/Float32MultiArray "layout:
 dim:
 - label: "run"
 size: 2
 stride: 1
 data_offset:0
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

Comments

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 -0600 )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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Comments

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

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

Question Tools

Stats

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

Seen: 2,591 times

Last updated: May 28 '19