Inserting a path using x y coordinates

Typically: "How do I... ", "How can I... " questions
Post Reply
razer200033
Posts: 16
Joined: 27 Nov 2021, 19:41

Inserting a path using x y coordinates

Post 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!

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

Re: Inserting a path using x y coordinates

Post 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

razer200033
Posts: 16
Joined: 27 Nov 2021, 19:41

Re: Inserting a path using x y coordinates

Post 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!

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

Re: Inserting a path using x y coordinates

Post by fferri »

Each item is a pose (3 values for X/Y/Z position, 4 values for unit quaternion).

See for example sim.getObjectPose

razer200033
Posts: 16
Joined: 27 Nov 2021, 19:41

Re: Inserting a path using x y coordinates

Post 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?

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

Re: Inserting a path using x y coordinates

Post 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

Post Reply