how to write algorithm in plugin

Typically: "How do I... ", "How can I... " questions
Post Reply
ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

how to write algorithm in plugin

Post by ariyayi »

My project is about path planning robot with PSO algorithm. I do it in threaded child scrip and it works, but it run slow. I want to run PSO algorithm in plugin and register new custom lua function PSO and call it in Threaded child script. How i can do it ?

in Threaded child scrip :

Code: Select all


   function a()
   end

   function b()
   end

   function PSO(worldsize, robot velocity , robot current position , robot 
   goal position , sensor  data)
   return value
   end

function sysCall_threadmain()  
Here I call PSO function several times until it reach the Goal
end
I write PSO algorithm in C++ but I don't know how I can use it in plugin ?

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

Re: how to write algorithm in plugin

Post by fferri »

You need to create a V-REP plugin with a Lua function callback that will execute your C++ algorithm.

Then load the plugin and call that function from the Lua child script in V-REP.

coppelia
Site Admin
Posts: 10337
Joined: 14 Dec 2012, 00:25

Re: how to write algorithm in plugin

Post by coppelia »

fferri is correct.

Have also a look at this plugin skeleton: it already implements an example C-code function callable from your script (simSkeleton.getData)

Cheers

ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

Re: how to write algorithm in plugin

Post by ariyayi »

thanks for quick reply,

Actually I am beginner with plugins and is my first time to create one. I download https://github.com/CoppeliaRobotics/v_repExtBubbleRob which include v_repExtBubbleRob.cpp v_repExtBubbleRob.h v_repExtBubbleRob.pro then I tried to make .dll file same as v_repExtBubbleRob.dll with out any modification with visual studio. It make v_repExtBubbleRob.dll file. I cut v_repExtBubbleRob.dll in VREP folder and copy my file.
when I run v-rep : load failed (could not load). The plugin probably couldn't load dependency libraries. I think I do it in wrong way. Could you please tell me step of creating it.

coppelia
Site Admin
Posts: 10337
Joined: 14 Dec 2012, 00:25

Re: how to write algorithm in plugin

Post by coppelia »

Use dependency walker to find out about missing dependencies. Normally it shouldn't make a difference since the V-REP interface is C (i.e. not C++), but what compiler version are you using? V-REP V3.5.0 uses VC2015, that's the V14.0 toolset.

Cheers

ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

Re: how to write algorithm in plugin

Post by ariyayi »

Hi,

V-REP version is 3.5.0

Comiler version
Image

Image

visual studio output:

Code: Select all

1>------ Rebuild All started: Project: v_repExtBubbleRob, Configuration: Debug Win32 ------
1>v_repLib.cpp
1>v_repExtBubbleRob.cpp
1>stackString.cpp
1>stackObject.cpp
1>stackNumber.cpp
1>stackNull.cpp
1>stackMap.cpp
1>stackBool.cpp
1>stackArray.cpp
1>socketOutConnection.cpp
1>Adding library: Winmm.lib
1>Adding library: Ws2_32.lib
1>socketInConnection.cpp
1>Adding library: Winmm.lib
1>Adding library: Ws2_32.lib
1>c:\program files\v-rep3\v-rep_pro_edu\programming\v_repextbubblerob\v_repextbubblerob\socketinconnection.cpp(66): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\um\winsock2.h(1848): note: see declaration of 'inet_ntoa'
1>scriptFunctionDataItem.cpp
1>scriptFunctionData.cpp
1>luaFunctionDataItem.cpp
1>luaFunctionData.cpp
1>Generating Code...
1>shared_memory.c
1>c:\program files\v-rep3\v-rep_pro_edu\programming\v_repextbubblerob\v_repextbubblerob\shared_memory.c(108): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\ucrt\stdio.h(1774): note: see declaration of 'sprintf'
1>   Creating library C:\Program Files\V-REP3\V-REP_PRO_EDU\programming\v_repExtBubbleRob\Debug\v_repExtBubbleRob.lib and object C:\Program Files\V-REP3\V-REP_PRO_EDU\programming\v_repExtBubbleRob\Debug\v_repExtBubbleRob.exp
1>v_repExtBubbleRob.vcxproj -> C:\Program Files\V-REP3\V-REP_PRO_EDU\programming\v_repExtBubbleRob\Debug\v_repExtBubbleRob.dll
1>v_repExtBubbleRob.vcxproj -> C:\Program Files\V-REP3\V-REP_PRO_EDU\programming\v_repExtBubbleRob\Debug\v_repExtBubbleRob.pdb (Full PDB)
1>Done building project "v_repExtBubbleRob.vcxproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

coppelia
Site Admin
Posts: 10337
Joined: 14 Dec 2012, 00:25

Re: how to write algorithm in plugin

Post by coppelia »

The images don't display...
Did you modify the plugin or is it the original plugin?

Cheers

ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

Re: how to write algorithm in plugin

Post by ariyayi »

I just tried to make Dynamic Link Library from file that are herehttps://github.com/CoppeliaRobotics/v_repExtBubbleRob with out any modification.

Code: Select all

v_repExtBubbleRob.cpp
v_repExtBubbleRob.h
v_repExtBubbleRob.pro
.
V-REP version is 3.5.0.
visual studio 2017 , compiler VC 2015 (v140)

I copy v_repExtBubbleRob.dll file that created by Visual Studio into V-REP directory and when V-REP run
in front of "BubbleRob" plugin :

Code: Select all

The plugin probably couldn't load dependency libraries. I think I do it in wrong way. Could you please tell me step of creating it.
I also do it with Qt 5.9.0 but the results are same.

also original v_repExtBubbleRob.dll is about 100KB but my file is about 600KB .

I said before it is my first time and I am not familiar with making dynamic share library, is there any file(lib) I must add before building dll file ?

Can I open original v_repExtBubbleRob.dll file to modify it ?

ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

Re: how to write algorithm in plugin

Post by ariyayi »

I fixed it. In Qt 5.9.0 I select kit "Desktop Qt 5.9.0 MSVC2015 64bit" then in configuration change Debug to release mode. it works perfect.
thanks

ariyayi
Posts: 16
Joined: 05 May 2018, 13:25

Re: how to write algorithm in plugin

Post by ariyayi »

ok

Post Reply