LAB 4 ENGI 38: ADVANCED CONTROLS -------------------------------------------------------------------- Lab Partners: (Alphabetically) Figliomeni, Dan Malyshev, Andrey McGrath, Adam TO: WARREN PAJU ELECTRICAL ENGINEERING DEPT. LAKEHEAD UNIVERSITY ATAC56 INVERTED PENDULUM
Table of Contents. OBJECTIVE... 3 2. APPARATUS... 3 3. PROCEDURE... 3 4. LAB PREP WORK... 3 4. POLE-PLACEMENT DESIGN... 4 4.2 LQR COMPENSATOR... 4 4.3 DIGITAL LQR COMPENSATOR... 5 5. THEORY... 5 6. OBSERVATIONS... 8 6. POLE-PLACEMENT... 8 6.2 LINEAR QUADRATIC REGULATOR... 9 6.3 DIGITAL CONTROLLER... 7. CONCLUSION... 2 APPENDIX A MATLAB file for pole placement and LQR... 3 APPENDIX B MATLAB file for digital LQR compensator design... 4 2
3. OBJECTIVE The purpose of this lab is to design compensators with error tracking integrator using state space methods to stabilize an inverted pendulum on a moving car 2. APPARATUS Inverted Pendulum set up 3. PROCEDURE The procedure is described in the Engineering 38 Advanced Controls II lab manual. 4. LAB PREP WORK The state space derivation of the inverted pendulum model is provided in the manual as follows: x y u x x = + = 3.335.824 4.673 3.46 36.98 3.628. (.) The output regulation with the integrator action modifies these matrices in order to have the position of the pendulum converge to a set parameter. The state-space representation becomes x y u x x = + = 3.335 8.24 4.673 3.46 36.98 3.628. (.2) This system can be used to design for 5 gain values. The fifth gain will represent the integrator gain K I =K 5.
4. POLE-PLACEMENT DESIGN Realistically, a settling time of 5.25 seconds and an overshoot of.95 percent is a good performance to design for. These parameters yield p =.76±.63,2 j These poles would represent the position and velocity of the cart. A set of faster poles can be chosen for the angle and angular velocity of the pendulum because we want them to converge faster than the cart position. In fact, the angular velocity should converge the fastest otherwise the system is unstable. Therefore, the angular velocity pole is placed far to the left. The integrator must converge fast, but if it converges too fast, the angular velocity will become an issue and the system will become unstable. Therefore, a compromise is necessary for the integrator pole that is fast converging and reasonable. In the end the following set of poles results..762+ j.626.762 j.626 p = 3.5 3.5 6 In light of the compromises made to achieve reasonable performance, the system became much slower. The simulated settling time exceeds 4 seconds and the pendulum experiences severe oscillations before achieving stability. The gains of the system are K K K K K K = [ 2 3 4 ] [ 69 4.6 5.3 9.7 6.84] = I 4.2 LQR COMPENSATOR The LQR controller offers a better solution to the inverted pendulum problem. For the design a few Q and R values were simulated. Reasonable performance was achieved for most of them but the better compromise for pole locations and gain values have been achieved with the following: Q =, R=.5 The obtained K vector was K = 49.43.8.8 K I [ 5.92] = 4.47 4
4.3 DIGITAL LQR COMPENSATOR A digital controller can be designed using the original state space representation defined by (.). The controller is simulated using the linear digital state space block in simulink. Good performance was achieved with the following set of parameters. 5 Q =, R=.5 5 The obtained K gain vector was K = 59.7 2.25 6.7 9.45 [ ] 5. THEORY The lab set up is depicted in figure. Figure : Stabilized inverted pendulum on a moving cart 5
The mathematical model of the system can be derived using the Newton balance of forces method acting on the inverted pendulum. Figure 2: Forces acting on the inverted pendulum The following set of non-linear equations describes the inverted pendulum system..... ( M + m) x+ mlθ cos( θ) mlθ sin( θ).... 2 ( I + ml ) θ mgl sin( θ) = mlx cos( θ). = F (2.) Where the force F acting on the cart can be described in terms of the input voltage to the motor as 2 2 K. gkm KgKm F = u x (2.2) 2 rr r R A A Substituting (2.2) into (2.) and rearranging for...ẋ θ and we obtain 2 2 K.... gkm KgKm u x mlθ cos( θ) + mlθ sin( θ).. 2 rra r RA x= M + m.. mgl sin θ = ( ) ( θ) mlx cos( θ).. 2 ( I + ml ) (2.3) This set of equations may be used to build the non-linear model of the system in MATLAB as shown in figure 3. This model is created into a subsystem and substituted into the control law model as shown in figure 4 to perform controller design simulations. 6
Figure 3: Non-linear model of the inverted pendulum Figure 4: Non-linear simulation of the inverted pendulum The saturation block in figure 4 limits the input voltage to ± 2V 7
6. OBSERVATIONS 6. POLE-PLACEMENT The simulated performance of the system is displayed in figures 5, 6 and 7. The simulation is performed according to the following criteria - Alpha disturbance of pi/2 occurs at t=sec and dissipates at t=.3sec - Position reference changes at t=sec Figure 5: Pole-Placement compensator angle simulation result Figure 6: Pole-Placement compensator position simulation result 8
Figure 7: Pole-Placement control effort simulation The pole-placement simulation indicates that the system is stable and all state variables gradually converge to zero. The actual system behaved similar to simulation. 6.2 LINEAR QUADRATIC REGULATOR The simulated performance of the system is displayed in figures 8, 9 and. The simulation is performed according to the following criteria - Alpha disturbance of pi/2 occurs at t=sec and dissipates at t=.3sec - Position reference changes at t=sec - Q =, R=. 5 9
Figure 8: LQR compensator angle simulation result Figure 9: LQR compensator position simulation result
Figure : LQR control effort simulation As seen in figures 8, 9, and all simulated state variables converge to zero well using the LQR compensator. Testing of the actual system confirmed simulation results. 6.3 DIGITAL CONTROLLER The digital controller was tested using a linear digital state-space representation of the inverted pendulum as shown in figure. Figure : Digital LQR compensator simulation The system simulated well and the position converges from initial conditions as shown in figure 2. The initial condition specified for the simulation was the angle of the pendulum with respect to the vertical axis of pi/2. The system converges in less than 2 seconds as seen in figure 2.
Figure 2: Position converging from initial conditions using LQR The digital LQR controller performed well on the actual system as expected. 7. CONCLUSION MATLAB is a powerful tool for designing control systems. In this experiment a pole placement, LQR and digital LQR compensators were implemented for the inverted pendulum. All controllers behaved as expected and the pendulum stabilized in the vertical position as expected. The true difficulty was in building the non-linear simulation model in MATLAB. This was a tough task due to complexity of differential equations. The pole-placement control was also difficult since only two poles can be designed for while the other three had to be guesstimated (sync). This was difficult because poleplacement utilizes a linear control to control a highly nonlinear system the inverted pendulum. Nonetheless, the experimental results were satisfactory. 2
APPENDIX A MATLAB file for pole placement and LQR clc; %clear everything %*****************************************************% % System Parameters % %*****************************************************% M=.455; %Kg m=.2; %Kg l=.35; %m r=.645; %m Kg=3.7; Km=.767; RA=2.6; %ohms g=9.8; %m/s^2 I=.65; %Kgm^2 A= [ ; 3.628 36.98 ; ; -3.46-4.673]; B= [; -8.24; ; 3.335]; Cbar= [ ; ]; %for isolating angle and position state variable readings C= [ ]; %used for controller design to control the cart position Anew=horzcat(vertcat(A,-C), zeros(5,)) %forming new A matrix for integrator feedback Bnew=vertcat(B, zeros(,)) %forming new B matrix for the same reasons %Obtaining user inputs for overshoot and settling time OS= input('enter overshoot in percentage form. For.9% enter.9\n') Ts= input('enter Settling time\n') temp= log(os)/(-pi); si= sqrt(temp/(+temp)); wn= 4/(Ts*si); % % adding 2 poles to second order char equn n= input('how far away (remember the -ve sign) e.g. -4\n'); pole= n*si*wn; fprintf('how far away do you want to push the integrator pole from the last two? ex. +2') e= input('enter +ve integer multiplier'); % now calculating the roots of the characteristic equation vector s^2+2*si*wn+wn^2 mainpoles=roots([ 2*si*wn wn^2]) %first two poles fastpoles=ones(2,)*pole %second two poles X=vertcat(fastpoles, mainpoles); %the combined result of four poles Y=[pole*e; X] %final set of 5 poles K_star= acker(anew, Bnew,Y) Kpole=[K_star(:,) K_star(:,2) K_star(:,3) K_star(:,4) ] %pole placement K vector Kipole=[K_star(:,5)] %pole placement Ki fprintf('these are the pole-placement gains!!! Change names in the model \n') Q= eye(5)*input('enter the Q multiplier') %defining Q matrix R= input('enter R for LQR\n') [Klqr,S,E]=lqr(Anew,Bnew,Q,R) K=[Klqr(:,) Klqr(:,2) Klqr(:,3) Klqr(:,4) ] %LQR K vector Ki=[Klqr(:,5)] %LQR Ki 3
APPENDIX B MATLAB file for digital LQR compensator design %38lab4 matlab m file for calculating digital LQR controller gains clc; %clear everything %*****************************************************% % System Parameters % %*****************************************************% % constants for the experiment M=.455; %Kg m=.2; %Kg l=.35; %m r=.645; %m Kg=3.7; Km=.767; RA=2.6; %ohms g=9.8; %m/s^2 I=.65; %Kgm^2 %*****************************************************% A= [ ; 3.628 36.98 ; ; -3.46-4.673]; B= [; -8.24; ; 3.335]; C= [ ]; D=zeros(,); %Obtaining the digital representation using zero-order hold method Ts= input('enter the sampling time Ts in seconds \n') [F,G,H,J] = c2dm (A,B,C,D,Ts,'zoh') %conversion from continuous to digital system fprintf('rank of controllability matrix is ') rank([g F*G]) Q=eye(4); %forming the q matrix Q(,)= input('enter the pendulum angle energy: '); Q(3,3)= input('enter the cart position energy: '); R= input('enter R\n') %R defined by the user [Kd, S, E]=lqrd(A,B,Q,R,Ts) %digital compensator design 4