0
$\begingroup$

Rosanswers logo

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!


Originally posted by pwong on ROS Answers with karma: 447 on 2014-08-05

Post score: 1

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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]"

Originally posted by BennyRe with karma: 2949 on 2014-08-06

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by pwong on 2014-08-07:
Thank you!

Comment by atomoclast on 2016-09-13:
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?

Comment by Cerin on 2017-03-26:
@atomoclast: Your message is malformed. You need to put dim inside the layout key, like this answer shows. e.g. {layout: {dim: [...]}, ...}, not {dim: [...]}.

$\endgroup$
0
$\begingroup$

Rosanswers logo

@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


Originally posted by duck-development with karma: 1999 on 2017-01-18

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by jayess on 2017-03-26:
YAML strings can be mulit-line or single-line. http://wiki.ros.org/YAML%20Overview

$\endgroup$
0
$\begingroup$

Rosanswers logo

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
"

Originally posted by matEhickey with karma: 15 on 2017-09-05

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.