Follow the + star public account and never miss exciting content
Reprinted from | Uncle Wheat
Friends who have engaged in motor or motion control should know that the S-curve is very important. Compare the following animated picture and you will know the benefits of the S-curve:
![aa88eb5d9552fa51f23a231a6d85552d.gif](https://img-blog.csdnimg.cn/img_convert/aa88eb5d9552fa51f23a231a6d85552d.gif)
Today I will describe to you the S speed curve planning algorithm.
1 Introduction
The most important feature of S-shaped acceleration and deceleration is the shape of the algorithm's acceleration/deceleration curve like the letter S. The speed curve of S-shaped acceleration and deceleration is smooth, which can reduce the impact on the control process and make the interpolation process flexible [ ^1]. Since the T-shaped curve actually has a large overshoot during the switching process from acceleration to constant speed, here is a comparison between the actual process of the T -curve and the 7-segment S-curve ;
T shape : Accelerate->Constant speed->Decelerate
S shape : Acceleration ( ) -> Uniform acceleration ( ) -> Deceleration ( ) -> Uniform ( ) -> Acceleration ( ) -> Uniform deceleration ( ) -> Deceleration ( )
The above text description on acceleration may be a bit convoluted to read. See the picture below:
2 Theoretical analysis
Since the acceleration of the S-curve changes during acceleration and deceleration, a new variable is introduced here, namely jerk .
Therefore, in the 7-segment S speed curve corresponding to the above figure , the maximum acceleration is stipulated as and the minimum acceleration is , then the relationship between acceleration is;
Jerk (): gradually increases;
at this time
Uniform acceleration (): reaches the maximum;
at this time
Deceleration (): gradually decrease;
at this time
uniform (): no change;
at this time
Acceleration/Deceleration (): Gradually increase;
at this time
Uniform deceleration (): reaches the maximum;
at this time
Decrease (): gradually decrease;
at this time
“is the absolute value of acceleration; where
Therefore, it is usually necessary to determine the three most basic system parameters: the maximum speed of the system, the maximum acceleration a_{max}, and the jerk, and then the entire operation process can be determined [^2];
Maximum speed : reflects the maximum operating capability of the system;
Maximum acceleration : reflects the maximum acceleration and deceleration capability of the system;
Jerk : reflects the flexibility of the system;
The greater the flexibility, the greater the overshoot and the shorter the running time;
The smaller the flexibility, the smaller the overshoot, and the longer the running time;
2.1 Acceleration time relationship equation
The entire acceleration change process is specifically shown in the figure below;
![d939fbc4b3c4be6ef5d15e4ab2fe45b8.png](https://img-blog.csdnimg.cn/img_convert/d939fbc4b3c4be6ef5d15e4ab2fe45b8.png)
Again, emphasize the relationship between and, and introduce variables here,
①
For example, if the current moment is in the interval, then if it is used as the initial point, it is the time relative to the moment, then there is:
The relationship function between acceleration and time can be obtained as follows:
â‘¡
According to formula ①, substituting into formula ② we can get:
In the above formula;
2.2 Speed-time relationship equation
Speed and acceleration satisfy; the relationship between jerk and speed satisfies:
Combining the acceleration time relationship with equation ②, the velocity curve relationship can be obtained. The specific relationship is shown in the figure below;
further simplification can be obtained:
2.3 Displacement time relationship equation
Displacement and jerk directly satisfy the relationship as follows:
Simple derivation
So we can get:
“I have almost forgotten the points, so I will review them when I go back;
The equation for the final displacement is shown below;
3 Ideas for program implementation
As mentioned before, S-curve planning needs to determine the three most basic system parameters: system maximum speed, maximum acceleration a_{max}, and jerk, so that the operating process can be determined. There is an implicit condition here, that is, the maximum speed can be reached during operation. This is the complete 7-segment S curve . In addition, there are some intermediate parameters:
, so there is;
jerk;
;
, the user specifies the time required for the entire running process;
But usually in the actual process, we care about,,;
3.1 Derivation
The ideal state is assumed to existand , the derivation process is as follows:
So we can get:
After simplification we get:
According to formula ②, we can know:
Finally got:
“is the initial speed;
The following discretization program can be written based on the displacement-time relationship equation .
Assuming that the maximum speed can be reached and the user gives the entire process running time, the derivation of is as follows:
Simplifying the above formula we can get:
According to the above formula, we can get:
Derivation of 3.2
At this time, there is still a calculation that needs to be made, which can be deduced from the measurements; first, the displacements satisfy the following relationship:
where the length of the acceleration zone is; where the length of the deceleration zone is;
Specific derivation; [^2] As mentioned earlier, so when =0, then
â‘£
Here is a simple deduction:
⑤
According to ④, ⑤ is finally simplified to :
“: is the total running time: is the total running distance
The detailed derivation process is as follows:
because:
because:
So, simplifying it gives:
So you can get:
because:
Substituting this in we get:
Simplify to get the final result :
4 matlab programs
The matlab program can be run after personal testing with simple modifications. Because the time of the entire running process is directly given here, the SCurvePara
value of acceleration needs to be found in the function, and the distance is 1:
SCurvePara
function [Tf1,V,A,J,T] = SCurvePara(Tf, v, a)
T = zeros(1,7);
for i=1:1000
% 加加速度 J
J = (a^2 * v) / (Tf*v*a - v^2 - a);
% Tk
T(1) = a / J;
T(2) = v / a - a / J; % t2 = v / a - t1;
T(3) = T(1);
T(4) = Tf - 2 * a / J - 2 * v / a; % t4 = Tf - 4*t1 - 2*t2;
T(5) = T(3);
T(6) = T(2);
T(7) = T(1);
% 根据T2和T4判断S曲线的类型
if T(2) < -1e-6
a = sqrt(v*J);
display('t2<0');
elseif T(4) < -1e-6
v = Tf*a/2 - a*a/J;
display('t4<0');
elseif J < -1e-6
Tf = (v^2 + a) / (v*a) + 1e-1;
display('J<0');
else
break;
end
end
A = a;
V = v;
Tf1 = Tf;
end
SCurveScaling
function s = SCurveScaling(t,V,A,J,T,Tf)
% J = (A^2 * V) / (Tf*V*A - V^2 - A);
% T(1) = A / J;
% T(2) = V / A - A / J; % T(2) = V / A - T(1);
% T(3) = T(1);
% T(4) = Tf - 2 * A / J - 2 * V / A; % T(4) = Tf - 4*T(1) - 2*T(2);
% T(5) = T(3);
% T(6) = T(2);
% T(7) = T(1);
%%
if (t >= 0 && t <= T(1))
s = 1/6 * J * t^3;
elseif ( t > T(1) && t <= T(1)+T(2) )
dt = t - T(1);
s = 1/2 * A * dt^2 + A^2/(2*J) * dt...
+ A^3/(6*J^2);
elseif ( t > T(1)+T(2) && t <= T(1)+T(2)+T(3) )
dt = t - T(1) - T(2);
s = -1/6*J*dt^3 + 1/2*A*dt^2 + (A*T(2) + A^2/(2*J))*dt ...
+ 1/2*A*T(2)^2 + A^2/(2*J)*T(2) + A^3/(6*J^2);
elseif ( t > T(1)+T(2)+T(3) && t <= T(1)+T(2)+T(3)+T(4) )
dt = t - T(1) - T(2) - T(3);
s = V*dt ...
+ (-1/6*J*T(3)^3) + 1/2*A*T(3)^2 + (A*T(2) + A^2/(2*J))*T(3) + 1/2*A*T(2)^2 + A^2/(2*J)*T(2) + A^3/(6*J^2);
elseif ( t > T(1)+T(2)+T(3)+T(4) && t <= T(1)+T(2)+T(3)+T(4)+T(5) )
t_temp = Tf - t;
dt = t_temp - T(1) - T(2);
s = -1/6*J*dt^3 + 1/2*A*dt^2 + (A*T(2) + A^2/(2*J))*dt ...
+ 1/2*A*T(2)^2 + A^2/(2*J)*T(2) + A^3/(6*J^2);
s = 1 - s;
elseif ( t > T(1)+T(2)+T(3)+T(4)+T(5) && t <= T(1)+T(2)+T(3)+T(4)+T(5)+T(6) )
t_temp = Tf - t;
dt = t_temp - T(1);
s = 1/2 * A * dt^2 + A^2/(2*J) * dt + A^3/(6*J^2);
s = 1 - s;
elseif ( t > T(1)+T(2)+T(3)+T(4)+T(5)+T(6) && t <= T(1)+T(2)+T(3)+T(4)+T(5)+T(6)+T(7) + 1e5 )
t_temp = Tf - t;
s = 1/6 * J * t_temp^3;
s = 1 - s;
end
end
The code for the test is as follows:TEST
%%
N = 500;
ThetaStart = 0; %起始位置
ThetaEnd = 90; %最终位置
VTheta = 90; %1 速度
ATheta = 135; %1.5 加速度
Tf = 1.8; % 总行程时间
v = VTheta/(ThetaEnd - ThetaStart);
a = ATheta/(ThetaEnd - ThetaStart);
v = abs(v);
a = abs(a);
Theta = zeros(1,N);
s = zeros(1,N);
sd = zeros(1,N);
sdd = zeros(1,N);
[TF,V,A,J,T] = SCurvePara(Tf, v, a);
display(J, 'J:');
display(TF,'Tf:');
display(V,'v:');
display(A, 'da:');
display(TF-Tf,'dTf:');
display(V-v,'dv:');
display(A-a, 'da:');
t=linspace(0,TF,N);
dt = t(2) - t(1);
for i = 1:N
if i == N
a = a;
end
s(i) = SCurveScaling(t(i),V,A,J,T,TF);
Theta(i) = ThetaStart + s(i) * (ThetaEnd - ThetaStart);
if i>1
sd(i-1) = (s(i) - s(i-1)) / dt;
end
if i>2
sdd(i-2) = (sd(i-1) - sd(i-2)) / dt;
end
end
subplot(3,1,1);
legend('Theta');
xlabel('t');
subplot(3,1,1);
plot(t,s)
legend('位移');
xlabel('t');
title('位置曲线');
subplot(3,1,2);
plot(t,sd);
legend('速度');
xlabel('t');
title('速度曲线');
subplot(3,1,3);
plot(t,sdd);
legend('加速度');
xlabel('t');
title('加速度曲线');
See that the final simulation results are the same as expected;
Finally, let’s take a look at the comparison of the effects of T-shaped and S-shaped speed curve planning:
5 Summary
This article only gives a detailed derivation and introduction to the 7-segment S-curve planning. The programs in matlab are implemented for both 4-segment and 5-segment. Many of them are deduced under ideal conditions. The initial speed defaults to 0 and the terminal speed It is also 0, and it is assumed that the acceleration and deceleration areas are symmetrical to each other. The final running result is in line with expectations.
6 Reference
[1]: Chen Youdong, Wei Hongxing, Wang Qikui. Linear and S-shaped acceleration and deceleration discrete algorithms for CNC systems [D]. Beijing: China Mechanical Engineering, 2010. [2]: Guo Xingui, Li Congxin, Research on S-curve acceleration and deceleration algorithm, Shanghai Jiao Tong
University National Mold CAD Engineering Research Center, 200030
------------ END ------------
●Column "Embedded Development"
●Embedded column selected tutorials
Follow the official account and reply " Add Group " to join the technical exchange group according to the rules, and reply " 1024 " to view more content.
Click " Read the original text " to view more sharing.