Linear interpolation
As I researched about my own custom G-Code interpreter on the Arduino I realised that it was neccesary to interpolate between two points in space. Thats because when both stepper motors step at the same time at the exact same speed a target value is reached too soon when one coordinate is not equal to the other ( x != y).
To avoid that problem one has to interpolate between the points and check if the interpolated value has to in- or decrement. I came up with this function to return an interpolated coordinate on the vector between the points:
1 2 3 4 5 6 7 8 9 10 11 |
long linearInterpolate(long a1, long b1, long a2, long b2, long C1) { long _C2 = 0; if(a1 == a2) { _C2 = b2; } else { _C2 = b1 + ((C1-a1)*b2 - (C1-a1)*b1)/(a2-a1); } return _C2; } |
Some reference and further reading on that topic here!