0
$\begingroup$

Rosanswers logo

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 :)


Originally posted by Boris_il_forte on ROS Answers with karma: 96 on 2013-11-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Dirk Thomas with karma: 16276 on 2013-11-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Boris_il_forte on 2013-11-23:
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?

Comment by Dirk Thomas on 2013-11-23:
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.

Comment by Boris_il_forte on 2013-11-23:
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!

$\endgroup$

Your Answer

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