action server, service server, or publisher/subscriber. Which one should I use?

Hi, I have a question, before question I will explain my case.In my case, there are 2 sides which one of them is simulation and other one is calculator, I need to execute this scenario:

• Simulation starts, and sends sensor datas to calculator software
• Simulation waits until it take a move info like "go stragiht" or "turn left" etc.
• Calculator receives sensor datas and process it and send move info to simulation
• Calculator waits until it take a sensor data

So, this is a Reinforcement Learning project and I have to not miss any sensor data and movement info. I need sides(simulation and calculator software) to wait each other until they receive required data.

The question is Which one should I use, an Action Server, a Service or simple publisher and subscriber... ?

edit retag close merge delete

Sort by » oldest newest most voted

In this case, assuming I understand it correctly, I would use a service (wiki), which behaves something like a function call to another node--send some information and get some information in return before proceeding. An action server (actionlib wiki) could also be useful, but the main reason for using that would be if the calculations take a long time and you want the option to preempt them with a new run. Since it sounds like you want to finish every run before continuing, a service seems more appropriate. Furthermore, I would not choose publisher/subscriber because that method is more useful for data pipelines, where the node producing the data just publishes and doesn't need a reply to move on. Coordinating the two sides of your interaction would be more complicated using a publisher/subscriber framework.

If you can think of some reason or use-case caveat that may make a service prohibitive or promotes another approach, please, elaborate, and I'll be happy to discuss further.

more

Thanks for your answer, When I check tutorials here I see "spin()" func to make server looping, but I didnt understand how to loop client side. Would encapsulating with a while loop be appropriate? If I check server continuesly with a while loop?What do you think?

( 2021-01-12 09:03:32 -0600 )edit

Although it's not totally off-topic, posting this as a new question will give it wider visibility and provide more room for answers than a comment. I'll provide a brief answer here, though:

The spin() function keeps a node alive, like an idle state, to let it handle callbacks (see Callbacks and Spinning wiki). Another approach is to write your own while loop to step through the processing it needs to do repeatedly, giving you tighter flow control. There are, of course, still other approaches, too. Which is appropriate depends entirely on what exactly the node needs to do. If your use case is step-by-step, a client-side while loop may make the most sense, but for a solid answer, I recommend posting a new question and fleshing out your use case more--maybe include pseudocode for clarity.

On a side note, please, mark the answer above as correct (check mark ...(more)

( 2021-01-12 09:44:27 -0600 )edit