The dynamic simulation of the m first-order inverted pendulum and the matlab simulation of the zero-pole configuration controller

Directory

1. Algorithm simulation effect

2. Algorithms involve an overview of theoretical knowledge

3. MATLAB core program

4. Complete algorithm code file


1. Algorithm simulation effect

The matlab2022a simulation results are as follows:

2. Summary of theoretical knowledge involved in algorithms

The inverted pendulum is a strongly nonlinear system with open-loop instability. Its control strategy is similar to the skills of acrobats performing a balancing act on a pole. The purpose is to make the pendulum in a critical stable state. It is a typical experimental platform for control theory research. . In the 1950s, cybernetic experts at the Massachusetts Institute of Technology designed the first set of inverted pendulum experimental equipment based on the principle of rocket boosters, and started the initial related research work. There are many types of inverted pendulums, which can be divided into linear inverted pendulum, circular inverted pendulum, and plane inverted pendulum according to their structure. .

The inverted pendulum system is an unstable system with high-order, unstable, multivariable, nonlinear and strong coupling characteristics. In the control process, in order to simplify the analysis of the linear one-stage inverted pendulum system, in the process of establishing the actual mathematical model, after ignoring the air resistance and various frictions, the linear one-stage inverted pendulum system is directly abstracted into a car and a uniform rod. system, as shown in Figure 1.

M Carriage mass

m Pendulum mass

b Carriage coefficient of friction

l The length from the center of rotation of the swing rod to the center of mass of the rod

I Inertia of pendulum

F is the force on the trolley

x car position

The angle between the pendulum and the vertical upward direction

Angle between the pendulum and the vertical downward direction (considering that the initial position of the pendulum is vertically downward)

Among them, N–the horizontal component of the interaction force between the trolley and the pendulum,

P–the vertical component of the interaction force between the trolley and the pendulum.

The following is the application of Newton’s method to establish the dynamic equation process of the straight-line inverted pendulum system:

Through force analysis, it can be seen that the resultant force on the trolley in the horizontal direction can be obtained as follows:

M*d2x/dt2=F –b*dx/dt- N (1)?

From the resultant force acting on the pendulum in the horizontal direction, the following equation can be obtained:

N=m*d2/dt2(x + lsin)

Namely: N=m*d2x/dt2 + m*l*d2/ dt2*cos- m* l* d2/ dt2*sin (2)

Put formula (2) into formula (1), then get the first motion equation of the system:

(M + m)*d2x/dt2 + b*dx/dt + m*l*d2/ dt2*cos- m* l* d2/ dt2*sin=F (3)?

Analyzing the resultant force in the vertical direction of the pendulum, the following equation can be obtained:

P-mg=m*d2 (l cos)/dt2?

Namely: P-mg=-m*l*(d/dt)2*cos- m*l*d2/ dt2*sin (4)

The moment balance equation of the system is as follows:

-P*l* sin-N*l *cos=I* d2/dt2 (5)

Combining formula (4) and formula (5), eliminating P and N, the second motion equation of the system is obtained:

(I + ml2) d2/dt2 + mgl sin=-ml d2x/dt2 cos (6)

Since =π + , cos=- cos, sin=- sin, so from formula (3) and formula (6) can get

The mathematical model of the system is the following equations:

(M + m)d2x/dt2 + b*dx/dt- m*l*d2/ dt2*cos + m* l* d2/ dt2*sin=F (7)?

(I + ml2) d2/dt2 + mgl sin=-ml d2x/dt2 cos

It is known from equation group (7) that the system is an obvious nonlinear system. In order to facilitate the design of the controller, the system needs to be linearized at the operating point (= 0). When the ratio of the angle between the pendulum and the vertical upward direction to 1 (in radians) is small, an approximation can be made:

cos=-1, sin=-, (d/dt)2=0. Use u to represent the input force F of the controlled object, and the mathematical model of the system becomes the following differential equation expression after linearization:

(I + ml2) d2/dt2 + mgl sin=-ml d2x/dt2 (8)

(M + m)*d2x/dt2 + b*dx/dt- m*l* m*l*d2/ dt2=u (8)

1. System transfer function model:

3.MATLAB core program

................................................ .........

for i=1:TT
    z1 =(A-B*Ks)*(z-zf);
    z = z + z1*dt;
    y(:,i) = z;
    
    % animation
    x1 = z(3)-k/2 + z(4)*dt*i; x2=z(3) + k/2 + z(4)*dt*i;
    y1 = -4;
    y2 =-2.5;
    x4 =(x1 + x2)/2 + l*sin(z(1));
    y4 = y2 + l*cos(z(1));
    
    t = 0:pi/100:2*pi;
    
    % A sphere on an inverted pendulum
    x3 = x4 + r*cos(t);
    y3 = y4 + r*sin(t);
    axes(handles.axes1);
    plot(x3,y3,'ro',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','r',...
    'MarkerFaceColor',[0.9,0.9,0.0]);
    hold on
    %track
    plot([-40,40],[-4,-4],'k','linewidth',20);
    hold on
    %Simulation car
    plot([x1,x2],[y1,y1],'b','linewidth',2);
    hold on
    plot([x2,x2],[y1,y2],'b','linewidth',2);
    hold on
    plot([x1,x2],[y2,y2],'b','linewidth',2);
    hold on
    plot([x1,x1],[y1,y2],'b','linewidth',2);
    hold on
    %Inverted pendulum
    plot([(x1 + x2)/2,x4],[y2,y4],'g','linewidth',3);
    hold off

    xlabel('car displacement');
    ylabel('height');
    axis([-30 30 -5 15])
    Y = [Y,(x1 + x2)/2];
    axes(handles.axes2);
    plot(Y,'r','linewidth',2);
    axis([0,TT,-15,15]);
    xlabel('time');
    ylabel('car displacement');
    pause(0.001);
    if (i==1)
        pause(0.01);
    end
    if (abs(z(1)-zf(1))<=0.001) &(abs(z(3)-zf(3))<=0.002)
        break;
    end
end



% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%parameter
global R1;
global I1;
global R2;
global I2;
global R3;
global I3;
global R4;
global I4;
global M;
global k;
global V;
global dt;
global l;
global TT;
CC1 = R1 + sqrt(-1)*I1;
CC2 = R2 + sqrt(-1)*I2;
CC3 = R3 + sqrt(-1)*I3;
CC4 = R4 + sqrt(-1)*I4;

fid = fopen('dual-mass swing system virtual test software test report.txt','wt');

fprintf(fid,'Test parameters: \\
');
 
fprintf(fid,'01, car width: ');fprintf(fid,'%2.2f\\
',k);
fprintf(fid,'02, car speed: ');fprintf(fid,'%2.2f\\
',V);
fprintf(fid,'03, inverted pendulum length:');fprintf(fid,'%2.2f\\
',l);
fprintf(fid,'04, ball quality: ');fprintf(fid,'%2.2f\\
',M);
if I1 > 0
fprintf(fid,'05, zero-pole configuration:');fprintf(fid,'%2.2f',R1); fprintf(fid,' + i*'); fprintf(fid,' %2.2f\\
',abs(I1));
else
fprintf(fid,'05, zero-pole configuration:');fprintf(fid,'%2.2f',R1); fprintf(fid,'-i*'); fprintf(fid,' %2.2f\\
',abs(I1));
end
if I2 > 0
fprintf(fid,' ');fprintf(fid,'%2.2f',R2); fprintf(fid,' + i*'); fprintf(fid,'%2.2f\\
 ',abs(I2));
else
fprintf(fid,' ');fprintf(fid,'%2.2f',R2); fprintf(fid,'-i*'); fprintf(fid,'%2.2f\\
 ',abs(I2));
end
if I3 > 0
fprintf(fid,' ');fprintf(fid,'%2.2f',R3); fprintf(fid,' + i*'); fprintf(fid,'%2.2f\\
 ',abs(I3));
else
fprintf(fid,' ');fprintf(fid,'%2.2f',R3); fprintf(fid,'-i*'); fprintf(fid,'%2.2f\\
 ',abs(I3));
end
if I4 > 0
fprintf(fid,' ');fprintf(fid,'%2.2f',R4); fprintf(fid,' + i*'); fprintf(fid,'%2.2f\\
 ',abs(I4));
else
fprintf(fid,' ');fprintf(fid,'%2.2f',R4); fprintf(fid,'-i*'); fprintf(fid,'%2.2f\\
 ',abs(I4));
end
fprintf(fid,'06, simulation time: ');fprintf(fid,'%2.2f\\
\\
',TT);


fprintf(fid,'test result: \\
');

fclose(fid);
08_045_m

4. Complete algorithm code file

V