I spent a couple hours simulating methods to do
acceleration/deceleration yesterday, and I'm pretty close. I've
had almost success by linearly adjusting the time delay between
steps downward to accelerate and upwards to decelerate. I've
written code in matlab to simulate and here's the results for
moving to 7,20 from 0,0
The top two graphs are x and y vs time, and you can see the
acceleration and deceleration. the bottom graph is the position
in x,y and it matches the expected slope perfectly. there are a
few more issues to work out, but as it stands, it should be easy
to integrate. It will be able to have an adjustable accel
duration, decel duration. Code below if anyone wants to play
with it..
-reza
clear;
maxSpeed = 15;
stepsPerInch = 460;
start = [0 0 0];
finish= [7 20 0];
vector = finish - start;
steps = vector .* stepsPerInch;
location = start;
distance = sqrt( sum( vector.^2) );
duration = distance / maxSpeed;
timePerStep = duration ./ steps;
incTime = timePerStep;
accelTime=1;
decelTime=1;
s=9917
inclog = zeros(s,1);
t=zeros(s,1);
locx=zeros(s,1);
locy=zeros(s,1);
locz=zeros(s,1);
c=10;
scale=3/4;
finished = duration+accelTime*(scale)+decelTime*scale;
i=0;
for time=0:.0000001:finished
for index=1:3
if (steps(index)>0)
if (time > incTime(index))
i=i+1;
if (time < accelTime)
inc = timePerStep(index) *
(c-(c-1)*time/accelTime);
elseif (time > finished-decelTime)
inc = timePerStep(index) *
(1+(c-1)*(time-finished+decelTime)/decelTime);
else
inc = timePerStep(index);
end
if (index==1)
inclog(i) = inc;
end
steps(index) = steps(index) - 1;
location(index) = location(index) +
(1/stepsPerInch);
incTime(index) = time + inc;
t(i)=time;
locx(i) = location(1);
locy(i) = location(2);
locz(i) = location(3);
end
end
end
end
%%
subplot(2,2,1)
plot(t,locx);
%axis([0 1 0 2.75])
title('X Axis vs. Time')
subplot(2,2,2);
plot(t,locy);
%axis([1 1.5 2.6 9])
title('Y Axis vs. Time')
slope = finish(2)/finish(1);
y=slope*locx;
err=abs(locy-y);
subplot(2,1,2);
plot(locx,locy,locx,err,'r',locx,y);
title('X Axis vs. Y Axis')