1

I have a list and inside I have lists of dictionaries and I want to publish the information inside to another node.

I have something like that:

[[ {data0 : String, start0 : Float, end0 : Float}, {data1 : String, start1 : Float, end1 : Float}, {data2 : String, start2 : Float, end2 : Float} ], {data0 : String, start0 : Float, end0 : Float}, {data1 : String, start1 : Float, end1 : Float} ]

So I want to publish a 2D list of String and two 2D list of Float but I don't know how to do it with the custom_message.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tom
  • 15
  • 3
  • If you're really lazy, in python, you can just use [json](https://docs.python.org/3.5/library/json.html), and [get it back out](https://stackoverflow.com/a/35920523/6069586), sending via String msg. If you want to benefit from ROS's strong typechecking & compile-time bug catching, then you need a custom msg. – JWCS Jun 09 '20 at 00:42

1 Answers1

1

You would have 2 msgs: one msg defines the struct/dict {data : String, start: float, end: float} and another would declare some arrangement of them. (See also.)

# MyMsg.msg
float32 data
string start
string end

Options:

# MyMsgArray.msg
Header header
MyMsg[] data
# MyMsgMatrix.msg
Header header
MyMsg[][] data
# MyMsgPairArray.msg
Header header
MyMsg[2][] data

Or these two:

# MyMsgPair.msg
float32[2] data
string[2] start
string[2] end
# MyMsgPairArray.msg
Header header
MyMsgPair[] data

Remember to add the relevant stuff to the package.xml and CMakeLists.txt: http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv

JWCS
  • 1,120
  • 1
  • 7
  • 17