Examples of control mechanism in the Plugin V_REP

plugin mechanism is a V-REP six kinds of control mechanisms, the biggest advantage is that no delay (LAG), speed is calculated. V-REP can be embedded in the script (embeded scripts) seamlessly. This is a remote API client can not do.

Comparison of six kinds of control mechanisms:

 

Plugin

  • V-REP automatically loads all plugins that it can find in its folder
  • V-REP recognizes plugin files with following mask: "v_repExt*.dll" on Windows, "libv_repExt*.dylib" on Mac OS and "libv_repExt*.so" on Linux. 

 

Example:

Usage behavior plugin controlled car, the car using proximity sensor, when approaching an obstacle, adjust the speed of the wheel, thereby regulating the forward direction;

Script code is as follows:

 1 function sysCall_threadmain()
 2     -- Check what OS we are using:
 3     platf=sim.getInt32Parameter(sim.intparam_platform)
 4     if (platf==0) then
 5         pluginFile='v_repExtBubbleRob.dll'  --windows
 6     end
 7     if (platf==1) then
 8         pluginFile='libv_repExtBubbleRob.dylib'  -- mac
 9     end
10     if (platf==2) then
11         pluginFile='libv_repExtBubbleRob.so'   --linux
12     end
13 
14     -- Check if the required plugin is there:
15     moduleName=0
16     moduleVersion=0
17     index=0
18     bubbleRobModuleNotFound=true
19     while moduleName do
20         moduleName,moduleVersion=sim.getModuleName(index)
21         if (moduleName=='BubbleRob') then
22             bubbleRobModuleNotFound=false
23         end
24         index=index+1
25     end
26 
27     if (bubbleRobModuleNotFound) then
28         -- Plugin was not found
29         sim.displayDialog('Error',"BubbleRob plugin was not found. ('"..pluginFile.."')&&nSimulation will not run properly",sim.dlgstyle_ok,true,nil,{0.8,0,0,0,0,0},{0.5,0,0,1,1,1})
30     else
31         -- Plugin is there
32 
33         local jointHandles={sim.getObjectHandle('pluginControlledBubbleRobLeftMotor'),sim.getObjectHandle('pluginControlledBubbleRobRightMotor')}
34         local sensorHandle=sim.getObjectHandle('pluginControlledBubbleRobSensingNose')
35         local robHandle=simBubble.create(jointHandles,sensorHandle,{0.5,0.25})
36         if robHandle>=0 then
37             simBubble.start(robHandle,9999) -- control happens here
38             simBubble.stop(robHandle)
39             simBubble.destroy(robHandle)
40         end
41     end
42 end

 

逐一解释说明各段代码含义:

 1     -- Check what OS we are using:
 2     platf=sim.getInt32Parameter(sim.intparam_platform)
 3     if (platf==0) then
 4         pluginFile='v_repExtBubbleRob.dll'  --windows
 5     end
 6     if (platf==1) then
 7         pluginFile='libv_repExtBubbleRob.dylib'  -- mac
 8     end
 9     if (platf==2) then
10         pluginFile='libv_repExtBubbleRob.so'   --linux
11     end

这段代码很直接,根据操作系统不同获得相应的插件名;

 

 1     -- Check if the required plugin is there:
 2     moduleName=0
 3     moduleVersion=0
 4     index=0
 5     bubbleRobModuleNotFound=true
 6     while moduleName do
 7         moduleName,moduleVersion=sim.getModuleName(index)
 8         if (moduleName=='BubbleRob') then
 9             bubbleRobModuleNotFound=false
10         end
11         index=index+1
12     end

索引V_REP安装目录下所有的插件,判断是否存在所需要的plugin;

 

Guess you like

Origin www.cnblogs.com/hlhfhmt/p/11285740.html