Summary of motor motion control algorithm

Follow the + star public account and never miss exciting content

01773e5cd7e12b9a2d135e7321d25d01.gif

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

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:
c72b40a7942b9f8dd0f4e536c853ecc1.png

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

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;
8a7f2a2474b162a73f325b45096da13c.png
further simplification can be obtained:
13b15374eba38bbde4dc9fdb27688d59.png

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;
e2de0e258f396f35770b1731d4b84105.png

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 SCurveParavalue 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;6c89c80d75fbcd55c17edae9cb26a238.jpeg

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 ------------

f64f38b0a33cb761097c196473ef91f1.gif

●Column "Embedded Tools "

●Column "Embedded Development"

●Column "Keil Tutorial"

●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.

bb2cd42857e58c7942a7483f9013bdf7.jpeg

b2b57a90d06581841ef7bf4a20a57e12.png

Click " Read the original text " to view more sharing.

Guess you like

Origin blog.csdn.net/ybhuangfugui/article/details/132893206