電機的S加速、減速曲線,可以實現速度和加速度的平滑;
使用Sigmoid函數,
total = 1000;%脈衝數
max = 400;%間隔時間最大值
min = 100;%間隔時間最小值
step1_start = 0;
step1_end = fix(total/3.0);
step2_start = fix(total/3.0);
step2_end = fix(total/3.0) * 2;
step3_start = fix(total/3.0) * 2 + 1;
step3_end = total;
x1 = step1_start:0.01:step1_end;
y1 = 1./(1+exp(0.05*(x1-fix(step1_end/2)*ones(1,length(x1)))));
speed_avg = 1/(1+exp(0.2*(step1_end-fix(step1_end/2))));
x2 = step2_start:0.01:step2_end;
y2 = speed_avg * ones(1,length(x2));
x3 = step3_start:0.01:step3_end;
%y3 = 1./(1+exp(0.05*(fix(step1_end/2)*4*ones(1,length(x3))-x3)));
y3 = 1./(1+exp(-0.06*(x3 - 5*fix(step1_end/2)*ones(1,length(x3)))));
x = [x1,x2,x3];
y = [y1,y2,y3];
y = y .* (max - min) + min .* ones(1,length(y));
plot(x,y)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2019/11/11增加:
如果要在硬件上實現,有兩種方式,第一種是具有硬件pwm發生器的,相對比較方便;但我手中用的一塊物聯網芯片,沒有硬件pwm,所有隻能用GPIO來模擬,特別注意,脈衝發生器的代碼,運行過程中不能被其它線程或是任務中斷,否則會導致步進電機出現丟步的問題;