Auterion / px4-ros2-interface-lib

Library to interface with PX4 from a companion computer using ROS 2
BSD 3-Clause "New" or "Revised" License
68 stars 21 forks source link

fix registering issue when node is not immediately spinned #42

Closed damien-robotsix closed 4 months ago

damien-robotsix commented 5 months ago

Hello,

Here is a suggestion for the classes in NodeWithMode. They immediately trigger the registering but if you don't spin the node fast enough (like I do since I need extra configuration after the creation of the instance)

In all cases, it could be good to either: 1) let the hand to the user to trigger the registration just before spinning the node 2) have a more complex mechanism to check that the node is spinning before doing the registration.

The modification if put in this PR is for solution 1). However, this changes usage as the user must do the registration "manually" before spinning the node. So I am open to suggestions on this.

Also, I did a minor modification to access the Executor because you might need that if you want to access specific functions you implemented in the class inherited from ExecutorBase.

Damien

bkueng commented 5 months ago

I think in your case I would rather not use NodeWithMode, and instead manually create the ros node, which gives you more flexibility. NodeWithMode is meant for simplicity, and adding an extra registration call would not allow to use it like this anymore: rclcpp::spin(std::make_shared<px4_ros2::NodeWithMode<MyExecutor, MyMode>>("my_node"));