System simulation using Matlab, state plane plots his lab is mainly concerned with making state plane (also referred to as phase plane ) plots for various linear and nonlinear systems with two states he second part of this document presents the derivation of the differential equations which describe the dynamics of the inverted pendulum Problem ake for example the system described by the differential equation Denoting x = y, x = y we now write x = x x = α( x ) x x he equilibrium point is x =, x = he linear model of the system around this equilibrium point is x x x = α x y+ α( y ) y + y = he 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=; % nt is the number of trajectories for k=:nt, x=[(rand(,)-5*[ ]')*]; % each one of the two initial states is %chosen randomly in the interval [-,+] =;tspan=[ ]; [t,x]= ode(@system,tspan,x); plot(x(),x(),'or',x(:,),x(:,)); end title('phase plane plot'); xlabel('x_'); ylabel('x_') function xdot=system(t,x) x=[x() x()]'; alpha=; xdot=[x(); -alpha*(x()^-)*x()-x()]; % xdot=[x(); - x()+alpha*x()]; % 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 α Notice how this parameter changes the shape of the trajectories
c Notice that the trajectories are converging to a closed orbit in the state space hat is a limit cycle Since the trajectories are converging towards it this means that it is a stable limit cycle Problem Consider the system described by the differential equation x = x y = x y a Calculate the equilibrium points bdetermine 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 he following figures present the results in the two cases Phase plane plot 5 x 5-5 - -5 - -5 5 5 x Figure State plane trajectories for the linear model around the stable equilibrium (,) Notice that for the linear model of the system, valid around this equilibrium point, this equilibrium is moved to the point (,) Phase plane plot 5 x 5-5 - -5 - -5 5 5 x Figure State plane trajectories for the linear model around the stable equilibrium (,-)
dsimulate the nonlinear system and draw the phase plane plot he next figure presents such a result Phase plane plot x - - - -4-5 -5 - -5 5 5 x Figure 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 he state trajectories go towards the equilibrium (,) from all directions he equilibrium (,-) is avoided on the direction of x while the trajectories are attracted to it on the direction of x he Matlab code which was used to obtain the previous figures is the following: function main clear all;close all;clc; nt=6; % nt is the number of trajectories for k=:nt, x=[(rand()-5)*; (rand())*-]; % each one of the two initial states is chosen randomly in a given interval =;tspan=[ ]; [t,x]= ode(@system,tspan,x); plot(x(),x(),'or',x(:,),x(:,)); end title('phase plane plot'); xlabel('x_'); ylabel('x_') function xdot=system(t,x) x=[x() x()]'; %xdot=[-x(); -x()^-x()^]; xdot=[- ; ]*x; %saddle point equilibrium %xdot=[- ; -]*x; %stable equilibrium
Problem Consider the system described by the differential equations x = x+ xx x = x xx 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( + x y ) a y = x( + y x ) x = y b y = x r = r( r) c θ = sin θ + ( 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= rcos θ, y = r 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) 4
INVERED PENDULUM he inverted pendulum on a cart is representative of a class of systems that includes stabilization of a rocket during launch he position of the cart is p, the angle of the rod is θ, 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 he coordinates of the bob are (p,z ) p m θ L z g f M p In the following we derive the differential equations which describe the dynamics of the inverted pendulum system use Lagrange's equation he kinetic energy of the cart is K = Mp he kinetic energy of the bob is Inverted Pendulum K = m( p + z ) where p = p + L, z = L so that p = p + Lθ, z = Lθ herefore, the total kinetic energy is K = K + K = Mp + m( p + p θ L + L θ ) he potential energy is due to the bob and is U = mgz = mgl he 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) L = K U = ( M + m) p + mlp θ + ml θ mgl 5
he generalized coordinates are selected as q = [ q ] q = [ p θ ] so that Lagrange's equations are d L L = f dt p p d L L = dt θ θ Substituting for L and performing the partial differentiation yields ( M + m) p + mlθ mlθ = f mlp + ml θ mgl = hese dynamical equations must now be placed into state-space form o accomplish this, write the Lagrange equation in terms of matrices as M + m ml p mlθ + f = ml ml θ mgl his is a mechanical system in typical Lagrangian form, with the inertia matrix multiplying the acceleration vector he term θ ml is a centripetal term and mgl is a gravity term Invert the inertia matrix and simplify to obtain mg mlθ f p = m cos θ ( M + m) ( M + m) g + mlθ + f θ = ml cos θ ( M + m) L Now, the state may be defined as x = [ x x x x ] [ ] = p p θ θ 4 and the input as u= f hen the nonlinear state equation may be written as x mg sin x cos x mlx4 sin x u m cos x ( M + m) x = = x4 ( M + m) g sin x + mlx4 sin x cos x + u cos x ml cos x ( M + m) L f ( x, u) 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 he equilibrium point of interest is x= p p θ θ = [ ], 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 x x,cos x In addition, all squared state components are very small and so set equal to zero his yields the linear state equation 6
x mgx u + mg x M M x M = + u = Ax + Bu x = 4 ( M + m) g ( M + m) gx u ML ML ML he 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 y = = x = h( x, u) θ he 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, θ, but this might be achieved by placing tachometers on a wheel and at the rod pivot point hen, the output equation will change Given the linear state-space equations, a controller can be designed to keep the rod upright hough 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 [ ] x = and u =, 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 7