Advice on composition (threads vs. components or smth else?)

asked 2022-04-29 04:20:46 -0500

märve gravatar image

Hello,

I want to create a ROS package that wraps a python library used to communicate with a robot.

It should be possible to define different sensors and motors in a config file for which the package then creates the different nodes/components at runtime. However, from what I've understood, you can't .spin() multiple nodes from the same process in python since .spin() is blocking. I've seen that using threads and then spinning the thread executor would work, but I'm unsure if that's the way to go.

The other option seems to be creating a component for each sensor/motor in C++ and then loading them into a ComposableNodeContainer from a launch file that reads the config file to know which components need to be loaded. In this case, however, I would probably need to use something like pybind11 or boos.python to call the python library for communicating with the robot.

What would be the better option? I would prefer to use python since it would simplify the python library usage, and I've never written any C++ before.

Are there any other better options, or have I misunderstood a concept, and my problem can be solved at a different level?

For your info, I'm using python3.8.10 and ROS2 Foxy on Ubuntu 20.04.4

Sorry for the inaccurate terms; I'm new to ROS, so please feel free to correct me. Thanks in advance for taking the time to help me out!

edit retag flag offensive close merge delete