I have this function from MotionPlanning scene:
Code: Select all
generatePathLengths=function(path)
-- Returns a table that contains a distance along the path for each path point
--for i=1, #path, 1 do
--printToConsole(path[i])
--end
local d=0
local l=6
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)
--printToConsole(d)
--retLengths[i+1]=d
table.insert(retLengths, d)
--print(retLengths[i+1])
end
for i=1, #retLenghts, 1 do
printToConsole(retLengths[i])
end
return retLengths
end
Code: Select all
0.040448429027207
0.081479386441184
0.12355868558718
0.16654204371931
0.21072063183018
0.2560940060319
0.30281931954343
0.35024715469976
0.39988492808365
0.45105952853239
0.50385022504862
0.55833624737192
0.6146043240016
0.67275371326007
0.73291094779395
0.79525364546093
0.85998775021026
0.92737530111189
0.99776308425344
I have tried both ways to add values of 'd' to retLengths: ''retLengths[i+1]=d'' and ''table.insert(retLengths, d)''
But as you can see the line "print(retLengths[i+1])", it prints out 19 values throughout the loop. What could be the reason for this? Everything is being calculated fine, but returning a nill, due to which further processing is stuck. Am I missing something here ???
Thanks