Ant robot resetting to initial state

Typically: "How do I... ", "How can I... " questions
Post Reply
faisalkhan
Posts: 14
Joined: 19 Sep 2018, 15:53

Ant robot resetting to initial state

Post 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.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Ant robot resetting to initial state

Post 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

Post Reply