Created
May 21, 2019 13:37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is a customization script. It is intended to be used to customize a scene in | |
-- various ways, mainly when simulation is not running. When simulation is running, | |
-- do not use customization scripts, but rather child scripts if possible | |
-- if you wish to execute code contained in an external file instead, | |
-- use the require-directive, e.g.: | |
-- | |
-- require 'myExternalFile' | |
-- | |
-- Above will look for <V-REP executable path>/myExternalFile.lua or | |
-- <V-REP executable path>/lua/myExternalFile.lua | |
-- (the file can be opened in this editor with the popup menu over | |
-- the file name) | |
get_shapes=function(baseObject,shapetype) | |
index=0 | |
shapeHandle=sim.getObjects(index,shapetype) | |
shapeHandles = {} | |
count=0 | |
while shapeHandle ~= -1 | |
do | |
parentHandle=sim.getObjectParent(shapeHandle) | |
-- if parentHandle ~= -1 and string.find(sim.getObjectName(shapeHandle), "node") then | |
-- childshape=sim.getObjectChild(shapeHandle,0) | |
-- if childshape >=0 then | |
-- shapeHandles[count]=shapeHandle | |
-- count=count+1 | |
-- end | |
-- end | |
if parentHandle ~= -1 and parentHandle==baseObject then | |
--childshape=sim.getObjectChild(shapeHandle,0) | |
--if childshape >=0 then | |
shapeHandles[count]=shapeHandle | |
count=count+1 | |
-- end | |
end | |
shapeHandle=sim.getObjects(index,shapetype) | |
index=index+1 | |
end | |
return shapeHandles,count | |
end | |
make_convex=function() | |
sim.addStatusbarMessage('Making convex') | |
index=0 | |
shapeHandle=sim.getObjects(index,sim.object_shape_type) | |
shapeHandles = {} | |
count=0 | |
while shapeHandle ~= -1 | |
do | |
parentHandle=sim.getObjectParent(shapeHandle) | |
if parentHandle ~= -1 and sim.getObjectName(parentHandle)=='pipete_convoyer' then | |
if sim.getObjectChild(shapeHandle,0)<0 then | |
shapeHandles[count]=shapeHandle | |
count=count+1 | |
end | |
end | |
shapeHandle=sim.getObjects(index,sim.object_shape_type) | |
index=index+1 | |
end | |
sim.addStatusbarMessage('shapes count: '..count) | |
for i=0,count-1 do | |
shape=shapeHandles[i] | |
name=sim.getObjectName(shape) | |
sim.addStatusbarMessage('processing shape: '..name) | |
object = sim.convexDecompose(shape, 8+16, | |
{100,3000, 3000, 0, 0, 100000, 20, 4, 4, 64}, | |
{1, 3, 0.5, 0.0, 0.0, 0.0025, 0.05, 0.05, 0.00125, 0.0001}) | |
sim.setObjectParent(object,shape,true) | |
sim.setObjectInt32Parameter(object,10,1) | |
end | |
end | |
function firstToUpper(str) | |
return (str:gsub("^%l", string.upper)) | |
end | |
set_convoyer_dummies=function() | |
sim.addStatusbarMessage('Setting convoyer dummies') | |
shapeHandles,count=get_shapes(sim.getObjectHandle("pipetePath"),sim.object_shape_type) | |
path=sim.getObjectHandle('pipetePath') | |
for i=0,count-1 do | |
node=shapeHandles[i] | |
nodename=sim.getObjectName(node) | |
dummyname='dummy'..nodename | |
sim.addStatusbarMessage('processing node: '..nodename) | |
local savedState=sim.getInt32Parameter(sim.intparam_error_report_mode) | |
sim.setInt32Parameter(sim.intparam_error_report_mode,0) | |
dummynode=sim.getObjectHandle(dummyname) | |
sim.addStatusbarMessage('dummynode: '..dummynode) | |
sim.setInt32Parameter(sim.intparam_error_report_mode,savedState) | |
if dummynode<0 and false then | |
sim.addStatusbarMessage('creating dummy: '..dummyname) | |
dummynode=sim.createDummy(0.001) | |
sim.setObjectName(dummynode,dummyname) | |
sim.setObjectParent(dummynode,path,true) | |
nodepos=sim.getObjectPosition(node,path) | |
nodeclosestpos=sim.getClosestPositionOnPath(path,nodepos) | |
sim.addStatusbarMessage('shapeclosepos: '..nodeclosestpos) | |
nodeposonpath=sim.getPositionOnPath(path,nodeclosestpos) | |
nodecloseorient=sim.getOrientationOnPath(path,nodeclosestpos) | |
sim.setObjectPosition(dummynode,-1,nodeposonpath) | |
sim.setObjectOrientation(dummynode,-1,nodecloseorient) | |
sim.setObjectParent(node,dummynode,true) | |
else | |
sim.setObjectInt32Parameter(dummynode,10,0) | |
end | |
-- | |
-- if dummyShape>-1 then | |
-- sim.addStatusbarMessage('processing shape: '..name) | |
--shapepos=sim.getObjectPosition(shape,-1) | |
--sim.setObjectPosition(dummy,-1,shapepos) | |
-- sim.removeObject(dummyShape) | |
-- end | |
--local extracted = string.match(name, "node(.*)") | |
--local nodenumber = tonumber(extracted) | |
-- if nodenumber>170 then | |
-- sim.addStatusbarMessage('processing shape: '..name) | |
-- sim.setObjectInt32Parameter(shape,10,1) | |
-- end | |
--sim.setObjectSpecialProperty(shape,0) | |
--sim.setObjectParent(shape,pipetePath,true) | |
-- dummy=sim.createDummy(0.001) | |
-- sim.setObjectName(dummy,'dummyNode'..extracted) | |
-- sim.setObjectParent(dummy,path,true) | |
-- nodepos=sim.getObjectPosition(node,-1) | |
-- sim.setObjectPosition(dummy,-1,nodepos) | |
end | |
end | |
show_by_filter=function() | |
end | |
filter_by_parents=function() | |
sim.addStatusbarMessage('Setting physics') | |
-- Put some initialization code here: | |
sim.setThreadSwitchTiming(2) -- Default timing for automatic thread switching | |
index=0 | |
shapeHandle=sim.getObjects(index,sim.object_shape_type) | |
shapeHandles = {} | |
count=0 | |
while shapeHandle ~= -1 | |
do | |
parentHandle=sim.getObjectParent(shapeHandle) | |
if parentHandle ~= -1 and string.find(sim.getObjectName(shapeHandle), "node") then | |
childshape=sim.getObjectChild(shapeHandle,0) | |
if childshape >=0 then | |
shapeHandles[count]=shapeHandle | |
count=count+1 | |
end | |
end | |
shapeHandle=sim.getObjects(index,sim.object_shape_type) | |
index=index+1 | |
end | |
sim.addStatusbarMessage('child shapes count: '..count) | |
pipetePath=sim.getObjectHandle("pipetePath") | |
for i=0,count-1 do | |
shape=shapeHandles[i] | |
name=sim.getObjectName(shape) | |
sim.addStatusbarMessage('processing shape: '..name) | |
--sim.setObjectSpecialProperty(shape,0) | |
--sim.setObjectParent(shape,pipetePath,true) | |
end | |
end | |
show_hide_nodes=function() | |
shapeHandles,count=get_shapes(sim.getObjectHandle("pipetePath"),sim.handle_all) | |
sim.addStatusbarMessage('shapes: '..count) | |
for i=0,count-1 do | |
shape=shapeHandles[i] | |
name=sim.getObjectName(shape) | |
-- local extracted = string.match(name, "node(.*)") | |
-- local nodenumber = tonumber(extracted) | |
-- if nodenumber>170 then | |
sim.addStatusbarMessage('processing shape: '..name) | |
sim.setObjectInt32Parameter(shape,10,0) | |
--end | |
--sim.setObjectSpecialProperty(shape,0) | |
--sim.setObjectParent(shape,pipetePath,true) | |
end | |
end | |
function sysCall_init() | |
-- do some initialization here | |
end | |
function sysCall_nonSimulation() | |
-- is executed when simulation is not running | |
end | |
function sysCall_cleanup() | |
-- do some clean-up here | |
end | |
function sysCall_beforeSimulation() | |
set_convoyer_dummies() | |
--show_hide_nodes() | |
end | |
-- You can define additional system calls here: | |
--[[ | |
function sysCall_beforeSimulation() | |
end | |
function sysCall_actuation() | |
end | |
function sysCall_sensing() | |
end | |
function sysCall_suspend() | |
end | |
function sysCall_suspended() | |
end | |
function sysCall_resume() | |
end | |
function sysCall_afterSimulation() | |
end | |
function sysCall_beforeInstanceSwitch() | |
end | |
function sysCall_afterInstanceSwitch() | |
end | |
function sysCall_dynCallback(inData) | |
end | |
function sysCall_jointCallback(inData) | |
return outData | |
end | |
function sysCall_contactCallback(inData) | |
return outData | |
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 | |
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 | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment