[There is an array of points in space. The function alternately takes points from it and builds a path from the drone to the point along them and the drone flies and stops at the end of the path and so on again in a loop until the points run out]
Now to the problems of my scripts:
I am using the simple path sim.createPath: local path=sim.createPath(pathArray,0,100,0,0,{0,0,1})
But there are 2 problems: the path for a large number of points is built even with smoothing = 0 is very crooked and does not go into some points. And the second problem: it is not clear how to detect the drone hitting the right point on the way. Therefore, I need a function that builds a path only by 2 points (to avoid curvature) and I need to somehow stop the drone at certain points for some time on the path and then resume moving (exactly coordinatewise).
My drone move code:
Code: Select all
if(signal=='true' and Start==false) then
println('Connection')
local pointscript=sim.getScriptAssociatedWithObject(sim.getObjectHandle('Scripts'))
ClastersTable=sim.callScriptFunction("returnClastersTable@"..sim.getScriptName(pointscript),pointscript,ClastersTable)
ObjectToFollowPath=sim.getObjectHandle(sim.handle_self)
path=sim.getObjectHandle('Path1')
pathData=sim.unpackDoubleTable(sim.readCustomDataBlock(path,'PATH'))
local m=Matrix(#pathData//7,7,pathData)
pathPositions=m:slice(1,1,m:rows(),3):data()
pathQuaternions=m:slice(1,4,m:rows(),7):data()
pathLengths,totalLength=sim.getPathLengths(pathPositions,3)
Start=true
end
if(Start) then
local t=sim.getSimulationTime()
-- print(Time)
--print(t)
if(IsGo)then
posAlongPath=posAlongPath+velocity*(t-previousSimulationTime)
posAlongPath=posAlongPath % totalLength
local pos=sim.getPathInterpolatedConfig(pathPositions,pathLengths,posAlongPath)
local quat=sim.getPathInterpolatedConfig(pathQuaternions,pathLengths,posAlongPath,nil,{2,2,2,2})
for i=1,#ClastersTable,1 do
local po= sim.getObjectPosition(sim.getObjectHandle(ClastersTable[1][i]),-1)
sim.setObjectPosition(ObjectToFollowPath,path,pos)
sim.setObjectQuaternion(ObjectToFollowPath,path,quat)
previousSimulationTime=t
end
if(t-Time>=10 and IsGo==false)then
--print('T')
IsGo=true
Time=t
else
previousSimulationTime=t
end
else
previousSimulationTime=sim.getSimulationTime()
end