Ask Your Question

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

asked 2021-01-12 05:38:11 -0600

enessayaci gravatar image

updated 2021-01-12 05:39:40 -0600

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... ?

Thanks a lot for your response in advance .

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-01-12 07:35:58 -0600

tryan gravatar image

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.

edit flag offensive delete link 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?

enessayaci gravatar image enessayaci  ( 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)

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-01-12 05:38:11 -0600

Seen: 29 times

Last updated: Jan 12