You are on page 1of 2

//save as .

odt file and use it with arduino #const min_step= // to be determined on the device

x(t)=t^2+2t; y(t)=t^3; // t goes from a to b // in n steps

dt=(b-a)/n; for(t=a;t<b;t+=dt) { //calculating net change dx=x(t+dt)-x(t)+dx1; dy=y(t+dt)-y(t)+dy1; x_steps=floor(dx/min_step); y_steps=floor(dy/min_step); if(abs(dx)>min_step || abs(dy)> min_step) { if(x_steps==0) { for(y_curr_steps=0; abs(y_curr_steps)<abs(y_steps); y_curr_steps+=sgn(y_steps) ) steppery(sgn(y_steps)); } elseif(y_steps==0) { for(x_curr_steps=0; abs(x_curr_steps)<abs(x_steps); x_curr_steps+=sgn(x_steps) ) stepperx(sgn(x_steps)); } elseif(abs(x_steps)>=abs(y_steps)) { ratio=x_steps/y_steps; for(x_curr_steps=0; abs(x_curr_steps)<abs(x_steps);) { stepperx(sgn(x_steps)); x_curr_steps+=sgn(x_steps); if(abs(x_curr_steps)>abs(ratio*y_curr_steps)) { steppery(sgn(y_steps)); y_curr_steps+=sgn(y_steps); } } } elseif(abs(y_steps)>abs(x_steps)) { ratio=y_steps/x_steps; for(y_curr_steps=0; abs(y_curr_steps)<abs(y_steps);) { steppery(sgn(y_steps)); y_curr_steps+=sgn(y_steps); if(abs(y_curr_steps)>abs(ratio*x_curr_steps)) { stepperx(sgn(x_steps));

//dx1 is the accumulated change i.e change that was not executed because it was too small //dy1 ditto

x_curr_steps+=sgn(x_steps); } } } } dx1=dx-x_steps*min_step; dy1=dy-y_steps*min_step; } // calculating accumulation

You might also like