Toppra - attempt to index a nil value (field 'qs')

Typically: "How do I... ", "How can I... " questions
abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

i am trying to use topp-ra for trajectory generation for 6 dof
using the function

Code: Select all

    local pathPts,times=sim.generateTimeOptimalTrajectory(path,lengths,minMaxVel,minMaxAccel)
 
but it gives the following error

Code: Select all

779: attempt to index a nil value (field 'qs')
stack traceback:
    ...rar/CoppeliaSim_Edu_V4_6_0_rev18_Ubuntu20_04/lua/sim.lua:779: in function 'sim.generateTimeOptimalTrajectory'
    

here is the inputs given to the function

Code: Select all

    local minMaxVel={-maxVel[1],maxVel[1],-maxVel[2],maxVel[2],-maxVel[3],maxVel[3],-maxVel[4],maxVel[4],-maxVel[5],maxVel[5],-maxVel[6],maxVel[6]}
    local minMaxAccel={-maxAccel[1],maxAccel[1],-maxAccel[2],maxAccel[2],-maxAccel[3],maxAccel[3],-maxAccel[4],maxAccel[4],-maxAccel[5],maxAccel[5],-maxAccel[6],maxAccel[6]}
    
    path,lengths=findPath(getConfig(),configs)
the path length and the path is calculated as follows

Code: Select all

function getPathLength(path)

    -- Returns the length of the path in configuration space

    local d=0

    local l=#simJointHandles

    local pc=#path/l

    for i=1,pc-1,1 do

        local config1={path[(i-1)*l+1],path[(i-1)*l+2],path[(i-1)*l+3],path[(i-1)*l+4],path[(i-1)*l+5],path[(i-1)*l+6]}

        local config2={path[i*l+1],path[i*l+2],path[i*l+3],path[i*l+4],path[i*l+5],path[i*l+6]}

        d=d+getConfigConfigDistance(config1,config2)

    end

    print(d)

    return d

end

function generatePathLengths(path)

    -- Returns a table that contains a distance along the path for each path point

    local d=0

    local l=#simJointHandles

    local pc=#path/l

    local retLengths={0}

    for i=1,pc-1,1 do

        local config1={path[(i-1)*l+1],path[(i-1)*l+2],path[(i-1)*l+3],path[(i-1)*l+4],path[(i-1)*l+5],path[(i-1)*l+6],path[(i-1)*l+7]}

        local config2={path[i*l+1],path[i*l+2],path[i*l+3],path[i*l+4],path[i*l+5],path[i*l+6],path[i*l+7]}

        d=d+getConfigConfigDistance(config1,config2)

        retLengths[i+1]=d

    end

    return retLengths

end

function _findPath(startConfig,goalConfigs)

    



    local task=simOMPL.createTask('task')

    simOMPL.setAlgorithm(task,simOMPL.Algorithm.RRTConnect)

    simOMPL.setStateSpaceForJoints(task,simJointHandles,useForProjection)

    simOMPL.setCollisionPairs(task,{robotCollection,sim.handle_all})

    simOMPL.setStartState(task,startConfig)

    simOMPL.setGoalState(task,goalConfigs[1])

    for i=2,#goalConfigs,1 do

        simOMPL.addGoalState(task,goalConfigs[i])

    end

    simOMPL.setup(task)

    local l=nil

    local res,path=simOMPL.compute(task,maxOMPLCalculationTime,-1,200)



    if path then

        l=getPathLength(path)

    end

    simOMPL.destroyTask(task)

    

    return path,l

end



function findPath(startConfig,goalConfigs)

    -- This function will search for a path between the specified start configuration,

    -- and several of the specified goal configurations.

    local onePath,onePathLength=_findPath(startConfig,goalConfigs)

    return onePath,generatePathLengths(onePath)

end

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

Re: Toppra - attempt to index a nil value (field 'qs')

Post by coppelia »

Hello,

if your data has 3 DoF, e.g. is a succession of xyz values, then your function expects, e.g.:

Code: Select all

sim.generatzeTimeOptimalTrajectory(
                {x1, y1, z1, ..., xN, yN, zN},
                {0, dist(x2-x1), dist(x3-x2), ..., dist(xN-xM)},
                {minVx, maxVx, minVy, maxVy, minVz, maxVz},
                {minAx, maxAx, minAy, maxAy, minAz, maxAz})
cheers

abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Re: Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

I tried to do what you have suggested but it still gives the same error
here the path

Code: Select all

    startPose = sim.getObjectPose(simTip)
    target1Pose = sim.getObjectPose(targets[1])
    target2Pose = sim.getObjectPose(targets[2])
    target3Pose = sim.getObjectPose(targets[3])
    target4Pose = sim.getObjectPose(targets[4])
    pathT= {startPose[1],startPose[2],startPose[3],
                target1Pose[1],target1Pose[2],target1Pose[3],
                target2Pose[1],target2Pose[2],target2Pose[3],
                target3Pose[1],target3Pose[2],target3Pose[3],
                target4Pose[1],target4Pose[2],target4Pose[3]}
here is the code for the toppra function

Code: Select all

function toppra(joints,path,maxVel,maxAccel,maxIterationDepth,distTol)
    local minMaxVel={-maxVel[1],maxVel[1],-maxVel[2],maxVel[2],-maxVel[3],maxVel[3],-maxVel[4],maxVel[4],-maxVel[5],maxVel[5],-maxVel[6],maxVel[6]}
    local minMaxAccel={-maxAccel[1],maxAccel[1],-maxAccel[2],maxAccel[2],-maxAccel[3],maxAccel[3],-maxAccel[4],maxAccel[4],-maxAccel[5],maxAccel[5],-maxAccel[6],maxAccel[6]}
    local pl=sim.getPathLengths(path,3)

    --local pathPts,times=sim.generateTimeOptimalTrajectory(path,pl,minMaxVel,minMaxAccel)
    local pathPts,times=sim.generateTimeOptimalTrajectory(path,pl, {20,360,20,360,20,360},{20,360,20,360,20,360})
    local lb=sim.setStepping(true)
    local st=sim.getSimulationTime()
    local dt=0
    while dt<times[#times] do
        local p=sim.getPathInterpolatedConfig(pathPts,times,dt)
        sim.setJointPosition(joints[1],p[1])
        sim.setJointPosition(joints[2],p[2])
        sim.setJointPosition(joints[3],p[3])
        sim.setJointPosition(joints[4],p[4])
        sim.setJointPosition(joints[5],p[5])
        sim.setJointPosition(joints[6],p[6])
        sim.step()
        dt=sim.getSimulationTime()-st
    end
    local p=sim.getPathInterpolatedConfig(pathPts,times,times[#times])
    sim.setJointPosition(joints[1],p[1])
    sim.setJointPosition(joints[2],p[2])
    sim.setJointPosition(joints[3],p[3])
    sim.setJointPosition(joints[4],p[4])
    sim.setJointPosition(joints[5],p[5])
    sim.setJointPosition(joints[6],p[6])
    sim.setStepping(lb)
end

also i am confused about the no. of dof i should write in the

Code: Select all

sim.getPathLengths(float[] path, int dof)
should I write 3 for xyz ?
or should i write 6 as i am using 6DOF robot manipulator?


here's a view of the used scene:
https://drive.google.com/file/d/1nGjRyU ... rive_link

abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Re: Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

the first joint is prismatic joint does that affect any thing ?

when i send 12 velocity values and 12 acceleration values two for each dof

Code: Select all

    --local pathPts,times=sim.generateTimeOptimalTrajectory(path,pl,minMaxVel,minMaxAccel)
    local pathPts,times=sim.generateTimeOptimalTrajectory(path,pl,{-1,1,20,360,20,360,20,360,20,360,20,360},{-20,60,20,360,20,360,20,360,20,360,20,360})
i get this error

Code: Select all

 Bad table size.
stack traceback:
    [C]: in function 'error'
    ...rar/CoppeliaSim_Edu_V4_6_0_rev18_Ubuntu20_04/lua/sim.lua:720: in function 'sim.generateTimeOptimalTrajectory'
    

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

Re: Toppra - attempt to index a nil value (field 'qs')

Post by coppelia »

Please print the content of those 2 first args...

abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Re: Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

here's the values of the first two argument :

Code: Select all

path = , {-0.18697777492768, 0.17304408666153, 0.69156785261529, -0.18843401532007, 0.35379786151547, 0.66025900000955, -0.20136289981033, 0.55544181316694, 0.63827241505926, -0.1487446285302, 0.76974007823206, 0.66625138077541, 0.12526892209561, 0.92441874981669, 0.66625090334619}

pl = , {0, 0.18345106162549, 0.38670176693684, 0.60913209626486, 0.92378892102793}

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

Re: Toppra - attempt to index a nil value (field 'qs')

Post by coppelia »

Your output looks strange... what is that initial comma?

Also, I am confused, you have in path exactly 15 values, and in pl exactly 5 values...

If you have a 6 DoF mechanism, then path should contain 6*n values... and pl n values...

Cheers

abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Re: Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

okay I give it the following arguments

Code: Select all

path = {1.5707963267949, 1.5707963267949, -1.5707963267949, 1.5707963267949, 1.5707963267949, 1.5707963267949, -1.5707963267949, 0.78539816339745, 1.5707963267949, 2.3561944901923, 1.5707963267949, 1.5707963267949}
pl = 2

maxVel={vel*math.pi/180,vel*math.pi/180,vel*math.pi/180,vel*math.pi/180,vel*math.pi/180,vel*math.pi/180} 
maxAccel = {accel*math.pi/180,accel*math.pi/180,accel*math.pi/180,accel*math.pi/180,accel*math.pi/180,accel*math.pi/180}
    
so that the path has 12 values(for the start and the end configuration only)
the pl 2
the min max velocity12 values the minimum and maximum velocity for each joint
the min max acceleration12 values the minimum and maximum acceleration for each joint for each joint


still gives the same error :'(

Code: Select all

attempt to index a nil value (field 'qs')
stack traceback:
    ...82AB494/d/coppeliaSim.app/Contents/Resources/lua/sim.lua:779: in function 'sim.generateTimeOptimalTrajectory'
    

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

Re: Toppra - attempt to index a nil value (field 'qs')

Post by coppelia »

Do like this:

in the demo scene scenes/trajectoryAndMotion/pathToTrajectory.ttt, open the script attached to object base and add following on line 181:

Code: Select all

print(path,pl,minMaxVel,minMaxAccel)
The run the simulation, select a few different paths, and click Time-optimal trajectory: then you will immediately see what is expected for a 2 DoF trajectory. When the input shape is wrong (or toppra generates an error), then errr is not correctly relayed to CoppeliaSim. This will be fixed in rev. 2 of V4.7, out today or tomorrow.

Cheers

abrarMahrous
Posts: 7
Joined: 04 Jun 2024, 10:04

Re: Toppra - attempt to index a nil value (field 'qs')

Post by abrarMahrous »

I was already comparing the output with demo :(
I hope this issue will be fixed ..


also if there's any demos to use topper with 6dof this would be awesome

Post Reply