Ask Your Question

2D array as service response

asked 2016-04-26 14:54:59 -0600

Moon gravatar image

updated 2016-04-27 00:51:20 -0600

mgruhler gravatar image

I want to use a service that has a 2D array response

this is my .srv file

uint32 a

uint32[][] tree

catkin_make error:

genmsg.base.InvalidMsgSpec: invalid field: Currently only support 1-dimensional array types: uint32[][]
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-27 00:57:04 -0600

mgruhler gravatar image

Well, the error says it all: two dimensional arrays are currently not supported.

I see two possibilities:

  1. use one of the MultiArray message types in std_msgs.
  2. create your service similar to what e.g. sensor_msgs/Image is doing, by having a 1D array for the data and an additional parameter for the length of a row, i.e.

    int32 a
    uint32 step # Full row length in bytes
    uint32[] data # actual matrix data, size is (step * rows)
edit flag offensive delete link more


thanks . :)

Moon gravatar imageMoon ( 2016-04-27 06:04:15 -0600 )edit

if I chose the second possibility ; do you know how to return step and data to my client node ??

Moon gravatar imageMoon ( 2016-04-27 06:11:42 -0600 )edit

Sorry, I don't understand your question.. This is a service, so the client sends the request, and receives the response, which contains step and data in this case....

mgruhler gravatar imagemgruhler ( 2016-04-27 06:52:04 -0600 )edit

I mean how to write it in server but I found this way resp=stResponse()
resp.step = = cell #cell is an array in my server code return resp

but I have another problem now: when I tried to print the received array in client it is printed as (1,2,3,4,..) not as the data that was assigned?

Moon gravatar imageMoon ( 2016-04-27 07:19:30 -0600 )edit

please post a new question and provide the respective code (make sure to format it properly using the preformatted text button, the one with 101 on it).

mgruhler gravatar imagemgruhler ( 2016-04-27 07:46:59 -0600 )edit

I did , thanks a lot :) and this the question if want to help

Moon gravatar imageMoon ( 2016-04-27 08:10:53 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-04-26 14:54:59 -0600

Seen: 755 times

Last updated: Apr 27 '16