0
$\begingroup$

Rosanswers logo

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

Originally posted by Moon on ROS Answers with karma: 19 on 2016-04-26

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)
    

Originally posted by mgruhler with karma: 12390 on 2016-04-27

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Moon on 2016-04-27:
thanks . :)

Comment by Moon on 2016-04-27:
if I chose the second possibility ; do you know how to return step and data to my client node ??

Comment by mgruhler on 2016-04-27:
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....

Comment by Moon on 2016-04-27:
I mean how to write it in server but I found this way resp=stResponse()
resp.step = 7 resp.data = 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?

Comment by mgruhler on 2016-04-27:
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).

Comment by Moon on 2016-04-27:
I did , thanks a lot :) and this the question if want to help http://answers.ros.org/question/233049/array-as-response-in-python/

Comment by thejose on 2020-10-14:
I don't understand how the second option works. Could you explain it in a little more detail?

Comment by mgruhler on 2020-10-15:
Instead of a two-dimensional array, create a one-dimensional array by putting all rows "behind" each other. With the step field you define how long (either in bytes or you could also use number of elements) each row ist.

Does this answer your question? If not, I suggest you create a new question where you detail what exactly you don't understand...

Comment by thejose on 2020-10-15:
Thank you! That answered my question.

$\endgroup$

Your Answer

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