Add-onsAn add-on in CoppeliaSim is quite similar to a plugin: it is automatically loaded at program start-up, and allows CoppeliaSim's functionality to be extended by user-written functionality or functions. Add-ons are written in Lua. Two types of add-ons are supported: Add-on functions and scripts should be written in a text file located in the same folder as the main application, with following naming convention: Add-on scripts that do not follow above naming convention can still be loaded and run via command line options. An add-on script should be segmented in several functions, as following skeleton script illustrates: -- Return sim.syscb_cleanup if you wish to stop the add-on script function sysCall_init() end function sysCall_cleanup() end function sysCall_nonSimulation() end function sysCall_beforeSimulation() end function sysCall_beforeMainScript() -- Can be used to step a simulation in a custom manner. local outData={doNotRunMainScript=false} -- when true, then the main script won't be executed return outData end function sysCall_actuation() end function sysCall_sensing() end function sysCall_afterSimulation() end function sysCall_suspend() end function sysCall_suspended() end function sysCall_resume() end function sysCall_addOnScriptSuspend() end function sysCall_addOnScriptSuspended() end function sysCall_addOnScriptResume() end function sysCall_beforeInstanceSwitch() end function sysCall_afterInstanceSwitch() end function sysCall_beforeCopy(inData) for key,value in pairs(inData.objectHandles) do print("Object with handle "..key.." will be copied") end end function sysCall_afterCopy(inData) for key,value in pairs(inData.objectHandles) do print("Object with handle "..key.." was copied") end end function sysCall_beforeDelete(inData) for key,value in pairs(inData.objectHandles) do print("Object with handle "..key.." will be deleted") end -- inData.allObjects indicates if all objects in the scene will be deleted end function sysCall_afterDelete(inData) for key,value in pairs(inData.objectHandles) do print("Object with handle "..key.." was deleted") end -- inData.allObjects indicates if all objects in the scene were deleted end function sysCall_afterCreate(inData) for i=1,#inData.objectHandles,1 do print("Object with handle "..inData.objectHandles[i].." was created") end end Add-ons can call any of the regular API functions, as long as not stated otherwise in the documentation. They can even call custom Lua functions registered by plugins. They however have two restrictions: For more information on add-ons, make sure to inspect the content of the demo add-ons simAddOnScript-addOnScriptDemo.lua, simAddOnFunc-addOnFunctionDemo.lua and simAddOnScript-b0RemoteApiServer.lua, located in the installation folder. Recommended topics |