Restore simulation

Typically: "How do I... ", "How can I... " questions
Post Reply
Chris2
Posts: 8
Joined: 09 Mar 2022, 11:00

Restore simulation

Post by Chris2 »

Hello,

I setup a robot and defined IK groups and set them to all explicit. In a lua script I call sim.handleIKGroup() each step in sysCall_actuation(). That works fine.

When the target is to far away the robot arm do wild gestures, which I want to avoid. The easiest is to calculate some distance and restore the simulation. In the CoppeliaUI ther is a "Edit conditional params" window with "Restore if". Is there some restore functionality accessible by lua? Alternatively I would save and restore all joint positions in code. Is there a better way instead "freezing" the robot arm?

Thanks,
Chris

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

Re: Restore simulation

Post by coppelia »

Hello Chris,

it seems you are still using the old IK functionality (i.e. the one you set up via the GUI). From CoppeliaSim V4.2, IK should be entirely set up and handled programmatically, which makes things much easier, also for debugging. All demo scenes starting with V4.2 use the new approach. In there, you'd use simIK.setIkGroupFlags(ikEnv,ikGroup,4+8)

To do something similar with the old IK functionality, you'd do something like:

Code: Select all

sim.setThreadAutomaticSwitch(false) -- in case you are running threaded
local allJoints=sim.getObjectsInTree(robotBaseHandle,sim.object_joint_type,0)
local allPositions={}
for i=1,#allJoints,1 do
    allPositions[allJoints[i]]=sim.getJointPosition(allJoints[i])
end
sim.handleIkGroup()
if (wantToRestore) then
    for i=1,#allJoints,1 do
        sim.setJointPosition(allJoints[i],allPositions[allJoints[i]])
    end
end
sim.setThreadAutomaticSwitch(true)
With spherical joints, you'd have to adjust the code somewhat.

Cheers

Post Reply