Page 1 of 1
Plugin Error:
Posted: Sun Jul 18, 2021 9:42 am
by mlaudu
I am having problem developing a plugin for OpenSim 4.2 to enable me open a model that has a newly defined muscle controller. I see that OpenSim 4.2 GUI was built using Visual Studio 16 2019-MSVC on Windows-x64. I created a folder with my MuscleController.cpp and MuscleController.h files containing my MuscleController definition. I added and edited the files osimPluginDLL.h, RegisterTypes_osimPlugin.cpp, RegisterTypes_osimPlugin.h and CMakeLists.txt. I created the project using cmake-3.21.0 using Visual Studio 2019 in x64. I then compiled the libraries in Visual Studio 2019 and added the .dll and .lib files to C:\OpenSim 4.2\plugins. I opened OpenSim 4.2 and it says "Successfully loaded library C:\OpenSim 4.2\plugins\MuscleController.dll.". However, when I tried to load the model that has MuscleController defined in it, I get the message "Object::newInstanceOfType(): object type '{MuscleController}' is not a registered Object! It will be ignored." and loading the model is aborted.
I am at a complete loss as to what else to do that is making the model not to load. The entry in the model xml file looks as follows:
Code: Select all
<!--Controllers that provide the control inputs for Actuators.-->
<ControllerSet name="controllerset">
<objects>
<MuscleController name="musclesController">
<!--The list of model actuators that this controller will control.The keyword ALL indicates the controller will control all the actuators in the model-->
<actuator_list>RMEDGAS RLATGAS RSOLEUS RTIBANT RVASMED RVASINT RVASLAT RSEMIMEM</actuator_list>
</MuscleController>
</objects>
<groups />
</ControllerSet>
Any help on resolving this will be greatly appreciated so I will not be stuck in OpenSIm 4.0.
Re: Plugin Error:
Posted: Mon Jul 19, 2021 9:49 am
by aymanh
Hello Professor Audu,
We definitely would like to help you out and get you using the latest OpenSim version.
To me the message suggests that your dll is perfectly fine, except that the name of the class in the XML file is not found in the registry of classes.
You can check that by loading the plugin in the GUI and checking the list of available classes (Help->XML Browser then check if the name "MuscleController" exists in the dropdown of available classes). If the classes you added are not there, then the class registration didn't happen (the likely scenario) if not then the problem is somewhere else which we can try to dig further into.
The way registration works in plugins is (AnalysisPlugin is a reasonable place to check):
1. Create a static instance of an object "instantiator" in a cpp file of an arbitrary type (call it MycontrollerInstantiator()).
2. Have the constructor of this object type call
Code: Select all
Object::RegisterType( MuscleController())
The result is that on loading the dll, the types that you want exposed to the outside world are registered through the call in 2, and these types can be instantiated either from XML files or programmatically.
Please let us know what you find out or if you need further help.
All the best,
-Ayman
Re: Plugin Error:
Posted: Tue Jul 20, 2021 1:51 pm
by mlaudu
Thank you very much Ayman. I checked in Help->XML Browser and my MuscleController was not listed. But just to make sure, I also copied the two example folders 'AnalysisPluginExample' and 'BodyDragExample' to my desktop without changing a thing except adding a 'build' folder to each. I then created the project files using CMake and build each using Visual Studio 2017 in Release mode. I then copied each of the two dll files created (osimPlugin.dll and BodyDragForce.dll) to 'C:\OpenSim 4.2\plugins'. I then opened OpenSim 4.2 and the two dlls showed under Tools->User Plugins - but neither of them was listed in Help->XML Browser. If this does not work for these two established examples then I may be doing something fundamentally wrong. Do you have any idea what else to test? Thanks. Musa.
Re: Plugin Error:
Posted: Wed Jul 21, 2021 3:05 pm
by aymanh
Hello,
To test I built the plugin from Code\CPP\Plugins\AnalysisPluginExample using VS 2019 Community, and the plugin was built successfully and when loaded in the GUI the Analysis showed up as seen below
![CapturePlugin.JPG](./download/file.php?id=5178&sid=894c477fd10fbddd8c1cf575b045dbc3)
- CapturePlugin.JPG (73.42 KiB) Viewed 799 times
Let's try to sort this out before moving to the new code/plugin.
Best regards,
-Ayman
Re: Plugin Error:
Posted: Sun Jul 25, 2021 3:39 pm
by mlaudu
Thank you very much for that guidance. It works; after I have cleaned out my previous API installation and made a fresh installation with a more recent version. Apparently I must have been mixing versions of the API and GUI installations. Thank you.
Re: Plugin Error:
Posted: Thu Aug 12, 2021 10:36 am
by tnt845
I seem to be having a very similar issue as Audu, but I believe the source of my issue is slightly different. I am trying to build a plugin based on the fatigue muscle example Code/CPP/MuscleExample. I am using the FatigableMuscle.cpp and FatigableMuscle.h in that folder along with the osimPluginDLL.h, RegisterTypes_osimPlugin.cpp, RegisterTypes_osimPlugin.h, and CMakeLists.txt files copied from the BodyDragExample.
I was able to build the FatiguableMuscle successfully using Visual Studio Community 2017 (I am using OpenSim 4.1) and got the message: "Successfully loaded library C:\OpenSim 4.1\plugins\FatigableMuscle.dll" when I loaded it into OpenSim but when I load a model with the fatigable muscle I get the same error message Professor Audu got about it not being a registered object.
When I repeat this process for the Body Drag example I do see BodyDrag Class available in the Help->XML Browser dropdown but the fatigable muscle class is not there.
Reading through Ayman's post I am guessing my issue is with
1. Create a static instance of an object "instantiator" in a cpp file
When I was first tried to build the plugin I got an error in Visual Studio: "C:\OpenSim 4.1\Resources\Code\CPP\Plugins\MuscleFatigue\RegisterTypes_osimPlugin.cpp(33): error C2371: 'instantiator': redefinition; different basic types"
That line of code in RegisterTypes_osimPlugin.cpp is :
Code: Select all
static dllObjectInstantiator instantiator;
. I originally just commented this line out and then it built fine and loaded successfully in OpenSim (but couldn't use it). Now I am assuming that is NOT an acceptable workaround.
Do you have any suggestions for what may be going wrong?
Thanks!
Ty