Compose two components into a single process in python
The tutorial describes how to do this in C++. How do I do the same in python?
My attempt so far:
class NodeletA(Node):
def __init__(self):
super().__init__('nodelet_a')
class NodeletB(Node):
def __init__(self):
super().__init__('nodelet_b')
def main():
rclpy.init(args=None)
executor = MultiThreadedExecutor()
a = NodeletA()
executor.add_node(a)
b = NodeletB()
executor.add_node(b)
executor.spin()
a.destroy_node()
b.destroy_node()
rclpy.shutdown()
This creates the components, but the spin
method does not block like the rclpy.spin()
does. The program instantly destroys the nodes and shuts down. how do I make executor.spin()
blocking. The executor needs to be multithreaded because one of my nodes hosts an action server, and I need the execute_callback
of the action to be non-blocking.
Thanks.
Not sure whether it just hasn't been updated, but at least according to ROS 2: Features Status node composition is a C++-only feature.
This was a red herring, sorry. The above code works. See my answer below.