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

What is the best way to send a vector of coples string, double?

asked 2013-11-23 01:53:54 -0500

Boris_il_forte gravatar image

updated 2014-01-28 17:06:38 -0500

ngrennan gravatar image

Hi,

I've a piece of software, that I would like to be ros-indipendent (is a library for fuzzy reasoning)

Now, the results of reasoning is a set of variables with the associated values to them. Now, my implementation of the reasoner gives in output a map<string, double="">. But i can use a vector (or an array) of structs.

now, i want to setup my reasoning service, so I've defined two messages, the Input message and the output message. And obviously, in my service I've got two variable as variable lenght arrays:

Reasoning.srv

#definition of the basic Reasoning service
#The input variable for the reasoning
InputVariable[] inputs
---
#The defuzzyfied output
DefuzzyfiedOutput[] results

DefuzzyfiedOutput.msg

#Definition of the defuzzyfied output type
#the name of the input variable
string name
#the defuzzyfied value
float64 value

now, when sending the results, I've to iterate over the map and set each pair of the DefuzzyfiedOutput struct, and then add it to the output vector.

there is a way to avoid that? I would like to set the map/vector/whatever when sending the message, I don't think is very smart to iterate over a map, and then let ros iterate again over the same thing to send the message.

I don't knowif it's clear what I would like to do... but I hope so...

Obviously I would like to avoid using the message as output element of my reasoning service, because I would like it to be independent from ros...

thank you very much :)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-11-23 05:53:02 -0500

Dirk Thomas gravatar image

The recommended practice is to write your library in a ROS independent manner (e.g. using a std::map in the API). Then you wrap that library in a thin layer which will map your API into ROS messages (doing the shuffling of the data from the map to the message and back).

ROS message do not support dictionaries / maps as a built in type which would make your mapping easier.

edit flag offensive delete link more

Comments

so there's no way to avoid the loop for doing he mapping? even with vectors? it's a shame because, although it will not affect asymptotic complexity of the operation, it makes it twice as slower (because however ros must serialize the object to be sent...) Where can I propose such feature?

Boris_il_forte gravatar image Boris_il_forte  ( 2013-11-23 06:19:12 -0500 )edit

You could use two vectors (which ROS messages support as a built in type) which you iterate at the same time to simulate a map. But you still have to copy the data from your API to the ROS message if you don't want to use ROS messages in your library API.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-11-23 06:21:20 -0500 )edit

too bad, so it's basically the same to use vector, maps or arrays as I thought. It's a shame, though. thank you very much!

Boris_il_forte gravatar image Boris_il_forte  ( 2013-11-23 06:33:02 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-23 01:53:54 -0500

Seen: 867 times

Last updated: Nov 23 '13