0
$\begingroup$

I'm just trying to get the nodes to initialize that's all.

Even running almost empty code with just the executor gives me back:

AttributeError: 'NoneType' object has no attribute 'add_node' [ros2run]: Process exited with failure 1

import rclpy
from rclpy.node import Node
from rclpy.executors import MultiThreadedExecutor

from agv_motors import Motors
from agv_power import Power

from agv_interfaces.srv import PowerSwitch



## start the code ##
class Core(Node):
    def __init__(self):
        super().__init__('core')
        self.executor = MultiThreadedExecutor()

        self.executor.add_node(self)
        
        self.get_logger().info("Core is running")

        self.power = Power()
        self.executor.add_node(self.power)
        self.get_logger().info("Power is running")
        ## Boot up the engines ##

        self.motors = Motors()
        self.executor.add_node(self.motors)
        self.get_logger().info("Motors are running")

        ## accelerate to 1 m/s ##

        ## turn left ##

        ## accelerate to 5 m/s ##

        ## turn right ##

        ## stop ##

        ## soft shutdown ##


def main(args=None):
    rclpy.init(args=args)

    core = Core()

    try:
        print("Spinning up!")
        core.executor.spin()
    finally:
        print("Spinning down!")
        core.executor.shutdown()
        rclpy.shutdown()

if __name__ == "__main__":
    main()

```
$\endgroup$

1 Answer 1

0
$\begingroup$

I got the problem narowed down.

It's having a problem with the initialization inside the class.

Presumably it doesn't like the fact that there could be multiple multithreaded executors.

The solution is to inicialize the executor outside the class, and then pass it down to the class constructor.

Be aware that you need to also spin it up outside the class as a different variable; You cannot access the executor from outside of the class.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.