generate path from a script and share it among functionss

Typically: "How do I... ", "How can I... " questions
Post Reply
anlyoung
Posts: 7
Joined: 19 May 2015, 18:44

generate path from a script and share it among functionss

Post by anlyoung »

I would like to generate path from two points from a child script to be followed by the robot via IK (i.e. tartget).
So I would make three functions (In a way this would be similar to sim.followPath()):
- makepath = function(pos1, pos2) -- this will generate a straight path between two points via pathHandle=sim.createPath, and insertPathCtrlPoints(pathHandle,2,0,2,{ptData1,ptData2}).
- setpath = function(object_to_move, path, vel) -- this will move the object (ikTip) along the path incrementally
- checkpath = function(object_to_move, path) -- this will check if it arrived the end end of the path

But I don't know a way to share the created 'path' to other functions in the sctipt.
Can you advise?

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

Re: generate path from a script and share it among functionss

Post by coppelia »

Hello,

I would advise against using a path object at first, since you will lose flexibility. If you need to generate a path, simply use a table containing path points or configurations, e.g.:

Code: Select all

local path={ {0,0}, {x,y} } -- e.g. a path with 2 points in the x/y space
Then you can easily manipulate that data structure, e.g. increase/reduce the number of points, or extract an interpolated point, etc. If you need to share the path with some other parts in a given script it is trivial. If you need to share it with another script, then you have several possibilities, e.g.:

Code: Select all

sim.setStringSignal("myData",sim.packTable(path))
-- In the other script, you can read that with:
local path=sim.getStringSignal('myData')
path=sim.unpackTable(path)

-- or in a similar way:
sim.writeCustomDataBlock(...)
--
sim.readCustomDataBlock(...)
or by simply calling a function in another script and passing the path as argument with sim.callScriptFunction.

Cheers

Post Reply