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

rostopic pub multiarray

asked 2014-08-05 18:21:22 -0600

pwong gravatar image

Quick question, how do I publish a multiarray? I use rostopic a lot, and its tremendously helpful. One thing I was never able to figure out, was how publish a multiarray(I also wasn't able to find a post on it).

This is the format it provides:

rostopic pub /topic_name std_msgs/Float32MultiArray "layout:
  dim:
  - label: ''
    size: 0
    stride: 0
  data_offset: 0
data:
- 0"

That can publish a single element multiarray, but I couldn't figure out how to add another element on that array.

I've tried...

rostopic pub /topic_name std_msgs/Float32MultiArray "layout:
  dim:
  - label: ''
    size: 0
    stride: 0
  data_offset: 0
data:
- [0.0, 1.0]"

and a bunch of other variants, but nothing works. If someone can help with the syntax, that would be appreciated!

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
5

answered 2014-08-06 00:07:15 -0600

BennyRe gravatar image

See this answer:

$ rostopic pub /topic_name std_msgs/Float32MultiArray "layout:
dim:
  - label: ''
    size: 0
    stride: 0
  data_offset: 0
data: [0.0, 1.0, 2.0]"
edit flag offensive delete link more

Comments

Thank you!

pwong gravatar image pwong  ( 2014-08-07 11:19:14 -0600 )edit
1

Hello, I tried this a Int16MultiArray message and got this error out:

ERROR: No field name [dim]

Args are: [layout.dim layout.data_offset data]

Any idea what it could be?

atomoclast gravatar image atomoclast  ( 2016-09-13 19:14:05 -0600 )edit

@atomoclast: Your message is malformed. You need to put dim inside the layout key, like this answer shows. e.g. {layout: {dim: [...]}, ...}, not {dim: [...]}.

Cerin gravatar image Cerin  ( 2017-03-26 11:03:13 -0600 )edit
1

answered 2017-01-18 14:03:49 -0600

duck-development gravatar image

updated 2017-01-18 14:05:20 -0600

@atomoclast

i have an Messege Generated with works

 rostopic pub /speed std_msgs/Int16MultiArray "layout:
   dim: []
   data_offset: 0
 data: [10, 100]"

the Importen part ist the make an multi line CMD, and not convert the input to an single line

edit flag offensive delete link more

Comments

YAML strings can be mulit-line or single-line. http://wiki.ros.org/YAML%20Overview

jayess gravatar image jayess  ( 2017-03-26 12:12:08 -0600 )edit
1

answered 2017-09-05 05:43:24 -0600

matEhickey gravatar image

For me none of this worked, I always have an error like
"field data[] must be an integer type" (or a float if it's a float array of course.).

How I achieved to send multiple value was to set one value a a line preceding by a hyphen.

exemple:

rostopic pub /modbus_wrapper/input std_msgs/Int32MultiArray "layout:
  dim:
  - label: ''
    size: 2
    stride: 0
  data_offset: 0
data:
- 0 
- 1
- 3
"
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2014-08-05 18:21:22 -0600

Seen: 14,771 times

Last updated: Sep 05 '17