Plugin order

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

Plugin order

Post by avena_robotics »

Hello,

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

Best regards,
Avena Robotics

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

Re: Plugin order

Post by fferri »

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.

What's exactly your use-case for loading plugins in a specific order?

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

Re: Plugin order

Post by avena_robotics »

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: 1193
Joined: 09 Sep 2013, 19:28

Re: Plugin order

Post by fferri »

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();
then load your plugin last (e.g. call it simExtZZsomething, or use a custom name and load it via sim.loadModule from an add-on script)

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

Re: Plugin order

Post by avena_robotics »

Thanks for answer,

we renamed the simExtROS2 plugin to load it in the beginning and it solved the problem.

Best regards,
Avena

Post Reply