Page 1 of 1

Ant robot resetting to initial state

Posted: 09 Feb 2019, 01:55
by faisalkhan
what is the proper way of loading and unloading model. i want to reset robot to it initial configuration e.g. position,joint angles.Can you provide the script to do this as i tried using loadmodel and removemodel function but failed.

Re: Ant robot resetting to initial state

Posted: 12 Feb 2019, 09:32
by coppelia
Hello,

what do you mean with
but failed
?
Normally you can load a model also during simulation. The only thing is that if you want to reposition a dynamically enabled model, you should do it directly after loading the model. In a non-threaded child script this is trivial. In a threaded child script you would do:

Code: Select all

    sim.setThreadAutomaticSwitch(false)
    local h=sim.loadModel('myModel.ttm')
    local p=sim.getObjectPosition(h,-1)
    p[1]=0.5
    sim.setObjectPosition(p,-1,p)
    sim.setThreadAutomaticSwitch(true)
If you have a model that was already dynamically simulated and you want to reset it to a specific position, it gets even trickier, since you need to remove all its objects from its dynamic representation before changing its position:

Code: Select all

    sim.setThreadAutomaticSwitch(false) -- if your script is threaded
    local objects=sim.getObjectsInTree(modelHandle)
    for i=1,#objects,1 do
        sim.resetDynamicObject(objects[i])
    end
    local p=sim.getObjectPosition(h,-1)
    p[1]=0.5
    sim.setObjectPosition(p,-1,p)
    sim.setThreadAutomaticSwitch(true) -- if your script is threaded
You can read more about that here.

Cheers