pendule inversé

  • Upload
    sakridj

  • View
    259

  • Download
    7

Embed Size (px)

Citation preview

Example: Modeling an Inverted Pendulum in SimulinkProblem setup and design requirements Force analysis and system equation setup Building the model Open-loop response Extracting a linearized model Implementing PID control Closed-loop response

Problem setup and design requirementsThe cart with an inverted pendulum, shown below, is "bumped" with an impulse force, F. Determine the dynamic equations of motion for the system, and linearize about the pendulum's angle, theta = 0 (in other words, assume that pendulum does not move more than a few degrees away from the vertical, chosen to be at an angle of 0). Find a controller to satisfy all of the design requirements given below.

For this example, let's assume that M m b l I F x theta mass of the cart 0.5 kg mass of the pendulum 0.2 kg friction of the cart 0.1 N/m/sec length to pendulum center of mass 0.3 m inertia of the pendulum 0.006 kg*m^2 force applied to the cart cart position coordinate pendulum angle from vertical

In this example, we will implement a PID controller which can only be applied to a singleinput-single-output (SISO) system,so we will be only interested in the control of the pendulums angle. Therefore, none of the design criteria deal with the cart's position. We will assume that the system starts at equilibrium, and experiences an impulse force of 1N. The pendulum should return to its upright position within 5 seconds, and never move more than 0.05 radians away from the vertical. The design requirements for this system are:

Settling time of less than 5 seconds. Pendulum angle never more than 0.05 radians from the vertical.

Force analysis and system equation setupBelow are the two Free Body Diagrams of the system.

This system is tricky to model in Simulink because of the physical constraint (the pin joint) between the cart and pendulum which reduces the degrees of freedom in the system. Both the cart and the pendulum have one degree of freedom (X and theta, respectively). We will then model Newton's equation for these two degrees of freedom.

It is necessary, however, to include the interaction forces N and P between the cart and the pendulum in order to model the dynamics. The inclusion of these forces requires modeling the x and y dynamics of the pendulum in addition to its theta dynamics. In the MATLAB tutorial pendulum modeling example the interaction forces were solved for algebraically. Generally, we would like to exploit the modeling power of Simulink and let the simulation take care of the algebra. Therefore, we will model the additional x and y equations for the pendulum.

However, xp and yp are exact functions of theta. Therefore, we can represent their derivatives in terms of the derivatives of theta.

These expressions can then be substituted into the expressions for N and P. Rather than continuing with algebra here, we will simply represent these equations in Simulink. Simulink can work directly with nonlinear equations, so it is unnecessary to linearize these equations as it was in the MATLAB tutorials.

Building the Model in SimulinkFirst, we will model the states of the system in theta and x. We will represent Newton's equations for the pendulum rotational inertia and the cart mass.

Open a new model window in Simulink, and resize it to give plenty of room (this is a large model). Insert two integrators (from the Linear block library) near the bottom of your model and connect them in series. Draw a line from the second integrator and label it "theta". (To insert a label, doubleclick where you want the label to go.) Label the line connecting the integrators "d/dt(theta)". Draw a line leading to the first integrator and label it "d2/dt2(theta)".

Insert a Gain block (from the Linear block library) to the left of the first integrator and connect its output to the d2/dt2(theta) line. Edit the gain value of this block by double clicking it and change it to "1/I". Change the label of this block to "Pendulum Inertia" by clicking on the word "Gain". (you can insert a newline in the label by hitting return). Insert a Sum block (from the Linear block library) to the left of the Pendulum Inertia block and connect its output to the inertia's input. Change the label of this block to Sum Torques on Pend. Construct a similar set of elements near the top of your model with the signals labeled with "x" rather than "theta". The gain block should have the value "1/M" with the label "Cart Mass", and the Sum block should have the label "Sum Forces on Cart". Edit the Sum Forces block and change its signs to "-+-". This represents the signs of the three horizontal forces acting on the cart.

Now, we will add in two of the forces acting on the cart.

Insert a Gain block above the Cart Mass block. Change its value to "b" and its label to "damping". Flip this block left-to-right by single clicking on it (to select it) and selecting Flip Block from the Format menu (or hit Ctrl-F). Tap a line off the d/dt(x) line (hold Ctrl while drawing the line) and connect it to the input of the damping block.

Connect the output of the damping block to the topmost input of the Sum Forces block. The damping force then has a negative sign. Insert an In block (from the Connections block library) to the left of the Sum Forces block and change its label to "F". Connect the output of the F in block to the middle (positive) input of the Sum Forces block.

Now, we will apply the forces N and P to both the cart and the pendulum. These forces contribute torques to the pendulum with components "N L cos(theta) and P L sin(theta)". Therefore, we need to construct these components.

Insert two Elementary Math blocks (from the Nonlinear block library) and place them one above the other above the second theta integrator. These blocks can be used to generate simple functions such as sin and cos. Edit upper Math block's value to "cos" and leave the lower Math block's value "sin". Label the upper (cos) block "Vertical" and the lower (sin) block "Horizontal" to identify the components. Flip each of these blocks left-to-right. Tap a line off the theta line and connect it to the input of the cos block. Tap a line of the line you just drew and connect it to the input of the sin block. Insert a Gain block to the left of the cos block and change its value to "l" (lowercase L) and its label to "Pend. Len."

Flip this block left-to-right and connect it to the output of the cos block. Copy this block to a position to the left of the sin block. To do this, select it (by singleclicking) and select Copy from the Edit Menu and then Paste from the Edit menu (or hit Ctrl-C and Ctrl-V). Then, drag it to the proper position. Connect the new Pend. Len.1 block to the output of the sin block. Draw long horizontal lines leading from both these Pend. Len. blocks and label the upper one "l cos(theta)" and the lower one "l sin(theta)".

Now that the pendulum components are available, we can apply the forces N and P. We will assume we can generate these forces, and just draw them coming from nowhere for now.

Insert two Product blocks (from the Nonlinear block library) next to each other to the left and above the Sum Torques block. These will be used to multiply the forces N and P by their appropriate components. Rotate the left Product block 90 degrees. To do this, select it and select Rotate Block from the Format menu (or hit Ctrl-R). Flip the other product block left-to-right and also rotate it 90 degrees. Connect the left Product block's output to the lower input of the Sum Torques block. Connect the right Product block's output to the upper input of the Sum Torques block. Continue the l cos(theta) line and attach it to the right input of the left Product block. Continue the l sin(theta) line and attach it to the right input of the right Product block.

Begin drawing a line from the open input of the right product block. Extend it up and the to the right. Label the open end of this line "P". Begin drawing a line from the open input of the left product block. Extend it up and the to the right. Label the open end of this line "N". Tap a line off the N line and connect it to the open input of the Sum forces block.

Next, we will represent the force N and P in terms of the pendulum's horizontal and vertical accelerations from Newton's laws.

Insert a Gain block to the right of the N open ended line and change its value to "m" and its label to "Pend. Mass". Flip this block left-to-right and connect it's to N line. Copy this block to a position to the right of the open ended P line and attach it to the P line. Draw a line leading to the upper Pend. Mass block and label it "d2/dt2(xp)". Insert a Sum block to the right of the lower Pend. Mass block. Flip this block left-to-right and connect its output to the input of the lower Pend. Mass block. Insert a Constant block (from the Sources block library) to the right of the new Sum block, change its value to "g" and label it "Gravity". Connect the Gravity block to the upper (positive) input of the newest Sum block. Draw a line leading to the open input of the new Sum block and label it "d2/dt2(yp)".

Now, we will begin to produce the signals which contribute to d2/dt2(xp) and d2/dt2(yp).

Insert a Sum block to the right of the d2/dt2(yp) open end. Change the Sum block's signs to "--" to represent the two terms contributing to d2/dt2(yp). Flip the Sum block left-to-right and connect it's output to the d2/dt2(yp) signal. Insert a Sum block to the right of the d2/dt2(xp) open end. Change the Sum block's signs to "++-" to represent the three terms contributing to d2/dt2(xp). Flip the Sum block left-to-right and connect it's output to the d2/dt2(xp) signal. The first term of d2/dx2(xp) is d2/dx2(x). Tap a line off the d2/dx2(x) signal and connect it to the topmost (positive) input of the newest Sum block.

Now, we will generate the terms d2/dt2(theta)*lsin(theta) and d2/dt2(theta)*lcos(theta).

Insert two Product blocks next to each other to the right and below the Sum block associated with d2/dt2(yp). Rotate the left Product block 90 degrees. Flip the other product block left-to-right and also rotate it 90 degrees. Tap a line off the l sin(theta) signal and connect it to the left input of the left Product block. Tap a line off the l cos(theta) signal and connect it to the right input of the right Product block. Tap a line off the d2/dt2(theta) signal and connect it to the right input of the left Product block. Tap a line of this new line and connect it to the left input of the right Product block.

Now, we will generate the terms (d/dt(theta))^2*lsin(theta) and (d/dt(theta))^2*lcos(theta).

Insert two Product blocks next to each other to the right and slightly above the previous pair of Product blocks. Rotate the left Product block 90 degrees. Flip the other product block left-to-right and also rotate it 90 degrees. Tap a line off the l cos(theta) signal and connect it to the left input of the left Product block. Tap a line off the l sin(theta) signal and connect it to the right input of the right Product block. Insert a third Product block and insert it slightly above the d/dt(theta) line. Label this block "d/dt(theta)^2". Tap a line off the d/dt(theta) signal and connect it to the left input of the lower Product block. Tap a line of this new line and connect it to the right input of the lower Product block. Connect the output of the lower Product block to the free input of the right upper Product block. Tap a line of this new line and connect it to the free input of the left upper Product block.

Finally, we will connect these signals to produce the pendulum acceleration signals. In addition, we will create the system outputs x and theta.

Connect the d2/dt2(theta)*lsin(theta) Product block's output to the lower (negative) input of the d2/dt2(yp) Sum block. Connect the d2/dt2(theta)*lcos(theta) Product block's output to the lower (negative) input of the d2/dt2(xp) Sum block. Connect the d/dt(theta)^2*lcos(theta) Product block's output to the upper (negative) input of the d2/dt2(yp) Sum block. Connect the d/dt(theta)^2*lsin(theta) Product block's output to the middle (positive) input of the d2/dt2(xp) Sum block. Insert an Out block (from the Connections block library) attached to the theta signal. Label this block "Theta". Insert an Out block attached to the x signal. Label this block "x". It should automatically be numbered 2.

Now, save this model as pend.mdl.

Open-loop responseTo generate the open-loop response, it is necessary to contain this model in a subsystem block.

Create a new model window (select New from the File menu in Simulink or hit CtrlN). Insert a Subsystem block from the Connections block library. Open the Subsystem block by double clicking on it. You will see a new model window labeled "Subsystem". Open your previous model window named pend.mdl. Select all of the model components by selecting Select All from the Edit menu (or hit Ctrl-A). Copy the model into the paste buffer by selecting Copy from the Edit menu (or hit Ctrl-C). Paste the model into the Subsystem window by selecting Paste from the Edit menu (or hit Ctrl-V) in the Subsystem window Close the Subsystem window. You will see the Subsystem block in the untitled window with one input terminal labeled F and two output terminals labeled Theta and x.

Resize the Subsystem block to make the labels visible by selecting it and dragging one of the corners. Label the Subsystem block "Inverted Pendulum".

Now, we will apply a unit impulse force input, and view the pendulum angle and cart position. An impulse can not be exactly simulated, since it is an infinite signal for an infinitesimal time with time integral equal to 1. Instead, we will use a pulse generator to generate a large but finite pulse for a small but finite time. The magnitude of the pulse times the length of the pulse will equal 1.

Insert a Pulse Generator block from the Sources block library and connect it to the F input of the Inverted Pendulum block. Insert a Scope block (from the Sinks block library) and connect it to the Theta output of the Inverted Pendulum block. Insert a Scope block and connect it to the x output of the Inverted Pendulum block. Edit the Pulse Generator block by double clicking on it. You will see the following dialog box.

Change the Period value to "10" (a long time between a chain of impulses - we will be interested in only the first pulse).

Change the Duty Cycle value to ".01" this corresponds to .01% of 10 seconds, or .001 seconds. Change the Amplitude to 1000. 1000 times .001 equals 1, providing an approximate unit impulse. Close this dialog box. You system will appear as shown below.

We now need to set an appropriate simulation time to view the response.

Select Parameters from the Simulation menu. Change the Stop Time value to 2 seconds. Close this dialog box

You can download a version of the system here. Before running it, it is necessary to set the physical constants. Enter the following commands at the MATLAB prompt.M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3;

Now, start the simulation (select Start from the Simulation menu or hit Ctrl-t). If you look at the MATLAB prompt, you will see some error messages concerning algebraic loops. Due to the algebraic constraint in this system, there are closed loops in the model with no dynamics which must be resolved completely at each time step before dynamics are considered. In general, this is not a problem, but often algebraic loops slow down the simulation, and can cause real problems if discontinuities exist within the loop (such as saturation, sign functions, etc.) Open both Scopes and hit the autoscale buttons. You will see the following for theta (left) and x (right).

Notice that the pendulum swings all the way around due to the impact, and the cart travels along with a jerky motion due to the pendulum. These simulations differ greatly from the MATLAB open loop simulations because Simulink allows for fully nonlinear systems.

Extracting the linearized model into MATLABSince MATLAB can't deal with nonlinear systems directly, we cannot extract the exact model from Simulink into MATLAB. However, a linearized model can be extracted. This is done through the use of In and Out Connection blocks and the MATLAB function linmod. In the case of this example, will use the equivalent command linmod2, which can better handle the numerical difficulties of this problem. To extract a model, it is necessary to start with a model file with inputs and outputs defined as In and Out blocks. Earlier in this tutorial this was done, and the file was saved as pend.mdl. In this model, one input, F (the force on the cart) and two outputs, theta (pendulum angle from vertical) and x (position of the cart), were defined. When linearizing a model, it is necessary to choose an operating point about which to linearize. By default, the linmod2 command linearizes about a state vector of zero and zero input. Since this is the point about which we would like to linearize, we do not need to specify any extra arguments in the command. Since the system has two outputs, we will generate two transfer functions.

At the MATLAB prompt, enter the following commands[A,B,C,D]=linmod2('pend') [nums,den]=ss2tf(A,B,C,D) numtheta=nums(1,:) numx=nums(2,:)

You will see the following output (along with algebraic loop error messages) providing a state-space model, two transfer function numerators, and one transfer function denominator (both transfer functions share the same denominator).A = 0 0 31.1818 2.6727 B = 0 0 4.5455 1.8182 C = 1 0 D = 0 0 nums = 0 0 den = 1.0000 numtheta = 0 numx = 0 0.0000 1.8182 0.0000 -44.5455 0.0000 4.5455 0.0000 0.0000 0.1818 -31.1818 -4.4545 0.0000 0.0000 0.0000 4.5455 1.8182 0.0000 0.0000 0.0000 -44.5455 0 1 0 0 0 0 0 0 0.0000 0.0000 1.0000 0 0.0000 0.0000 0 1.0000 -0.4545 -0.1818

To verify the model, we will generate an open-loop response. At the MATLAB command line, enter the following commands.t=0:0.01:5; impulse(numtheta,den,t);

axis([0 1 0 60]);

You should get the following response for the angle of the pendulum.

Note that this is identical to the impulse response obtained in the MATLAB tutorial pendulum modeling example. Since it is a linearized model, however, it is not the same as the fullynonlinear impulse response obtained in Simulink.

Implementing PID controlIn the pendulum PID control example, a PID controller was designed with proportional, integral, and derivative gains equal to 100, 1, and 20, respectively. To implement this, we will start with our open-loop model of the inverted pendulum. And add in both a control input and the disturbance impulse input to the plant.

Open your Simulink model window you used to obtain the nonlinear open-loop response. (pendol.mdl) Delete the line connecting the Pulse Generator block to the Inverted Pendulum block. (single-click on the line and select Cut from the Edit menu or hit Ctrl-X). Move the Pulse Generator block to the upper left of the window. Insert a Sum block to the left of the Inverted Pendulum block. Connect the output of the Sum block to the Inverted Pendulum block. Connect the Pulse generator to the upper (positive) input of the Sum block.

Now, we will feed back the angle output.

Insert a Sum block to the right and below the Pulse Generator block. Change the signs of the Sum block to "+-". Insert a Constant block (from the Sources block library) below the Pulse generator. Change its value to "0". This is the reference input. Connect the constant block to the upper (positive) input of the second Sum block. Tap a line off the Theta output of the Inverted Pendulum block and draw it down and to the left. Extend this line and connect it to the lower (negative) input of the second Sum block.

Now, we will insert a PID controller.

Double-click on the Blocksets & Toolboxes icon in the main Simulink window. This will open a new window with two icons. In this new window, double-click on the SIMULINK extras icon. This will open a window with icons similar to the main Simulink window. Double-click on the Additional Linear block library icon. This will bring up a library of Linear blocks to augment the standard Linear block library. Drag a PID Controller block into your model between the two Sum blocks. Connect the output of the second Sum block to the input of the PID block. Connect the PID output to the first Sum block's free input.

Edit the PID block by doubleclicking on it. Change the Proportional gain to 100, leave the Integral gain 1, and change the Derivative gain to 20. Close this window.

You can download our version of the closed-loop system here

Closed-loop responseWe can now simulate the closed-loop system. Be sure the physical parameters are set (if you just ran the open-loop response, they should still be set.) Start the simulation, double-click on the Theta scope and hit the autoscale button. You should see the following response:

This is identical to the closed-loop response obtained in the MATLAB tutorials. Note that the PID controller handles the nonlinear system very well because the angle is very small (.04 radians).

Example: Modeling an Inverted PendulumProblem setup and design requirements Force analysis and system equations MATLAB representation and the open-loop response

Problem setup and design requirementsThe cart with an inverted pendulum, shown below, is "bumped" with an impulse force, F. Determine the dynamic equations of motion for the system, and linearize about the pendulum's angle, theta = Pi (in other words, assume that pendulum does not move more than a few degrees away from the vertical, chosen to be at an angle of Pi). Find a controller to satisfy all of the design requirements given below.

For this example, let's assume thatM m b l I F x mass of the cart mass of the pendulum friction of the cart length to pendulum center of mass inertia of the pendulum force applied to the cart cart position coordinate 0.5 kg 0.2 kg 0.1 N/m/sec 0.3 m 0.006 kg*m^2

thet pendulum angle from a vertical

For the PID, root locus, and frequency response sections of this problem we will be only interested in the control of the pendulum's position. This is because the techniques used in these tutorials can only be applied for a single-input-single-output (SISO) system. Therefore, none of the design criteria deal with the cart's position. For these sections we will assume that the system starts at equilibrium, and experiences an impulse force of 1N. The pendulum should return to its upright position within 5 seconds, and never move more than 0.05 radians away from the vertical. The design requirements for this system are:

Settling time of less than 5 seconds. Pendulum angle never more than 0.05 radians from the vertical.

However, with the state-space method we are more readily able to deal with a multi-output system. Therefore, for this section of the Inverted Pendulum example we will attempt to control both the pendulum's angle and the cart's position. To make the design more challenging we will be applying a step input to the cart. The cart should achieve its desired position within 5 seconds and have a rise time under 0.5 seconds. We will also limit the pendulum's overshoot to 20 degrees (0.35 radians), and it should also settle in under 5 seconds.

The design requirements for the Inverted Pendulum state-space example are:

Settling time for x and theta of less than 5 seconds. Rise time for x of less than 0.5 seconds. Overshoot of theta less than 20 degrees (0.35 radians).

Force analysis and system equationsBelow are the two Free Body Diagrams of the system.

Summing the forces in the Free Body Diagram of the cart in the horizontal direction, you get the following equation of motion:

Note that you could also sum the forces in the vertical direction, but no useful information would be gained. Summing the forces in the Free Body Diagram of the pendulum in the horizontal direction, you can get an equation for N:

If you substitute this equation into the first equation, you get the first equation of motion for this system:

(1 )

To get the second equation of motion, sum the forces perpendicular to the pendulum. Solving the system along this axis ends up saving you a lot of algebra. You should get the following equation:

To get rid of the P and N terms in the equation above, sum the moments around the centroid of the pendulum to get the following equation:

Combining these last two equations, you get the second dynamic equation:(2 )

Since MATLAB can only work with linear functions, this set of equations should be linearized about theta = Pi. Assume that theta = Pi + ( represents a small angle from the vertical upward direction). Therefore, cos(theta) = -1, sin(theta) = - , and (d(theta)/dt)^2 = 0. After linearization the two equations of motion become (where u represents the input):

1. Transfer FunctionTo obtain the transfer function of the linearized system equations analytically, we must first take the Laplace transform of the system equations. The Laplace transforms are:

Since we will be looking at the angle Phi as the output of interest, solve the first equation for X(s),

then substitute into the second equation, and re-arrange. The transfer function is:

where,

From the transfer function above it can be seen that there is both a pole and a zero at the origin. These can be canceled and the transfer function becomes:

2. State-SpaceAfter a little algebra, the linearized system equations equations can also be represented in state-space form:

The C matrix is 2 by 4, because both the cart's position and the pendulum's position are part of the output. For the state-space design problem we will be controlling a multi-output system so we will be observing the cart's position from the first row of output and the pendulum's with the second row.

MATLAB representation and the open-loop response1. Transfer FunctionThe transfer function found from the Laplace transforms can be set up using MATLAB by inputting the numerator and denominator as vectors. Create an m-file and copy the following text to model the transfer function:M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input -b*m*g*l/q];

q = (M+m)*(i+m*l^2)-(m*l)^2; num = [m*l/q 0]; den = [1 b*(i+m*l^2)/q pend=tf(num,den)

-(M+m)*m*g*l/q

Your output should be:

To observe the system's velocity response to an impulse force applied to the cart add the following lines at the end of your m-file:t=0:0.01:5; impulse(pend,t) axis([0 1 0 60])

Transfer function: 4.545 s ---------------------------------s^3 + 0.1818 s^2 - 31.18 s - 4.455

You should get the following velocity response plot:

As you can see from the plot, the response is entirely unsatisfactory. It is not stable in open loop. You can change the axis to see more of the response if you need to convince yourself that the system is unstable. Although the output amplitude increases past 60 radians (10 revolutions), the model is only valid for small . In actuality, the pendulum will stop rotating when it hits the cart ( =90 degree).

2. State-SpaceBelow, we show how the problem would be set up using MATLAB for the statespace model. If you copy the following text into a m-file (or into a '.m' file located in the same directory as MATLAB) and run it, MATLAB will give you the A, B, C, and D matrices for the state-space model and a plot of the response of the cart's position and pendulum angle to a step input of 0.2 m applied to the cart.M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3;

p = i*(M+m)+M*m*l^2; %denominator for the A and B matrices A = [0 1 0 0; 0 -(i+m*l^2)*b/p (m^2*g*l^2)/p 0; 0 0 0 1; 0 -(m*l*b)/p m*g*l*(M+m)/p 0] B = [ 0; (i+m*l^2)/p; 0; m*l/p] C = [1 0 0 0; 0 0 1 0] D = [0; 0] pend=ss(A,B,C,D);

You should see the following output after running the m-file:

T=0:0.05:10; U=0.2*ones(size(T)); [Y,T,X]=lsim(pend,U,T); plot(T,Y) axis([0 2 0 100])

The blue line represents the cart's position and the green line represents the pendulum's angle. It is obvious from this plot and the one above that some sort of control will have to be designed to improve the dynamics of the system. Several example controllers are included with these tutorials; select from below the one you would like to use. Note: The solutions shown in the PID, root locus and frequency response examples may not yield a workable controller for the inverted pendulum problem. As stated previously, when we put this problem into the single-input, single-output framework, we ignored the x position of the cart. The pendulum can be stabilized in an inverted position if the x position is constant or if the cart moves at a constant velocity (no acceleration). Where possible in these examples, we will show what happens to the cart's position when our controller is implemented on the system. We emphasize that the purpose of these examples is to demonstrate design and analysis techniques using MATLAB; not to actually control an inverted pendulum.

Example: Modeling a Cruise Control SystemPhysical setup and system equations Design requirements MATLAB representation Open-loop response Closed-loop transfer function

Physical setup and system equationsThe model of the cruise control system is relatively simple. If the inertia of the wheels is neglected, and it is assumed that friction (which is proportional to the car's speed) is what is opposing the motion of the car, then the problem is reduced to the simple mass and damper system shown below.

Using Newton's law, the modeling equations for this system become:

(1)

where u is the force from the engine. For this example, let's assume that

m = 1000kg b = 50Nsec/m u = 500N

Design requirements

The next step in modeling this system is to come up with some design criteria. When the engine gives a 500 Newton force, the car will reach a maximum velocity of 10 m/s (22 mph). An automobile should be able to accelerate up to that speed in less than 5 seconds. Since this is only a cruise control system, a 10% overshoot on the velocity will not do much damage. A 2% steady-state error is also acceptable for the same reason. Keeping the above in mind, we have proposed the following design criteria for this problem: Rise time < 5 sec Overshoot < 10% Steady state error < 2%

MATLAB representation1. Transfer FunctionTo find the transfer function of the above system, we need to take the Laplace transform of the modeling equations (1). When finding the transfer function, zero initial conditions must be assumed. Laplace transforms of the two equations are shown below.

Since our output is the velocity, let's substitute V(s) in terms of Y(s)

The transfer function of the system becomes

To solve this problem using MATLAB, copy the following commands into an new m-file:m=1000; b=50; u=500; num=[1]; den=[m b]; cruise=tf(num,den);

These commands will later be used to find the open-loop response of the system to a step input. But before getting into that, let's take a look at the state-space representation.

2. State-SpaceWe can rewrite the first-order modeling equation (1) as the state-space model.

To use MATLAB to solve this problem, create an new m-file and copy the following commands:m = 1000; b = 50; u = 500; A = [-b/m]; B = [1/m]; C = [1]; D = 0; cruise=ss(A,B,C,D);

No>e: It is possible to convert from the state-space representation to the transfer function or vice versa using MATLAB. To learn more about the conversion, see the Conversion

Open-loop responseNow let's see how the open-loop system responds to a step input. Add the following command to the end of your m-file and run it in the MATLAB command window:

step(u*cruise) You should get the following plot:

From the plot, we see that the vehicle takes more than 100 seconds to reach the steady-state speed of 10 m/s. This does not satisfy our rise time criterion of less than 5 seconds.

Closed-loop transfer functionTo solve this problem, a unity feedback controller will be added to improve the system performance. The figure shown below is the block diagram of a typical unity feedback system.

The transfer function in the plant is the transfer function derived above {Y(s)/U(s)=1/ms+b}. The controller will to be designed to satisfy all design criteria. Four different methods to design the controller are listed at the bottom of this page. You may choose on PID, Rootlocus, Frequency response, or State-space.

Example: DC Motor Speed ModelingPhysical setup and system equations Design requirements MATLAB representation and open-loop response

Physical setup and system equationsA common actuator in control systems is the DC motor. It directly provides rotary motion and, coupled with wheels or drums and cables, can provide transitional motion. The electric circuit of the armature and the free body diagram of the rotor are shown in the following figure:

For this example, we will assume the following values for the physical parameters.* moment of inertia of the rotor (J) = 0.01 kg.m^2/s^2 * damping ratio of the mechanical system (b) = 0.1 Nms * electromotive force constant (K=Ke=Kt) = 0.01 Nm/Amp * electric resistance (R) = 1 ohm * electric inductance (L) = 0.5 H * input (V): Source Voltage * output (theta): position of shaft * The rotor and shaft are assumed to be rigid

The motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, is related to the rotational velocity by the following equations:

In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant). From the figure above we can write the following equations based on Newton's law combined with Kirchhoff's law:

1. Transfer FunctionUsing Laplace Transforms, the above modeling equations can be expressed in terms of s.

By eliminating I(s) we can get the following open-loop transfer function, where the rotational speed is the output and the voltage is the input.

2. State-SpaceIn the state-space form, the equations above can be expressed by choosing the rotational speed and electric current as the state variab and the voltage as an input. The output is chosen to be the rotational speed.

Design requirementsFirst, our uncompensated motor can only rotate at 0.1 rad/sec with an input voltage of 1 Volt (this will be demonstrated later when the open-loop response is simulated). Since the most basic requirement of a motor is that it should rotate at the desired speed, the steady-state error of the motor speed should be less than 1%. The other performance requirement is that the motor must accelerate to its steady-state speed as soon as it turns on. In this case, we want it to have a settling time of 2 seconds. Since a speed faster than the reference may damage the equipment, we want to have an overshoot of less than 5%.

If we simulate the reference input (r) by an unit step input, then the motor speed output should have:

Settling time less than 2 seconds Overshoot less than 5% Steady-state error less than 1%

MATLAB representation and open-loop response1. Transfer FunctionWe can represent the above transfer function into MATLAB by defining the numerator and denominator matrices as follows:

Create a new m-file and enter the following commands:J=0.01;

Now let's see how the original open-loop system performs. Add the following commands onto the end of the m-file and run it in the MATLAB command window:

b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]; motor=tf(num,den);

step(motor,0:0.1:3);You should get the following plot:title('Step Response for the Open Loop System');

From the plot we see that when 1 volt is applied to the system, the motor can only achieve a maximum speed of 0.1 rad/sec, ten times smaller than our desired speed. Also, it takes the motor 3 seconds to reach its steady-state speed; this does not satisfy our 2 seconds settling time criterion.

2. State-SpaceWe can also represent the system using the state-space equations. Try the following commands in a new m-file.J=0.01; b=0.1; K=0.01; R=1; L=0.5; A=[-b/J K/J -K/L -R/L]; B=[0 1/L]; C=[1 0]; D=0;

motor_ss=ss(A,B,C,D);

Run this m-file in the MATLAB command window, and you should get the same output as the one shown above.

step(motor_ss)

Example: Modeling DC Motor PositionPhysical Setup System Equations Design Requirements MATLAB Representation and Open-Loop Response

Physical SetupA common actuator in control systems is the DC motor. It directly provides rotary motion and, coupled with wheels or drums and cables, can provide transitional motion. The electric circuit of the armature and the free body diagram of the rotor are shown in the following figure:

For this example, we will assume the following values for the physical parameters. These values were derived by experiment from an actual motor in Carnegie Mellon's undergraduate controls lab.* moment of inertia of the rotor (J) = 3.2284E-6 kg.m^2/s^2 * damping ratio of the mechanical system (b) = 3.5077E-6 Nms * electromotive force constant (K=Ke=Kt) = 0.0274 Nm/Amp * electric resistance (R) = 4 ohm * electric inductance (L) = 2.75E-6 H

* input (V): Source Voltage * output (theta): position of shaft * The rotor and shaft are assumed to be rigid

System EquationsThe motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, is related to the rotational velocity by the following equations:

In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant). From the figure above we can write the following equations based on Newton's law combined with Kirchhoff's law:

1. Transfer FunctionUsing Laplace Transforms the above equations can be expressed in terms of s.

By eliminating I(s) we can get the following transfer function, where the rotating speed is the output and the voltage is an input.

However during this example we will be looking at the position, as being the output. We can obtain the position by integrating Theta Dot, therefore we just need to divide the transfer function by s.

2. State SpaceThese equations can also be represented in state-space form. If we choose motor position, motor speed, and armature current as our state variab, we can write the equations as follows:

Design requirementsWe will want to be able to position the motor very precisely, thus the steady-state error of the motor position should be zero. We will also want the steady-state error due to a disturbance, to be zero as well. The other performance requirement is that the motor reaches its final position very quickly. In this case, we want it to have a settling time of 40ms. We also want to have an overshoot smaller than 16%. If we simulate the reference input (R) by a unit step input, then the motor speed output should have:

Settling time less than 40 milliseconds Overshoot less than 16% No steady-state error No steady-state error due to a disturbance

MATLAB representation and open-loop response1. Transfer FunctionWe can put the transfer function into MATLAB by defining the numerator and denominator as vectors:

Create a new m-file and enter the following commands:J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0]; motor=tf(num,den);

Now let's see how the original open-loop system performs. Add the following command onto the end of the m-file and run it in the MATLAB command window: You should get the following plot:

step(motor,0:0.001:0.2)

From the plot we see that when 1 volt is applied to the system, the motor position changes by 6 radians, six times greater than our desired position. For a 1 volt step input the motor should spin through 1 radian. Also, the motor doesn't reach a steady state which does not satisfy our design criteria

2. State SpaceWe can put the state space equations into MATLAB by defining the system's matrices as follows:J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; A=[0 1 0 0 -b/J K/J 0 -K/L -R/L]; B=[0 ; 0 ; 1/L]; C=[1 0 0]; D=[0]; motor=ss(A,B,C,D);

The step response is obtained using the command

step(motor)