Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data handling
#1
I have the following data handling problem:
In making a machine controller the machine movements are controlled by "G Code". A typical G code would be:
G3 X.234 Y.237 I1.008 J2.2195 Z.291 F36:
In handling the data we derive 13 different numbers from the above code. In order to make the machine operate smoothly we do something called Lookahead wherein we preview the succeeding 20 codes, getting the 13 different numbers from each.
All this data is put in an array of 13 x 20. Now when the machine is being run, the data is taken from the first group and as many following groups as needed. After the first group is run, I Re-number the following groups as:

FOR w = 1 to 20
xx(w) = XX(w + 1) 'X value, #1
yy(w) = yy(w + 1)
zz(w) = zz(w + 1)
ii(w) = ii(w + 1)
"
"
aa(w) = aa(w + 1) 'Arc value, #13
NEXT w

As you can see, the data from the first group is now lost. Now new data is added so that there are 20 groups of data stored.

So the data is being shifted back one place each time old data is used (removed) and new data is added.

My question is this: "Is there a better way of handling the data so that I don't have to renumber it and thus can SAVE THE TIME lost in the renumbering?" There may be many thousand blocks of data in a program, and I don't want to save 13 sets on info for each.

I hope this is clear enough; if not , maybe I can expand on it.
Regards,
Jack C.
Reply
#2
Use a queue: an array with one index to reading point and another to writing point. When they arrive at the end of the array are wrapped to the top.

Code:
DEFINT A-Z
'suppose an array of 20 values
CONST arraysize = 20
DIM a(arraysize)
CLS
readindx = 0        'initialize the two indexes  
writeindx = 0
t = 1               'only for demo
ended = 0

'main loop
DO
  'writing loop
  DO
    'if end of data set dataended flag and exit write loop
    IF t > 400 THEN dataended = -1: EXIT DO

   'increase write pointer and wrap it if end of array
    writeindx = writeindx + 1
    IF writeindx > arraysize THEN writeindx = 0
  
    'write next data block into array (t emulates a file pointer)
    a(writeindx) = t
    t = t + 1

  'stop writing if we reach write index
  LOOP UNTIL readindx = writeindx

  'executing loop
  DO
    'incease read pointer and wrap it if end of array
    readindx = readindx + 1
    IF readindx > arraysize THEN readindx = 0
  
    'pass a line of data to your machine. In this demo we just print
    PRINT a(readindx);
  
    'if we reach write index and data ended, quit
    IF dataended AND readindx = writeindx THEN END

  'stop reading if we reach write index
  LOOP UNTIL readindx = writeindx
LOOP
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)