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

How do I send numpy array with ROS services?

asked 2016-10-24 05:26:33 -0600

GPaolo gravatar image

Hi, I am writing a service in ROS and need to send 3D numpy arrays through this service. I know that for the messages there is numpy_msg, but haven't found anything similar for the services. Thanks for the help! :D

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-10-24 17:03:28 -0600

huanxiner gravatar image

Not sure if there is an existing serviec/message type that you can use out of box, but reshape the 3D array into a 1D array then simply use float64[] would probably work.

Creating ROS srv/msg

edit flag offensive delete link more

answered 2016-10-25 06:15:48 -0600

Airuno2L gravatar image

Two tips:

  1. You can use any existing messages to create a service. More info on that can be found here.
  2. When you use numpy_msg, you're messages are actually going to be passed along as float32[] messages. The numpy_msg package just provides a nice way to serialize and deserialize float32[] messages directly into numpy arrays. More info on that here.

So you could have a service that, for example, takes a numpy array and int in the request, and responds with a new numpy array, that would look something like this:

int32 an_integer
float32[] input_array
float32[] output_array
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-10-24 05:26:33 -0600

Seen: 2,318 times

Last updated: Oct 25 '16