Ant robot resetting to initial state
-
- Posts: 14
- Joined: 19 Sep 2018, 15:53
Ant robot resetting to initial state
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
Hello,
what do you mean with
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:
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:
You can read more about that here.
Cheers
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)
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
Cheers