Ask Your Question
0

Compose two components into a single process in python

asked 2020-05-05 05:03:35 -0500

CraigH92 gravatar image

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.

edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-05 06:27:22 -0500 )edit

This was a red herring, sorry. The above code works. See my answer below.

CraigH92 gravatar image CraigH92  ( 2020-05-05 08:25:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-05 08:25:28 -0500

CraigH92 gravatar image

This was a red herring, sorry. The above code works.

The problem was my NodeletB was creating a client using an IDL type that was an action, not a service, and this caused it to crash without any error messages.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-05-05 05:03:35 -0500

Seen: 76 times

Last updated: May 05 '20