We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on a project and I need some help to get it started. I want to create a program that will parse text from a text file and create an arrayList of PVector points from the file.
Here is an example of the text I will use as input:
...
LOAD/TOOL,1240,ADJUST,1240
PAINT/COLOR,186
RAPID
GOTO/50.9361188,22.1399311,66.0000000,0.0000000,0.0000000,1.0000000
PAINT/COLOR,211
RAPID
GOTO/50.9361188,22.1399311,44.8782394
PAINT/COLOR,6
FEDRAT/IPM,50.0000000
GOTO/50.9361188,22.1399311,41.8782394 // First point
PAINT/COLOR,31
FEDRAT/100.000000 // This is an indicator line to start recording the following points
// I also want to use the point before the following as the first point
GOTO/135.032223,22.1399311,41.8782394
GOTO/135.643971,26.8821142,43.6767850
GOTO/135.655965,26.9743716,43.7117751
GOTO/135.668047,27.0666190,43.7467613
GOTO/135.681138,27.1656088,43.7843047
...
After I create the arrayList of 3D Vectors, I want to calculate the sum of the distances traveled from point to point in sequence.
There is a lot more I want to do with this after, but this will get me started.
Answers
I used one of the examples that came with Processing and came up with this so far:
Now I just need to put some logic in there somewhere to select only the points I want, then calculate the sum of the distances, which will be easy with the PVectors.
Any refinements or pointers are welcome.
first I recommend to check pointList
e.g. use
println (pointList.size());
if the number of items is correct approx.
then you can println a few items / PVectors to see if they are as expected
then to add up dist use a for-loop i to size()-1 (or -2 ?)
and say
then say
Greetings, Chrisir
why does line 5 have 6 arguments when all the other GOTOs have 3?
well spotted!
also, why use a for-loop in line 16 of the code?
Just say
Greetings, Chrisir
or
Just say
Greetings, Chrisir
@Chrisir Thanks for all the points! I will go through and do some refactoring. That's the fun part. I don't think a for-loop is necessary. I'll make some changes.
@koogs This is code that is used to generate G Code for machine programming. The first 3 numbers are for X, Y, and Z position of the tool tip. The last 3 are I, J, and K, which indicate the tool's orientation. With 0,0,1, as above, the tool is oriented straight down. This is necessary info for 5 axis mills. If the orientation of the tool doesn't change, then the IJK numbers are dropped until (or if) they change.