## Plugin order

Typically: "How do I... ", "How can I... " questions
avena_robotics
Posts: 16
Joined: 11 Aug 2020, 12:47

### Plugin order

Hello,

is it possible to set loading order of plugins? And if it is, how?

Best regards,
Avena Robotics

fferri
Posts: 722
Joined: 09 Sep 2013, 19:28

### Re: Plugin order

If you are talking about the automatically loaded plugins, I think you need to modify the client application and provide a custom initialization callback that would load plugins according to your logic.

Another possibility would be to name your plugins with a name different from the standard pattern, so that they are not automatically loaded. Then you can load those with sim.loadModule perhaps inside an add-on script, according to your logic.

avena_robotics
Posts: 16
Joined: 11 Aug 2020, 12:47

### Re: Plugin order

Thanks for answer. It helps alot ;)

Our use case:
We use ROS2 in our plugins and ROS2 has to be initialized before creation of any nodes. There is simExtROS2 plugin which initializes ROS2 (function rclcpp::init()).

Let's say that our plugin is loaded before simExtROS2 plugin and it initializes ROS2. Later when simExtROS2 plugin loads it fails because ROS2 has been already initialized. We could remove simExtROS2 plugin and check in every plugin whether ROS2 initialized, but we want to have option to use ROS2 interface in Lua scripts.

Temporary solution is to rename simExtROS2 plugin so it is loaded in the beginning and we did it like this for now.

fferri
Posts: 722
Joined: 09 Sep 2013, 19:28

### Re: Plugin order

avena_robotics wrote:
26 Jan 2021, 10:59
Our use case:
We use ROS2 in our plugins and ROS2 has to be initialized before creation of any nodes. There is simExtROS2 plugin which initializes ROS2 (function rclcpp::init()).

Let's say that our plugin is loaded before simExtROS2 plugin and it initializes ROS2. Later when simExtROS2 plugin loads it fails because ROS2 has been already initialized. We could remove simExtROS2 plugin and check in every plugin whether ROS2 initialized, but we want to have option to use ROS2 interface in Lua scripts.

Temporary solution is to rename simExtROS2 plugin so it is loaded in the beginning and we did it like this for now.
Can't you do something like the following:

in a global variable, remember if you need to shutdown rclcpp:

Code: Select all

bool initialized_rclcpp = true;

in plugin initialization:

Code: Select all

if(!rclcpp::is_initialized())
rclcpp::init();
else
initialized_rclcpp = false;

in plugin cleanup:

Code: Select all

if(initialized_rclcpp)
rclcpp::shutdown();