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

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
2

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

Comments

thanks . :)

Moon gravatar image Moon  ( 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 image Moon  ( 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 image mgruhler  ( 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 = 7resp.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?

Moon gravatar image Moon  ( 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 image mgruhler  ( 2016-04-27 07:46:59 -0600 )edit

I did , thanks a lot :) and this the question if want to help http://answers.ros.org/question/23304...

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

I don't understand how the second option works. Could you explain it in a little more detail?

thejose gravatar image thejose  ( 2020-10-14 20:39:06 -0600 )edit

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...

mgruhler gravatar image mgruhler  ( 2020-10-15 01:14:18 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,991 times

Last updated: Apr 27 '16