Hello,
sim.followPath is deprecated and only works with the old-type path objects. That function is still there for backward compatibility reasons, but old-type paths are not available directly anymore since CoppeliaSim V4.2
Use the
new paths object, and use your own path following function. As an example, open the demo scene
scenes/movingAlongAPath.ttt, and replace the code of the blue cube with following:
Code: Select all
function sysCall_init()
cube=sim.getObject('.')
path=sim.getObject('/Path')
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)
velocity=0.04 -- m/s
corout=coroutine.create(coroutineMain)
end
function sysCall_actuation()
if coroutine.status(corout)~='dead' then
local ok,errorMsg=coroutine.resume(corout)
if errorMsg then
error(debug.traceback(corout,errorMsg),2)
end
end
end
function coroutineMain()
sim.setThreadAutomaticSwitch(false)
followPath(0,totalLength*0.25,velocity,0.01,99)
followPath(totalLength*0.25,-totalLength*0.25,velocity*2,0.01,99)
followPath(-totalLength*0.25,2*totalLength,velocity*4,0.01,99)
end
function callback(config,vel,accel)
local p=config[1]
p=p%totalLength
local pos=sim.getPathInterpolatedConfig(pathPositions,pathLengths,p)
local quat=sim.getPathInterpolatedConfig(pathQuaternions,pathLengths,p,nil,{2,2,2,2})
sim.setObjectPosition(cube,path,pos)
sim.setObjectQuaternion(cube,path,quat)
end
function followPath(startPos,endPos,vel,accel,jerk)
sim.moveToConfig(-1,{startPos},{0},{0},{vel},{accel},{jerk},{endPos},{0},callback)
end
also about your code: it would do nothing anyway, since the condition sim.getSimulationTime()>4 won't be met, and your thread will immediately end. Instead it should be something like:
Code: Select all
function coroutineMain()
sim.setThreadAutomaticSwitch(false)
while sim.getSimulationTime()<4 do
sim.switchThread()
end
follow path here
end
Make sure to use CoppeliaSim V4.3, or at least V4.2! (but CoppeliaSim V4.3 just came out and introduced many new features and bug fixes)
Cheers