V_REP中Plugin控制机制实例

plugin机制是V-REP六种控制机制的一种,最大的优点就是无延迟(lag),计算速度快。可以和V-REP中的嵌入脚本(embeded scripts)实现无缝连接。这是remote API client所不能做到的。

六种控制机制的比较:

 V_REP中Plugin控制机制实例V_REP中Plugin控制机制实例

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. 

 

实例:

使用plugin控制小车的行为,小车使用proximity sensor,当接近障碍物时,调节轮的速度,进而调节前进方向;

脚本代码如下:

 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;

 

上一篇:U82394 SZY的三分图 数学


下一篇:CF993E