0
$\begingroup$

I have a simple ROS 2 node written in C++ that interacts with the user using the cin command. The node expects a basic string input like "yes" or "no" from the user:

string answer;
getline(cin, answer);

When I run the node using:

ros2 run package_name executable_name 

I can easily interact with the node via stdin and stdout.

However, when I run my node from a launch file (which also performs several other tasks), two issues arise:

  1. The stdin interaction doesn't work.
  2. Any stdout output doesn't appear in the launch file terminal.

After searching online, I discovered that there are challenges with handling stdin and stdout from launch file.

I’m considering switching to expecting a service call, and interacting through the rqt Service Caller GUI.

Does this approach seem like the right direction?

Answer: I chose to use a service because it's easy to work with through the rqt app

$\endgroup$

1 Answer 1

0
$\begingroup$

Yes, you can use a service for this, but unless there's a need for a return value, you could equally well simply use a topic, or a parameter. It boils down to preference.

$\endgroup$
1
  • $\begingroup$ I chose to use a service because it's easy to work with through the rqt app $\endgroup$
    – TripleS
    Commented Aug 19 at 11:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.