ros2 publisher without node and spinning
Hi !
I have a ROS2 system up and running and from an external (C++) process I'd like to occasionally, randomly, asynchronously publish some data to an existing topic, without spinning a node at fixed frequency. (I'd like to publish the data when an event is triggered, but then I'd like to publish that immediately instead of waiting for some spin invocation.)
Using spin_once one can make a workaround to make this work, however according to the docs there is no spin_once available in the C++ API.
Found no way to do this in ROS2 C++. Is it doable ?
G
If I dive into rclcpp and look in executor.cpp I am able to find
So it seems that you should be able to do something like this
Haven't tried this, but you can have a look if this is the way to do what you want.
Depending on what exactly you are trying to do you could probably also look into using the other abstraction layers, i.e. sending directly through DDS, creating a custom waitable that achieves what you want or writing a custom executor/workaround at rclcpp level. This however requires you to look deeper into rclcpp, rcl and rmw (I don't expect your use-case requires you to go this deep though).
You have already asked a similar question here: https://answers.ros.org/question/3380... Please follow up on the previous question rather than just posting new ones and not replying on the previous ones.
Though the two question is similar they are not the same (!) and might have different solutions, that is why I posted this second one. (Low latency does not neceserly means no spinning.) In the meantime I found a solution to the other question and also posted as an answer.
You do need a node to publish messages. But you don't need to spin at all if the only thing your node does is publishing - spinning is needed for incoming messages so subscribing, offering/using services etc.