Modify path control point

Typically: "How do I... ", "How can I... " questions
Post Reply
Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

Modify path control point

Post by Justus »

Hi,

I have a situation where I need to continously (every sim step) adjust a path (simulation of a complex chain tensioning mechanism).
I can use sim.cutPathCtrlPoints and sim.insertPathCtrlPoints in combination with a table containing all path control point data. But is there are more elegant way to do this, for instance: sim.modifyPathCtrPoint?

Regards,
Justus

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

Re: Modify path control point

Post by coppelia »

Hello Justus,

unfortunately, as for now, there are only the two mentioned functions for that.

Cheers

Echo
Posts: 4
Joined: 06 Jun 2022, 14:43

Re: Modify path control point

Post by Echo »

I see now there is a function called resamplePath, can you tell more details about the method? and also the last input int[] of the function? I attached a new child script on the path. But it seems that it's not inserting more control points at the Path. Below is the code I attached to the Path.
  • function sysCall_init()
    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()
    pathLengths,totalLength=sim.getPathLengths(pathPositions,3)
    end

    function sysCall_actuation()
    -- put your actuation code here
    sim.resamplePath(pathPositions,pathLengths,50,
    {type='linear',strength=1.0,forceOpen=false},nil)
    end

    function sysCall_sensing()
    -- put your sensing code here
    end

    function sysCall_cleanup()
    -- do some clean-up here
    end

    -- See the user manual or the available code snippets for additional callback functions and details

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

Re: Modify path control point

Post by coppelia »

A path is an object mainly meant to be modified via the GUI, not programmatically.
If you need to programmatically generate and modify a path, then don't use a path object, but simply a path data structure. You can then manipulate that data very easily via path related API functions (in that list, only the first function generates a path object, the other functions operate on a path data structure).

To visualize a path data structure, you can either generate a path from it with sim.createPath, or you can display it in a flexible way via a drawing object (sim.addDrawingObject and sim.addDrawingObjectItem), e.g.:

Code: Select all

function sysCall_init()
    myPathData={0.0,0.0,0.2,
                0.5,0.0,0.2,
                0.5,0.5,0.2,
                0.0,0.5,0.2,
                0.0,0.0,0.2}
    displayPath(myPathData,{1,0,0})
end

function displayPath(path,color)
    if drawingObject then
        sim.removeDrawingObject(drawingObject)
    end
    drawingObject=sim.addDrawingObject(sim.drawing_linestrip,2,0,-1,0,color)
    for i=0,#path//3-1,1 do
        sim.addDrawingObjectItem(drawingObject,{path[3*i+1],path[3*i+2],path[3*i+3]})
    end
end
Cheers

Echo
Posts: 4
Joined: 06 Jun 2022, 14:43

Re: Modify path control point

Post by Echo »

So if I want to generate a path(eg. for some navigation problem) I should put these code inside the Robot attached script?

But if I just want to structure some fixed path, where should I place the script? For now the Path object I have is added by [Add->Path->closed] and the shape of the path is changed by manually changing the position and orientation of each control point.

If I still want the path to have the same structure but with more control points(so that the trajectory tracking will be more smooth and I don't need to modify the orientation for each control point), what I can do is copy the data of the current path and using a script(I don't know where to place this script) to generate a new path?

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

Re: Modify path control point

Post by coppelia »

Yes, you can do that. You can generate a path object, then extract its data with:

Code: Select all

    path=sim.getObject('/Path')
    pathData=sim.unpackDoubleTable(sim.readCustomDataBlock(path,'PATH'))
pathData is a succession of poses (x,y,z,qx,qy,qz,qz). If you want the poses of the control points only, do:

Code: Select all

    path=sim.getObject('/Path')
    pathData=sim.unpackDoubleTable(sim.readCustomDataBlock(path,'PATHCTRLPTS'))
From there, you can manipulate the path data as you wish. E.g. you can split position and orientation data, with:

Code: Select all

    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()
Have a look at the demo scene in scenes/movingAlongAPath.ttt that illustrates this in many different ways.

Cheers

Post Reply