UR5 IK Path Generation Fails

Typically: "How do I... ", "How can I... " questions
Post Reply
La_Fayette
Posts: 3
Joined: 30 Oct 2024, 15:06

UR5 IK Path Generation Fails

Post by La_Fayette »

I am working with CoppeliaSim and I have implemented a control script for the UR5 and UR10 robotic arms. The code for the UR10 works perfectly, while the same logic for the UR5 fails with the error message: ‘Error: No path generated’. This means that the inverse kinematics (IK) path generation for the UR5 does not work, even though all relevant objects are found in the simulation environment.
When I run the script for the UR10 robot, it correctly finds all objects (base, tip, joints, target pose) and generates a valid trajectory for the motion.
On the contrary, when I run the same code for the UR5 robot, the script can locate all the objects, but it does not generate a trajectory. And I only move the script from one robot to the other, allegedly this should work.

I'm basing the simulation on this YouTube playlist https://www.youtube.com/watch?v=pObt5SB ... Kg&pp=iAQB, and the code on the robot's script, as it is treated in the videos, comes from \scenes\kinematics\ikPathGeneration.ttt.

I'll be enormously thankful.

This is the link to my project: https://drive.google.com/file/d/1q4Nj4K ... drive_link
And this is the code that finds all objects for both robots but only generates a path for UR10:

Code: Select all

sim=require'sim'
simIK=require'simIK'

function hopThroughConfigs(path, joints, reverse, dynModel)
    local lb = sim.setStepping(true)
    local s = 1
    local g = #path / 6
    local incr = 1
    if reverse then
        s = #path / 6
        g = 1
        incr = -1
    end
    for i = s, g, incr do
        if dynModel then
            for j = 1, #joints, 1 do
                sim.setJointTargetPosition(joints[j], path[(i-1)*6+j])
            end
        else
            for j = 1, #joints, 1 do
                sim.setJointPosition(joints[j], path[(i-1)*6+j])
            end
        end
        sim.step()
    end
    sim.setStepping(lb)
end

function sysCall_thread()
    print("Starting UR5 script...")

    local simBase = sim.getObject('..')
    if simBase == -1 then
        print("Error: Base object not found.")
        return
    else
        print("Base object found.")
    end

    local simTip = sim.getObject('../tip')
    if simTip == -1 then
        print("Error: Tip object not found.")
        return
    else
        print("Tip object found.")
    end

    local simGoal = sim.getObject('/goalPose')
    if simGoal == -1 then
        print("Error: Goal Pose object not found.")
        return
    else
        print("Goal Pose object found.")
    end

    local simJoints = {}
    for i = 1, 6, 1 do
        simJoints[i] = sim.getObject('../joint', { index=i-1 })
        if simJoints[i] == -1 then
            print("Error: Joint " .. i .. " not found.")
            return
        else
            print("Joint " .. i .. " found.")
        end
    end

    sim.step() -- Ensure we have skipped the first simulation step
    local dynModel = sim.isDynamicallyEnabled(simJoints[1])
    print("Dynamic model enabled: " .. tostring(dynModel))

    -- Prepare an IK group
    local ikEnv = simIK.createEnvironment()
    local ikGroup = simIK.createGroup(ikEnv)
    local ikElement, simToIkMap = simIK.addElementFromScene(ikEnv, ikGroup, simBase, simTip, simGoal, simIK.constraint_pose)

    -- Retrieve some handles of objects created in the IK environment:
    local ikTip = simToIkMap[simTip]
    local ikJoints = {}
    for i = 1, #simJoints, 1 do
        ikJoints[i] = simToIkMap[simJoints[i]]
    end

    -- Generate a path
    local path = simIK.generatePath(ikEnv, ikGroup, ikJoints, ikTip, 300)

    if path == nil or #path == 0 then
        print("Error: No path generated.")
        simIK.eraseEnvironment(ikEnv)
        return
    end

    print("Path generated successfully.")

    simIK.eraseEnvironment(ikEnv)

    -- Hop through the path configurations
    while true do
        hopThroughConfigs(path, simJoints, false, dynModel)
        hopThroughConfigs(path, simJoints, true, dynModel)
    end
end
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: UR5 IK Path Generation Fails

Post by coppelia »

Hello,

the problem with the second robot is that it starts in a singular configuration, i.e. it loses several DoFs when stretched like that and Ik can't work. The solution: simply slightly move away from that configuration, so that you regain all 6 DoFs again. You can do this by e.g. setting an initial angle of +1 and -1 for the 3rd and 4th joint respectively.

Cheers
Post Reply