Page 1 of 1
Plugin order
Posted: 25 Jan 2021, 15:04
by avena_robotics
Hello,
is it possible to set loading order of plugins? And if it is, how?
Best regards,
Avena Robotics
Re: Plugin order
Posted: 25 Jan 2021, 18:27
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?
Re: Plugin order
Posted: 26 Jan 2021, 10:59
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.
Re: Plugin order
Posted: 27 Jan 2021, 11:06
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:
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)
Re: Plugin order
Posted: 27 Jan 2021, 15:25
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