An error when using simIK.findConfig

Typically: "How do I... ", "How can I... " questions
Post Reply
165561
Posts: 1
Joined: 30 Mar 2024, 11:30

An error when using simIK.findConfig

Post by 165561 »

Hello team!

I want to perform low-level control of joints in C++. The input for the controller, which was written in C++, is the subtraction between the joint’s target position and its current position (similar to the inData.error in sysCall_joint). Therefore, I intend to use simIK.findConfig (which I’ve implemented in a function named IKconfig) to obtain the target configuration. Additionally, I plan to use simxCallScriptFunction in C++ to receive the return value from simIK.findConfig. To ensure that simIK.findConfig runs correctly, I initially attempted to invoke it in CoppeliaSim.

Here are the steps I followed:

In sysCall_init(), I created the IK Environment and Group, and added an IK element using simIK.addIkElementFromScene.
In sysCall_actuation(), I invoked the IKconfig function (simIK.findConfig).

However, I encountered the following error: “in sim.genericFunctionHandler: Found invalid joint handle.”

I am certain that the joint handle is valid because, after encountering the error, I attempted to use the same joint handle to execute functions like sim.getJointVelocity, and the results were normal.

Could you please explain why this error occurs and provide guidance on how to resolve it?

The definition of the IKconfig function is as follows:

Code: Select all

function IKconfig()
    jointPositions = simIK.findConfig(ikEnv,ikGroup,simJoints,0.1,0.5,{1,1,1,0.1},nil,nil)
    return jointPositions                              
end

fferri
Posts: 1231
Joined: 09 Sep 2013, 19:28

Re: An error when using simIK.findConfig

Post by fferri »

165561 wrote: 30 Mar 2024, 13:15 I encountered the following error: “in sim.genericFunctionHandler: Found invalid joint handle.”
The IK plugin creates a copy of the simulated environment, so you will have the "sim" world, and the "IK" world which uses a different set of handles.

Most of the simIK functions use "IK" world handles.

A map to convert from "sim" handle to "IK" handle is returned by simIK.addElementFromScene (return arg simToIkObjectMap), e.g. you can use simToIkObjectMap[jointHandle] to obtain the "IK" world handle of a joint whose sim handle is jointHandle.

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

Re: An error when using simIK.findConfig

Post by coppelia »

Hello,

you are mixing up the IK and the CoppeliaSim worlds: the IK world has its own set of handles. The IK world might reflect the CoppeliaSim world structurally (i.e. both kinematic chains in the IK and CoppeliaSim world are identical), but handles are distinct.

You can find out about a handle's counterpart by using the return values 2 and 3 from simIK.addElementFromScene:

Code: Select all

    local ikElement, simToIkMap, ikToSimMap = simIK.addElementFromScene(ikEnv, ikGroup, simBase, simTip, simTarget, constraints)
    
    -- Find the counterpart of simTip:
    local ikWorldTip = simToIkMap[simTip]

    -- Find the counterpart of ikWorldTip:
    local simWorldTip = ikToSimMap[ikWorldTip] -- should be the same as simTip
So arguments related to handles in simIK.findConfig should only be handles from the IK world.

Cheers

Post Reply