Linear Interpolation algorithm:
 

Let suppose:

    that the step displacement value is identical on Y and X axis,

    that motors and driving screws are identical on both X and Y axis,

So in this case, the algorithm is:
    Read coordinates from starting point A (Xa,Ya).

    Read coordinates from next destination point B (Xb,Yb).

    Calculate the distance and derive the time TPS required to go from starting point to detination point (speed is a known constant) .

    Calculation for first step:

      If m > 2 then 1 Y step

      Ifi m >= 0.5 and m <= 2 then 1 X+Y step 

      If m < 0.5 then 1 X step


    Once the line is noticed, we can imagine the displacement from the preceeding point, then recalculate a new slope from this new point. A *nd so on up to reaching the destination (B).
     

      If ref_slope >=1 then
        if m > ref_slope  then 1 Y step

        If m <= ref_slope then 1 X+Y step

      If ref_slope <1 then
        If  m >= ref_slope then 1 X+Y step

        If  m < ref_slope then 1 X step
        For each step, we count the number of X alone steps and Y alone steps (N1), together with the number of simultaneous X+Y steps (N2). The time elapsed for each step (t), is derived from the relation 
        TPS = N1*t + (N2*t*1.414)   (1.414  =  square root of 2)... so finally t = TPS/(N1+N2*1.414).

     
    Once destination point B has been reached, this point become the next starting point and the next point is read: the next destination and the alogrithm resume as before.
     

    With same hypothesis

    If ref_slope =1
      we proceed with  (Xb-Xa) steps in  X + Y
    If ref_slope < 1
      m = ((Xb-Xa) mod (Yb-Ya))

      Repeat (Yb-Ya) times
      {
          (1/(ref_slope) div 2) X steps
          1  X+Y step
          1/(pente ref) -1 - (1/(pente ref) div 2) X steps
          si (m >0)
          {
          do1 X step;
          m= m-1
          }
      }

    Si pente ref > 1
      m = ((Xb-Xa) mod (Yb-Ya))

      repeat (Xb-Xa) times
      {
          (ref_slope div 2) Y steps
          1 X+Y step
          pente ref -1 - (pente ref div 2) Y steps
          si (m >0)
          {
          do 1 X step;
          m= m-1
          }
      }

With these two methods, this types of trajectory are obtained:
 
traject.gif (3351 octets)
Starting point A(0,0)

Destination B(27,3)

ref_slope = 3/27 = 0.111 

->X displacement (with respect to this first point B coordinates are (26,3))

m = 3/26 = 0.115 -> Simultaneous displacement over X and Y axis ( B(25,2))

m = 2/25 = 0.08 -> X step ( B(24,2))

and so on...

m = 0 (Not a good example! nothing remains..... But It works also)

Do 3 times

9 / 2 = 4.5 -> 4  X steps

1 X+Y step

9 - 1 - 4 = 4 X steps

...

Do not forget that for a 48 steps per revolution motor, and a 6 mm driving screw (ISO, 1mm pitch), then 1 motor step move the wire slightly more than 2/100 mm (0.0208mm), which is a fairly good precision compared to the approximation induced by effects like the wire kerf....
 


Return