logo
  • userLoginStatus

Welcome

Our website is made possible by displaying online advertisements to our visitors.
Please disable your ad blocker to continue.

Current View

Mechanical Engineering - Control and Actuating Devices for Mechanical Systems

Collections of notes for the oral exam - Matlab

Collections of notes, exercises or exams

1 REQUEST AND NOTES FOR THE ORAL EXAM NOTES: - Report for the exam: can be done in team (3/4 people) REQUESTS: • LAB1: Consider a proportional control ( P controller ) with the data given during the lesson and plot the diagrams for the 3 cases: - A value of Kp which gives k* > 0 - A value of Kp which gives k* = 0 - A value of Kp which gives k* < 0 Modify the program to consider a PD and a PI controller (just for one of the 3 cases of K* at your choice) • LAB2: 2 LAB 1 % Always write initial commands to close al clear all clear all close all clc % SYSTEM DATA m = 3; L = 4; J = 1/12*m*L^2; k = 150; c = 10; g = 9.81; % EQUIVALENT PARAMETERS OF THE SYSTEM mx = J+m*L^2/4 cx = c*L^2/4 kx = k*L^2/4 - m*g*L/2 if kx>0 disp( 'Natural frequency of the undamped system [rad/s]:' ) omega_n = sqrt(kx/mx) end % STATE SPACE FORM % we compute the state space form of the system in order to study % stability through the eignevalues P = [m 0; 0 1]; Q = [cx kx; - 1 0]; N = [1;0]; % we compute state matrix computed as the inverse of P times Q and % than we can compute its eigenvalues A = - inv(P)*Q B = inv(P)*N lambda = eig(A) % function eing: with one putput gives the eigenvalues and with 2 % outputs gives also the eigenvectors % for example [eigvect, eigval]=eig(A) 3 % EXAMPLE: P CONTROLLER % same procedure as before can be used to compute the eigenvalues % of the controlled system kp = 100; if kx+kp>0 disp ( 'Natural frequency of the controlled undamped system [rad/s]:' ) omega_nc = sqrt((kx+kp)/mx) end % the matrix P doesn't change but the matrix Q does Qc = [cx kx+kp; - 1 0]; Ac = - inv(P)*Qc lambda_c = eig(Ac) % LAPLACE DOMAIN: SPECIFIC FUNCTIONS % TRANSFERT FUNCTIONS % there are specific funcions in matlab to work in the laplace % domain, such as tf, which take as inputs arreys which represents % the coefficients of the terms of the numerator and denomina tor % and build automatically the transfert function. The fucnction % appears in the command window these transfert functions can then % be used to draw the diagrams num_Gs = 1 den_Gs = [mx cx kx] Gs = tf(num_Gs, den_Gs) % open loop TF (H=1) num_G = kp; den_G = den_Gs; G = tf(num_G, den_G) % closed loop TF num_L = kp; den_L = [mx cx kx+kp]; L = tf(num_L, den_L) % POLE FUNCTION % now we can use the function "pole" to obtain the values of the % poles of the TF; the output of the pole function is a column % vector 4 poles_c = pole(L) % poles of L correspond to the eigenvalues % computed before % now taht we have the poles we can draw the root locus of the % system manually, by representing how the poles of the system % vary when kp changes v_kp = [0:100:1000]; % values of kp considered for ii=1:length(v_kp) num_Li = v_kp(ii); den_Li = [mx cx kx+v_kp(ii)]; Li = tf(num_Li, den_Li); poles_Li(:,ii) = pole(Li); end % now we plot the root locus by plotting the real and imaginary % parts of the poles computed as kp changes figure plot(real(poles_Li),imag(poles_Li), '*' ) grid on xlabe l( 'Re' ) ylabel( 'Im' ) % ROOT LOCUS, BODE DIAGRAM, NYQUIST DIAGRAM % there are also functions that draw the root locus and other % diagrams automatically % the function "rlocus" takes as input the tranfert function of % which we want to study the poles, which is the open loop % transfert function G (we draw the root locus of the open loop % tranfert function, which is then used to derive the poles of the % closed loop TF!) figure rlocus(G) % another useful functions are the "bode" and the "nyquist" % functions which plot the respectively diagrams figure bode(G) % ACTUAL bode diagram, not the asymptotic ones! figure nyquist(G) 5 % another function is the "step" function that plots the response % in time of the system to a unitary step (so we have to use the % complete closed loop transfert function L) figure step(L) % from this we can see the performances parameters % such as the steady state value % these diagrams can be also used to see the effect of the change % in the kp values v_kp = [100:100:1000]; for ii=1:length(v_kp) num_Gi = v_kp(ii); % open loop TF for changing values of kp den_Gi = den_G; Gi = tf (num_Gi, den_Gi); figure(10) % figure with a fixed number so that at each time % step the figure overwrites and at the end we will % have only one figure bode(Gi) hold on figure(11) nyquist(Gi) hold on num_Li = v_kp(ii); den_Li = [mx cx kx+v_kp(ii)]; Li = tf(num_Li, den_Li) figure(12) step(Li) hold on end % INTERPRETATIONS OF THE RESULTS % BODE DIAGRAMS: the phase of the transfert function remains the % same while the magnitude of the system changes and it is % translated upwards % NYQUIST DIAGRAMS: increasing kp the magnitude of the nyquist % diagra m increase but the shape remains the same since the phase % doesn't change. There are never encirclements around - 1 -- > % stability since there are no unstable poles 6 % STEP RESPONSE IN TIME DOMAIN: the error decreases as kp % increases because we approach 1, the system becomes faster (tr % decreases), the oscillations are at higher frequencies and the % overshoot increases 7 LAB 2