Sie sind auf Seite 1von 7

System simulation using Matlab, state plane plots This lab is mainly concerned with making state plane

(also referred to as phase plane) plots for various linear and nonlinear systems with two states. The second part of this document presents the derivation of the differential equations which describe the dynamics of the inverted pendulum. Problem 1. & Take for example the system described by the differential equation && + a ( y 2 - 1) y + y = 0 . y & Denoting x1 = y, x2 = y we now write & x1 = x2 2 & x2 = -a ( x1 - 1) x2 - x1 The equilibrium point is x1 = 0, x2 = 0 . The linear model of the system around this equilibrium point is & x1 0 1 x1 x = -1 a x . 2 &2 The following Matlab code simulates the system and draws the resulting trajectories in the phase plane (state plane).
function main clear all;close all;clc; nt=2; % nt is the number of trajectories for k=1:nt, x0=[(rand(2,1)-0.5*[1 1]')*2]; % each one of the two initial states is %chosen randomly in the interval [-1,+1] T=100;tspan=[0 T]; [t,x]= ode23(@system,tspan,x0); hold on; plot(x0(1),x0(2),'or',x(:,1),x(:,2)); hold on; end title('Phase plane plot'); xlabel('x_1'); ylabel('x_2') function xdot=system(t,x) x=[x(1) x(2)]'; alpha=0.02; xdot=[x(2); -alpha*(x(1)^2-1)*x(2)-x(1)]; % xdot=[x(2); - x(1)+alpha*x(2)]; % this is to be uncommented when the %simulation of the linear model of the system is desired

a. Run the simulation for various numbers of trajectories. Are the trajectories moving toward or away from the equilibrium point? If they are moving toward (away of) the equilibrium point then it is a stable (unstable) equilibrium. b. Run the simulation for various values of a . Notice how this parameter changes the shape of the trajectories. 1

c. Notice that the trajectories are converging to a closed orbit in the state space. That is a limit cycle. Since the trajectories are converging towards it this means that it is a stable limit cycle. Problem 2. Consider the system described by the differential equation & x = -x . 2 2 & y = 1- x - y a. Calculate the equilibrium points. b.Determine the linear model of the system around those equilibrium points c. Simulate the two linear approximations of the nonlinear system and draw the phase plane plots. One equilibrium point is stable while the other one is a saddle point. The following figures present the results in the two cases.
Phase plane plot 2

1.5

x2

0.5

-0.5

-1 -1.5

-1

-0.5

0 x1

0.5

1.5

Figure 1. State plane trajectories for the linear model around the stable equilibrium (0,1). Notice that for the linear model of the system, valid around this equilibrium point, this equilibrium is moved to the point (0,0).
Phase plane plot 20

15

10

x2

-5

-10 -1.5

-1

-0.5

0 x1

0.5

1.5

Figure 2. State plane trajectories for the linear model around the stable equilibrium (0,-1).

d.Simulate the nonlinear system and draw the phase plane plot. The next figure presents such a result.
Phase plane plot 3

x2

-1

-2

-3

-4

-5 -1.5

-1

-0.5

0 x1

0.5

1.5

Figure 3. State plane trajectories for the nonlinear system.

Notice how in small regions around the two equilibrium points the phase plot for the nonlinear system resembles the ones obtained at part c. The state trajectories go towards the equilibrium (0,1) from all directions. The equilibrium (0,-1) is avoided on the direction of x2 while the trajectories are attracted to it on the direction of x1. The Matlab code which was used to obtain the previous figures is the following:
function main clear all;close all;clc; nt=60; % nt is the number of trajectories for k=1:nt, x0=[(rand(1)-0.5)*3; (rand(1))*3-1]; % each one of the two initial states is chosen randomly in a given interval T=1.1;tspan=[0 T]; [t,x]= ode23(@system,tspan,x0); hold on; plot(x0(1),x0(2),'or',x(:,1),x(:,2)); hold on; end title('Phase plane plot'); xlabel('x_1'); ylabel('x_2') function xdot=system(t,x) x=[x(1) x(2)]'; %xdot=[-x(1); 1-x(1)^2-x(2)^2]; xdot=[-1 0; 0 2]*x; %saddle point equilibrium %xdot=[-1 0; 0 -2]*x; %stable equilibrium

Problem 3. Consider the system described by the differential equations & x1 = - x1 + x1 x2 . & x2 = x2 - x1 x2 a. Calculate the equilibrium points. b. Determine the linear model of the system around those equilibrium points. c. Simulate the two linear approximations of the nonlinear system and draw the phase plane plots. d. Simulate the nonlinear system and draw the phase plane plot. Problem 4. Simulate the following systems and draw the phase plane plot. x = y (1 + x - y 2 ) & a. 2 y = x(1 + y - x ) & & x = y b. & y = -x & r = r (1 - r ) c. 3 & q = sin q + (1 - r ) In the case of part b. you will see that the trajectories in the state plane are circles. In the case of part c., plot the state trajectories in the plane (x,y) where x = r cos q , y = r sin q . You will see that the equilibrium point in the origin is unstable and that all the state trajectories are attracted to a circular trajectory with radius equal to one (a stable limit cycle).

INVERTED PENDULUM The inverted pendulum on a cart is representative of a class of systems that includes stabilization of a rocket during launch. The position of the cart is p, the angle of the rod is q, the force input to the cart is f, the cart mass is M, the mass of the bob is m, and the length of the rod is L. The coordinates of the bob are (p2,z2).
p2 m

g q L z2

p Inverted Pendulum

In the following we derive the differential equations which describe the dynamics of the inverted pendulum system use Lagrange's equation. The kinetic energy of the cart is 1 & K 1 = Mp 2 . 2 The kinetic energy of the bob is 1 & 2 &2 K 2 = m( p 2 + z 2 ) 2 where p 2 = p + L sin q , z 2 = L cos q so that & & & & & p 2 = p + Lq cos q , z 2 = - Lq sin q . Therefore, the total kinetic energy is 1 1 & & & && K = K 1 + K 2 = Mp 2 + m( p 2 + 2 pq L cos q + L2q 2 ) . 2 2 The potential energy is due to the bob and is U = mgz 2 = mgL cos q . The Lagrangian is (note that on the left hand side of this equation L denotes the Lagrangian function while L in the right hand side is the constant length of the pendulum arm). 1 1 & & & & L = K - U = ( M + m) p 2 + mLpq cos q + mL2q 2 - mgL cos q . 2 2

The generalized coordinates are selected as q = [q1 q 2 ] T = [ p q ] T so that Lagrange's equations are d L L = f & dt p p . d L L =0 & dt q q Substituting for L and performing the partial differentiation yields & & ( M + m) && + mLq& cos q - mLq 2 sin q = f p . & mL&& cos q + mL2q& - mgL sin q = 0 p

These dynamical equations must now be placed into state-space form. To accomplish this, write the Lagrange equation in terms of matrices as & p M + m mL cos q && mLq 2 sin q + f = . mL cos q & mL2 q& mgL sin q This is a mechanical system in typical Lagrangian form, with the inertia matrix multiplying the & acceleration vector. The term mLq 2 sin q is a centripetal term and mgL sin q is a gravity term. Invert the inertia matrix and simplify to obtain & mg sin q cos q - mLq 2 sin q - f && = p 2 m cos q - ( M + m) . & - ( M + m) g sin q + mLq 2 sin q cos q + f cos q & q& = mL cos 2 q - ( M + m) L
T

Now, the state may be defined as x = [x1 x 2 x3 Then the nonlinear state equation may be written as

x4 ] = p

& & p q q

and the input as u= f.

x2 2 mg sin x3 cos x3 - mLx 4 sin x3 - u 2 m cos x3 - ( M + m) & = f ( x, u ) . x= x4 2 - ( M + m) g sin x3 + mLx 4 sin x3 cos x3 + u cos x3 mL cos 2 x3 - ( M + m) L Given these nonlinear state equations, it is very easy to simulate the inverted pendulum behavior on a computer. We now want to linearize this and obtain the linear state equations. The equilibrium point of & & interest is x = p p q q T = [ 0 0 0 0] T , where the rod is upright. Instead of using the linearization method, for simplicity in this case we will use approximations which are valid near the origin sin x3 x3 , cos x3 1 . In addition, all squared state components are very small and so set equal to zero. This yields the linear state equation 6

x2 - mgx + u 0 3 0 M & x= = 0 x4 ( M + m) gx3 - u 0 ML

1 0 0 0

0 - mg M 0 ( M + m) g ML

0 0 1 0 M x + 0 u = Ax + Bu . 1 -1 0 ML

The output equation depends on the measurements taken, which depends on the sensors available. Assuming measurements of cart position and rod angle, the output equation is p 1 0 0 0 y= = x = h ( x, u ) . q 0 0 1 0 The cart position may be measured by placing an optical encoder on one of the wheels, and the rod &, & angle by placing an encoder at the rod pivot point. It is difficult to measure the velocities p q , but this might be achieved by placing tachometers on a wheel and at the rod pivot point. Then, the output equation will change. Given the linear state-space equations, a controller can be designed to keep the rod upright. Though the controller is designed using the linear state equations, the performance of the controller & should be simulated in a closed-loop system using the full nonlinear dynamics x = f ( x, u ) Problem 5. Write the Matlab code for the simulation of the inverted pendulum. Present the results of the simulation, considering the initial state x0 = [ 0 0 0.001 0] T and u = 0 , using a visual representation of the inverted pendulum in a similar fashion as in the case of the robotic arm from the previous laboratory session. Note that this will be part of a future mini-project which will require simulation of the inverted pendulum system in the case when the control input is calculated using an optimal state feedback control law.

Das könnte Ihnen auch gefallen