(二)插件

Plugins

A plugin is a shared library (e.g. a dll) that is automatically loaded by CoppeliaSim's main client application at program start-up, or dynamically loaded/unloaded via sim.loadModule/sim.unloadModule. It allows CoppeliaSim's functionality to be extended by user-written functions (in a similar way as with add-ons). The language can be any language able to generate a shared library and able to call exported C-functions (e.g. in the case of Java, refer to GCJ and IKVM). A plugin can also be used as a wrapper for running code written in other languages or even written for other microcontrollers (e.g. a plugin was written that handles and executes code for Atmel microcontrollers).

插件是一个可分享的库(例如,一个dll动态链接库),在程序开始的时候由CoppeliaSim的主客户应用自动装载,或由sim.loadModule/sim.unloadModule动态装载/卸载。

它使得CoppeliaSim的功能可以由用户写的函数(与以add-ons的扩展方式类似)得到扩展。

它的语言可以是任意一种语言,只要能产生可分享的库并且能够调用到处的c函数(例如Java,参考GCJ和IKVM)。

插件也可以用作 wrapper 用于运行其他语言编写的代码,甚至是其他微控制器编写的代码(例如,处理和执行Atmel微控制器的代码的插件)。

Plugins are usually used to customize the simulator and/or a particular simulation. Often, plugins are only used to provide a simulation with custom script commands, and so are used in conjunction with scripts. Other times, plugins are used to provide CoppeliaSim with a special functionality requiring either fast calculation capability (scripts are most of the times slower than compiled languages) or an interface to a hardware device (e.g. a real robot).

插件通常用于定制模拟器和/或特定的仿真。

通常,插件只用于使用自定义脚本命令编写的仿真,以及与脚本联合使用。(自定义脚本命令:

sim.registerScriptFunction (Lua)                       simRegisterScriptCallbackFunction (C/C++)
sim.registerScriptVariable (Lua)                       simRegisterScriptVariable (C/C++)

其他时候,插件被用来为CoppeliaSim提供一种特殊的功能,这种功能要么需要快速的计算能力(脚本的速度通常比编译语言慢),要么需要一个与硬件设备(例如,一个真正的机器人)的接口。

Each plugin is required to have following 3 entry point procedures:

每个插件都需要有以下3个入口点过程:

extern "C" __declspec(dllexport) unsigned char simStart(void* reserved,int reservedInt);
extern "C" __declspec(dllexport) void simEnd();
extern "C" __declspec(dllexport) void* simMessage(int message,int* auxiliaryData,void* customData,int* replyData);

If one procedure is missing then the plugin will be unloaded and won't be operational. Refer to the console window at start-up for the loading status of plugins. Following briefly describes above three entry point purpose:

如果缺少一个过程,则插件将被卸载,并且将不可操作。参考 控制台窗口 在启动时为插件的加载状态。以下简要介绍了上述三个入口点的目的:

 

simStart

This procedure will be called one time just after the main client application loaded the plugin. The procedure should:

这个过程将在主客户端应用程序加载插件后调用一次。程序应:

  • check whether the version of CoppeliaSim is same or higher than the one that was used to develop the plugin (just make sure all commands you use in the plugin are supported!).
  • 检查CoppeliaSim的版本是否与用于开发插件的版本相同或更高(只需确保插件中使用的所有命令都受支持!)。
  • allocate memory, and prepare GUI related initialization work (if required).
  • 分配内存,并准备GUI相关的初始化工作(如果需要)。
  • register custom script functions (if required).
  • 注册自定义脚本函数(如果需要)。
  • register custom script variables (if required) .
  • 注册自定义脚本变量(如果需要)。
  • return the version number of this plugin if initialization was successful, otherwise 0. If 0 is returned, the plugin is unloaded and won't be operational. Due to backward compatibility, the version number is limited to values between 1 and 255. To overcome this limitation, one can additionaly also use following API functions: simSetModuleInfo / simGetModuleInfo.
  • 如果初始化成功,则返回该插件的版本号,否则返回0。如果返回0,则卸载该插件,并且该插件将不可操作。由于向后兼容,版本号限制为1到255之间的值。要克服此限制,还可以使用以下API函数: simSetModuleInfo / simGetModuleInfo。
     

simEnd

This procedure will be called one time just before the simulation loop exits. The procedure should release all resources reserved since simStart was called.

此过程将在模拟循环退出之前调用一次。该过程应释放由simStart启用的所有资源。

simMessage

This procedure will be called very often while the simulator is running. The procedure is in charge of monitoring messages of interest and reacting to them. It is important to react to following events (best by intercepting the sim_message_eventcallback_instancepass message) depending on your plugin's task:

当模拟器运行时,将经常调用此过程。程序负责监视感兴趣的消息并对其作出反应。对以下事件做出反应很重要(最好是拦截 sim_message_eventcallback_instancepass 消息)根据插件的任务:

  • When objects were created, destroyed, scaled, or when models are loaded: make sure you reflect the change in the plugin (i.e. synchronize the plugin with the scene content)
  • 当物体被创建、销毁、缩放或者当模型被加载时:确保你在插件中对此变化进行了反应(即:将插件与场景内容同步)
  • When scenes were loaded or the undo/redo functionality called: make sure you erase and reconstruct all plugin objects that are linked to the scene content
  • 当场景被加载或者撤销/重做功能被调用时:确保你擦除或重构了与场景内容相连接的所有插件对象
  • When the scene was switched: make sure you erase and reconstruct all plugin objects that are linked to the scene content. In addition to this, remember that a scene switch will discard handles of following items:
  • 当场景变化时:确保你擦除或重构场景内容中的所有插件对象。另外,请记住,场景切换将丢弃以下句柄:
  • signals 信号
  • drawing objects 图像对象
  • etc. 等
  • When the simulator is in an edit mode: make sure you disable any "special functionality" provided by the plugin, until the edit mode was ended. In particular, make sure you do not programmatically select scene objects.
  • 当你的模拟器处在编辑模式时:确保禁用插件提供的任何“特殊功能”,直到编辑模式结束。特别是,请确保您没有以编程方式选择 场景对象。
  • When a simulation was launched: make sure you initialize your plugin elements if needed
  • 启动模拟时:如果需要,请确保初始化插件元素
  • When a simulation ended: make sure you release any memory and plugin elements that are only required during simulation
  • 当模拟结束时:确保您释放了所有只在模拟过程中需要的内存和插件元素
  • When the object selection state was changed, or a dialog refresh message was sent: make sure you actualize the dialogs that the plugin displays
  • 当对象选择状态被更改,或者发送了一条对话框刷新消息时:确保实现插件显示的对话框

Refer to the messages of type sim_message_eventcallback_ for more details. When writing plugins several additional points have to be observed or taken into account:

请参阅类型sim_message_eventcallback_以了解更多细节。在编写插件时,必须注意或考虑几个额外的要点

  • Plugins have to be put into the same directory as the main client application and respect following naming: simExtXXXX.dll (Windows), libsimExtXXXX.dylib (Mac OSX), libsimExtXXXX.so (Linux), where XXXX is the name of the plugin. Use at least 4 characters and don't use underscores since the plugin would be ignored (however you should use underscores when your plugin itself loads some additional libraries (e.g. language resources like simExtXXXX_de.dll, etc.)).
  • 插件必须放在 主客户端应用程序 同一目录下, 并遵循以下命名规则:simExtXXXX.dll (Windows), libsimExtXXXX.dylib (Mac OSX), libsimExtXXXX.so (Linux), 其中 XXXX  是插件的名称。使用至少4个字符,不要使用下划线,否则该插件将被忽略(但是当插件本身加载一些附加库可以使用下划线(例如语言资源,如 simExtXXXX_de.dll等)。

  • When registering customized script functions or script variables, use a prefix and stick to it for all functions and variables that the module registers (e.g. simLab.testMemory()simLab.errorValue, etc.).
  • 注册自定义脚本函数或脚本变量时,使用前缀并将其粘贴到模块注册的所有函数和变量(例如:simLab.testMemory()simLab.errorValue等)。

  • Threads created in the plugin should be used very carefully, and should never call any simulator command (use them for background calculations or communication with hardware).
  • 插件中创建的线程应该非常小心地使用,并且不应该调用任何模拟器命令(使用它们进行背景计算或与硬件通信)。

  • When outputting messages, use simAddLog.
  • 输出消息时,使用 simAddLog。

You are free to compile your plugin with whatever compiler you wish. If, however, you wish to write a Qt plugin (i.e. a plugin using the Qt framework) you should remember following:

你可以自由地用任何你想要的编译器编译你的插件。但是,如果您希望编写一个Qt插件(即使用Qt框架的插件),您应该记住以下几点:

  • You are required to compile the plugin with the same Qt version as the one used to compile CoppeliaSim. Have a look at the CoppeliaSim [Help --> About] menu bar item for details about Qt version
  • 您需要使用编译CoppeliaSim时使用的Qt版本编译插件。有关Qt版本的详细信息,请查看CoppeliaSim[Help-->About]菜单栏项

  • You should compile the plugin with the same compiler as CoppeliaSim
  • 您应该使用与CoppeliaSim相同的编译器编译插件

For more information on plugins, refer to following repositories:

有关插件的更多信息,请参阅以下存储库:

  • simExtPluginSkeleton: represents a plugin template that you can use to create your own plugin. See also simExtSkel
  • simExtPluginSkeleton:表示可以用来创建自己插件的插件模板。另请参见simExtSkel
  • simExtVision: a plugin that handles specific vision tasks (e.g. simulation of the Velodyne sensor, or simulation of an omnidirectional camera).
  • simExtVision:一个处理特定视觉任务的插件(例如,模拟Velodyne传感器,或模拟全向相机)。

    simExtBubbleRob: illustrates how to add customized Lua functions and how to handle several specific models. Refer also to the related plugin tutorial.

  • simExtBubbleRob:演示如何添加定制的Lua函数以及如何处理几个特定的函数 模型。另请参阅 相关插件教程。

    simExtK3: the plugin related to the KheperaIII model.

  • simExtK3:与KheperaIII模型相关的插件。

  • simExtRemoteApi: the plugin related to the legacy remote API functionality (server side).
  • simExtRemoteApi:与 传统远程API功能 (服务器端)。

  • simExtROS: the ROS package allowing you to build the ROS Interface for CoppeliaSim.
  • simExtROS: Ros包允许您为CoppeliaSim构建 ROS接口。

  • simExtROS2: the ROS 2 package allowing you to build the ROS 2 Interface for CoppeliaSim.
  • simExtROS2: Ros2包允许您为CoppeliaSim构建 ROS 2接口。

  • simExtB0: the BlueZero framework wrapped in a CoppeliaSim plugin.
  • simExtB0: 封装在CoppeliaSim插件中的BlueZero 框架。
  • simExtMTB: illustrates a Qt plugin which integrates a robot language interpreter (or other emulator) into CoppeliaSim. Refer also to its related tutorial.
  • simExtMTB:演示了一个Qt插件,它将机器人语言解释器(或其他模拟器)集成到CoppeliaSim中。另请参阅相关教程。

     

CoppeliaSim plugins may be published under any license.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值