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

subscribing to a topic at every iteration of a loop

asked 2012-07-11 05:48:16 -0500

Erwan R. gravatar image

updated 2014-01-28 17:12:59 -0500

ngrennan gravatar image

Hello,

Maybe this question is more about algorithms than ROS, but I think it's interesting to ask for ROS external compatibility.

I'm currently trying to connect ROS with a third-party neural network simulator. This Neural Network simulator is organized similarly the ROS in the fact that is runs several scripts (equivalents to nodes) that are interacting through f_send and f_recv functions. Theses functions define links (eq. to topics) between scripts and use sockets on the technical point of view.

The current solution for interconnecting both software is to have a hybrid program included in the NN simulator that uses the ROS subscribers and publishers. This would allow data to come from ROS to the simulator with a ROS publisher and a f_recv box whereas the opposite direction would be done with a ROS subscriber and a f_send box. That's for the cute theory. This solution avoids big changes in the NN simulator structure and allows the ROS node to use the communication functions f_send and f_recv, to be quite independent from the technical point of view.

The problem comes because both f_send/recv functions are done in C and are not a class that I could inherit to had an attribute to store the publisher/subscriber pointer. There is a kind of class instantiation mechanism but all information is deduced from the input group number. So the only place I can insert ROS pub/subs is in the send/recv function, which is called at each iteration of the NN simulation. This means initialising the publisher and the subscriber at each call, and want to know if it a reasonable method or a bad patch ? Is there a clever feature or tool in ROS that would help ?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-07-16 03:53:18 -0500

Erwan R. gravatar image

Thanks both of you for answering.

I had a discussion with one of the NN simulator developers and he told me that there is a mechanism to transmit data between their functions without modifying the whole structure of the simulator. That's what I'm gonna use. But another question about message type will probably come ;) ...

edit flag offensive delete link more
2

answered 2012-07-11 06:12:19 -0500

dornhege gravatar image

It is bad, because the publisher/subscribers will need some time to "find" there connection. If you create new ones all the time, and immediately publish, you'll probably get zero messages through.

If that is you only insertion point, you could create them static or call some init() function once, that sets up the publishers.

On a side note: you might want to set that up as Nodelets as it seems to be that you'll be passing a lot of stuff around.

edit flag offensive delete link more
1

answered 2012-07-11 14:33:29 -0500

joq gravatar image

Even in C you could declare static variables allowing the publish or subscribe to happen only on the first call.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-07-11 05:48:16 -0500

Seen: 921 times

Last updated: Jul 16 '12