simIK.generatePath returns empty path when called from Lua child script

Typically: "How do I... ", "How can I... " questions
Post Reply
mevlanajr
Posts: 5
Joined: 06 Jul 2025, 11:44

simIK.generatePath returns empty path when called from Lua child script

Post by mevlanajr »

Hi, I'm using simIK.generatePath from a Lua child script to generate a straight-line Cartesian path for the UR5 robot between its tip and a goal dummy. Here's the simplified code:

Code: Select all

function sysCall_init()
    sim = require 'sim'
    simIK = require 'simIK'

    local base = sim.getObject('/UR5')
    local tip = sim.getObject('/UR5/tip')
    local goal = sim.getObject('/goal')
    local joints = {
        sim.getObject('/UR5/base_joint'),
        sim.getObject('/UR5/shoulder_joint'),
        sim.getObject('/UR5/elbow_joint'),
        sim.getObject('/UR5/wrist_1_joint'),
        sim.getObject('/UR5/wrist_2_joint'),
        sim.getObject('/UR5/wrist_3_joint'),
    }

    local ikEnv = simIK.createEnvironment()
    local ikGroup = simIK.createGroup(ikEnv)
    local ikElement, simToIkMap = simIK.addElementFromScene(
        ikEnv, ikGroup, base, tip, goal, simIK.constraint_position
    )

    local ikTip = simToIkMap[tip]
    local ikJoints = {}
    for i = 1, #joints do
        ikJoints[i] = simToIkMap[joints[i]]
    end

    local flatPath = simIK.generatePath(ikEnv, ikGroup, ikJoints, ikTip, 300)
    simIK.eraseEnvironment(ikEnv)

    print('[Lua] flatPath len =', #flatPath)
end
The issue is: flatPath is always empty (length = 0), even though the goal is clearly reachable and within range. No errors are printed, and the simulation runs without crashing.

Any idea what could be causing generatePath to silently fail?
Does this relate to object handle paths, orientation mismatch, or something else?

Here is the attached scene:
https://drive.google.com/file/d/15rbVC6 ... sp=sharing

Thanks.
coppelia
Site Admin
Posts: 10802
Joined: 14 Dec 2012, 00:25

Re: simIK.generatePath returns empty path when called from Lua child script

Post by coppelia »

Hello,

please excuse the late reply, due to summer vacation.

Your problem is that your robot starts in a singular configuration, i.e. it loses several degrees of freedom in that configuration and IK will fail. Try simply adding e.g. a 10 deg. joint value to joint elbow_joint.
Keep also in mind that even if the first and last configurations are reachable, other configurations in-between might not.

Cheers
Post Reply