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