Hello,
that API function will not touch scaling data, i.e. if will leave the object as it is.
Additionally, at simulation end, many parameters are restored, but not all of them. If you need a perfect restoration, best would be to copy the original object/model and/or save it to a buffer, like in following simple example of a customization script attached to a dummy, handling that task:
Code: Select all
function sysCall_init()
model=sim.getObjectHandle("robotModel")
end
function sysCall_beforeSimulation()
copy=sim.saveModel(model) -- memorize the original model
print("Model data was saved")
end
function sysCall_afterSimulation()
restoreIfNeeded()
end
function restoreIfNeeded()
if copy then
sim.removeModel(model) -- destroy the modified model
model=sim.loadModel(copy) -- restore the original model
print("Model was destroyed, and restored from the original data")
copy=nil
end
end
function sysCall_cleanup()
restoreIfNeeded()
end
You can also keep scaled objects, and restore them to their initial pose something like following (scene is available in CoppeliaSim V4.3.0,
scenes/teleportDynamicModel.ttm):
Code: Select all
function memorize()
-- memorize the object poses, etc.:
-----------------------------------------------
local l=sim.setThreadAutomaticSwitch(false) -- in case this runs in a thread
initialState={}
local modelObjects=sim.getObjectsInTree(modelHandle,sim.handle_all,0)
for i=1,#modelObjects,1 do
local obj=modelObjects[i]
local data={}
data.localPose=sim.getObjectPose(obj,sim.handle_parent)
-- e.g. you could also take into account the joints' initial states:
--[[
if sim.getObjectType(obj)==sim.object_joint_type then
if sim.getJointType(obj)==sim.joint_spherical_subtype then
data.jointM=sim.getJointMatrix(obj)
else
data.jointPos=sim.getJointPosition(obj)
end
end
--]]
initialState[obj]=data
end
sim.setThreadAutomaticSwitch(l)
-----------------------------------------------
end
function restore()
-- Restore the model to its original position/orientation:
----------------------------------------------------
local l=sim.setThreadAutomaticSwitch(false) -- in case this runs in a thread
for handle, data in pairs(initialState) do
sim.setObjectPose(handle,sim.handle_parent,data.localPose)
-- e.g. you could also take into account the joints' initial states:
--[[
if data.jointPos then
sim.setJointPosition(handle,data.jointPos)
end
if data.jointM then
sim.setSphericalJointMatrix(handle,data.jointM)
end
--]]
sim.resetDynamicObject(handle)
end
sim.setThreadAutomaticSwitch(l)
----------------------------------------------------
end
function sysCall_init()
modelHandle=sim.getObjectHandle("robotModel")
memorize()
end
Cheers