ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Instead of manually terminating the node, I found out that actually the state machine did not terminate automatically (as it should) because there was a blocked spin.

The solution I found was to add the "Grip" state in a MultiThreadedExecutor, using a ReentrantCallback, and then spin_once:

In the state:

self.executor = rclpy.executors.MultiThreadedExecutor()
self.executor.add_node(self.grasp_node)
self.executor.spin_once(self.grasp_node)

the subscriber:

self.__node.create_subscription(Bool, 'vacuum_pump_center', self.__control_center_vacuum_pump, 1, callback_group=ReentrantCallbackGroup())

Then I destroyed the node and rclpy.shutdown()

This achieved the desired result: the state machine spins once, it goes through the callback, and then terminates.