I am trying to show a trajectory and 2 other effected trajectories in coppeliasim. Therefore I want to just draw lines connecting the points inside of each of these trajectories. The 3 trajectories are stored in text files with each row having the points x,y and z coordinates.
function readCSV(filename)
local data = {} -- Initialize the vector of vectors
file = io.open(filename, "r") -- Open the file in read mode
if not file then
print("Error opening file: " .. filename)
return nil
end
-- Iterate through the lines of the file
for line in file:lines() do
-- Use string.gmatch to iterate through elements separated by ","
for element in string.gmatch(line, "([^,]+)") do
table.insert(data, tonumber(element)) -- Assuming the elements are numbers, convert and add to the table
end
end
file:close() -- Close the file
return data
end
function sysCall_init()
-- do some initialization here
simRemoteApi.start(19999)
-- variables for lines
line_size = 5
Imu_trace = sim.addDrawingObject(sim.drawing_points, line_size, 0 ,-1, 1000, {0,0,0})
Tremor_trace = sim.addDrawingObject(sim.drawing_points, line_size, 0 ,-1, 1000, {1,0,0})
Suppression_trace = sim.addDrawingObject(sim.drawing_points, line_size, 0 ,-1, 1000, {0,0,1})
-- load and iterate through the text file positions
--load
file_name_imu_pos = "positions/end_effector_positions_0.txt"
file_name_tremor_pos = "positions/tremor_cause_positions_0.txt"
file_name_sup_pos = "positions/suppressed_positions_0.txt"
Imu_pos = readCSV(file_name_imu_pos)
tremor_pos = readCSV(file_name_tremor_pos)
sup_pos = readCSV(file_name_sup_pos)
sim.addDrawingObjectItem(Imu_trace, Imu_pos)
sim.addDrawingObjectItem(Tremor_trace, tremor_pos)
sim.addDrawingObjectItem(Suppression_trace, sup_pos)
-- move the arm to that position
end
function sysCall_actuation()
-- put your actuation code here
end
function sysCall_sensing()
-- put your sensing code here
end
function sysCall_cleanup()
-- do some clean-up here
end
The code runs without any issues and the the values are all accurately read into the data vector, but the lines are still not drawing. What is the issue and how to fix this?
Your code now looks good. Are you sure you have anything in Imu_pos, tremor_pos or sup_pos? Try printing those values with a simple print, and show us the output of those prints.