Following Path function

Typically: "How do I... ", "How can I... " questions
Post Reply
chousuiri
Posts: 4
Joined: 26 Jun 2024, 09:28

Following Path function

Post by chousuiri »

There is a deprecated path function used in the following code snippet:

Code: Select all

pathLength = sim.getPathLength(path)
. I attempted to use the only usable path function (the one with dummies), but encountered the error: "in sim.getPathLength: object is not a path."

Additionally, I created the tip and the target for path following, but the tip did not follow the trajectory.

Here is my code for one of the targets:

Code: Select all

threadfunction = function()
    while true do
        sim.followPath(target, path, 1, posOnPath, v, 0)
    end
end

path = sim.getObjectHandle('/FL_Path')
target = sim.getObjectHandle('/FL_target')
pathLength = sim.getPathLength(path)

posOnPath = 0
-- v = 0.0849 --0.0797 -- 0.025 m/s
v = 0.0687
res, err =xpcall(threadfunction, function(err) return debug.traceback(err) end)

if not res then
    sim.addStatusbarMessage('lua runtime error: ' .. err)
end
Many tutorials still use the old path function, which has left me stuck.

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

Re: Following Path function

Post by coppelia »

Hello,

can you point me to the file/document that still uses those deprecated functions?

Cheers

chousuiri
Posts: 4
Joined: 26 Jun 2024, 09:28

Re: Following Path function

Post by chousuiri »

I appreciate your concern.

Here is a screenshot of the objects. I'm unsure how to recreate them, but it originated from an old file. I need help finding a replacement function since the path (dummy one) is not recognized as a valid path according to the error message.
Image

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

Re: Following Path function

Post by coppelia »

Old scene files should still be operational, but shouldn't be extended with the old-type path objects anymore. If you really must, you can simply copy-paste one such old path object, and modify the copy to what you need. You can also temporarily enable the display of old dialog items by setting variable showOldDlgs temporarily to true in usrset.txt.

Otherwise, use the new paths, there is a relevant demo scene that illustrates how to read them and operate on them: scenes/movingAlongAPath-lua.ttt

Cheers

chousuiri
Posts: 4
Joined: 26 Jun 2024, 09:28

Re: Following Path function

Post by chousuiri »

Thanks a bunch!

Cloudiness
Posts: 1
Joined: 05 Jul 2024, 11:08

Re: Following Path function

Post by Cloudiness »

Hello!
I saw that u have the same problem as mine so i wanted to ask u how did u solve your problem?

Since there is no function

Code: Select all

sim.followPath()
i cant just link my Dummy object with rectilinear path.
https://sun9-56.userapi.com/impg/1tIwQ0 ... type=album

I also know that there is an example for the robot following the path, i studied it and it uses the sensors to follow the path.

So the main question what`s the alternative function for

Code: Select all

sim.followPath()
? And how do i simply connect the object with the path?

fferri
Posts: 1297
Joined: 09 Sep 2013, 19:28

Re: Following Path function

Post by fferri »


chousuiri
Posts: 4
Joined: 26 Jun 2024, 09:28

Re: Following Path function

Post by chousuiri »

Cloudiness wrote: 05 Jul 2024, 11:16 Hello!
I saw that u have the same problem as mine so i wanted to ask u how did u solve your problem?

Since there is no function

Code: Select all

sim.followPath()
i cant just link my Dummy object with rectilinear path.
https://sun9-56.userapi.com/impg/1tIwQ0 ... type=album

I also know that there is an example for the robot following the path, i studied it and it uses the sensors to follow the path.

So the main question what`s the alternative function for

Code: Select all

sim.followPath()
? And how do i simply connect the object with the path?
Sorry for my late reply. Have you already solved the problem?

Anyway, here are some parts of my code in the base section.

Code: Select all

 function sysCall_init()
    sim = require('sim')
    FL_objectToFollowPath = sim.getObject('/FL_target')
    FL_path = sim.getObject('/FL_Path')
    FL_pathData = sim.unpackDoubleTable(sim.readCustomDataBlock(FL_path, 'PATH'),0,0,0)
    local m = Matrix(#FL_pathData // 7, 7, FL_pathData)
    FL_pathPositions = m:slice(1, 1, m:rows(), 3):data()
    FL_pathQuaternions = m:slice(1, 4, m:rows(), 7):data()
    FL_pathLengths, FL_totalLength = sim.getPathLengths(FL_pathPositions, 3)
    FL_velocity = 0.04 -- m/s
    FL_posAlongPath = 0
    FL_previousSimulationTime = 0
    sim.setStepping(true)
end
function sysCall_actuation()
    simIK.applyIkEnvironmentToScene(ikEnv,ikGroup)
end
function sysCall_thread()
    while not sim.getSimulationStopping() do
        -- FL
        local t = sim.getSimulationTime()
        FL_targetpos = sim.getObjectPosition(FL_simTarget,-1)[3]
        FL_posAlongPath = FL_posAlongPath + FL_velocity * (t - FL_previousSimulationTime)
        FL_posAlongPath = FL_posAlongPath % FL_totalLength
        local FL_pos = sim.getPathInterpolatedConfig(FL_pathPositions, FL_pathLengths, FL_posAlongPath)
        local FL_quat = sim.getPathInterpolatedConfig(FL_pathQuaternions, FL_pathLengths, FL_posAlongPath, nil, {2, 2, 2, 2})
        sim.setObjectPosition(FL_objectToFollowPath, FL_pos, FL_path)
        sim.setObjectQuaternion(FL_objectToFollowPath, FL_quat, FL_path)
        FL_previousSimulationTime = t
        sim.step()
    end
end
I hope it helps!

Post Reply