# How to perform decoupling between decision making and action execution in ROS2?

Hi I'm making a robot using:

• ros2 foxy
• OS Ubuntu Linux 20.04.2 LTS (Focal Fossa).
• Linux 5.8.0-59-generic

I built an Action based on the tutorial Building an Action Server and Client. Then expanded it using Serial and successfully managed to send messages to the serial port as seen in this thread.

The structure of my project is the following:

- workspace
- src
- arduino_comm #Represents the controller for the motor
- serial_server.py
- serial_client.py
- motor_interface
- other_interface


The Server and Client use the following action, which is based on the tutorial

##################################################
#Action that sends robot towards a specific spatial position.
##################################################
#Goal of achieving a specific position.
int32 botgoalposition
---
#Resulting position that we're aiming to attain.
int32[] botendposition
---
int32[] botcurrposition


So far it works well, now I want to create a main node that will take care of the decision making and indicate where the robot will move. So far I think I'll start with something simple like pressing the keyboard's arrowkeys to turn them into commands to the action server that represent a change in coordinates and make arduino_comm translate them to commands for the Arduino to move a pair of motors.

I thought about it and to me it makes the most sense to build a service to send the coordinates only once to the action and then wait for a response from the action server called arduino_comm. Nonetheless I read that services are/used to? be blocking so if I want the main controller to perform other actions (such as receiving input from a joystick or a keyboard, or process from a camera) the robot wouldn't be able to do those decisions, right?

On the other hand in the documentation here about publishers and subscribers it mentions that they're non-blocking and convenient for calling from a given topic to all the available nodes subscribed to that topic. But I'm not sure if sending a stream of data may impact my actions and cause them to reset.

So I'd like to know what are the suggested options for the architecture of a robot like that.

• When to use publisher vs service as main control logic of a robot that will send data to all the other nodes?
• If I create a logic node that will send commands to all the others, do I need to send the commands to action clients (meaning I need to codify an action client for every node or just one client that is the logic node and holds the topics for all servers) or can I send them directly to the action server?
• What are some tutorials I can use for ROS2 on how to send and receive commands from one node to another? And does it matter if they're publishers/action/services?