Page 1 of 1

Inserting a path using x y coordinates

Posted: 29 Nov 2021, 08:25
by razer200033
Hi!

I recently started using Coppeliasim for my final year project, I am new with it.
I need help regarding making the dummy follow a specific path using x y coordinates. I know about a method to import the coordinates from a csv file, and it worked, but I need help in generating a path using the data from that csv file. I used some of the codes I found on the forums here and there, but I keep getting the error: "createpath: argument 1 must be a table of elements of type float".
Can someone please help me with this issue?

Thanks in advance!

Re: Inserting a path using x y coordinates

Posted: 30 Nov 2021, 05:33
by coppelia
Hello,

here a simple example, creating a path with 4 control points located at (0,0,0),(1,0,0),(1,1,0),(0,1,0):

Code: Select all

    local ctrlPts={0,0,0,0,0,0,1,
                    1,0,0,0,0,0,1,
                    1,1,0,0,0,0,1,
                    0,1,0,0,0,0,1}
    sim.createPath(ctrlPts,0,100,0)
Cheers

Re: Inserting a path using x y coordinates

Posted: 30 Nov 2021, 06:26
by razer200033
Thanks a lot for your reply!

From what I understand, the first 6 elements of the coordinates are for the 6 direction movement. But I'm not too sure about the last ones.
Can you please elaborate the syntax about the 28 elements in the code?

Thanks!

Re: Inserting a path using x y coordinates

Posted: 30 Nov 2021, 08:36
by fferri
Each item is a pose (3 values for X/Y/Z position, 4 values for unit quaternion).

See for example sim.getObjectPose

Re: Inserting a path using x y coordinates

Posted: 16 Dec 2021, 06:47
by razer200033
Hi!

Thanks! Using this syntax, the path can be created now. But my original question, regarding how can I create a path using a csv file? I keep getting the error: "createpath: argument 1 must be a table of elements of type float", even though Coppelia reads the file and inputs it. How can this be solved to create the path now?

Re: Inserting a path using x y coordinates

Posted: 16 Dec 2021, 09:30
by fferri
Simply read the file line by line, split by comma, convert the values to numbers, and add those values to the path table.

E.g.:

Code: Select all

local path={}
for line in io.lines('path.csv') do
    for x in string.gmatch(line,'([^,]+)') do
        table.insert(path,tonumber(x))
    end
    if #path%7~=0 then error('incorrect number of columns in CSV') end
end