Electrical Engineering Technology Lab Assignment
1. Objective
What is the purpose of the experiment?
2. Procedure
Write an explanation of the theory or procedure behind the exercise. Do not re-list the procedure as given in the laboratory manual or give a step-by-step account of the steps you took.
3. Data & Results
Give the experimental data in tabular or graphical form. Show samples of calculations. If applicable, include relevant MATLAB results such as graphs of output and command screen history. These can be attached as an appendix if needed.
4. Discussion
Discuss the results or your exercise and show how the objectives were met. Comment on how the results correlate with theoretical values. What are some causes of error in the results?
5. Conclusion
Briefly reiterate the key points of the above sections. Was the experiment considered a success? What (if anything) could have been done differently or better? What are some lessons learned?
6. Questions
Answer any questions that were asked in the exercise.
Laboratory Exercise 5
Inverted Pendulum: Simulink Modeling
Contents
• Physical setup and system equations
• Building the nonlinear model with Simulink
• Generating the open-loop response
• Extracting a linear model from the simulation
In this page we outline how to build a model of our inverted pendulum system for the purposes of simulation using Simulink and its add-ons. A great advantage of simulation, as will be demonstrated in this example, is that it can generate numerical solutions to nonlinear equations for which closed-form solutions cannot be generated. The nonlinear simulation can then be employed to test the validity of a linearized version of the model. The simulation model can also be used to evaluate the performance of the control scheme designed based on the linearized model.
Building the nonlinear model with Simulink
We can build the inverted pendulum model in Simulink employing the equations derived above by following the steps given below.
• Begin by typing simulink into the MATLAB command window to open the Simulink environment. Then open a new model window in Simulink by choosing New > Model from the File menu at the top of the open Simulink Library Browser window or by pressing Ctrl-N.
• Insert four Fcn Blocks from the Simulink/User-Defined Functions library. We will build the equations for , , , and employing these blocks.
• Change the label of each Fcn block to match its associated function.
• Insert four Integrator blocks from the Simulink/Continuous library. The output of each Integrator block is going to be a state variable of the system: , , , and .
• Double-click on each Integrator block to add the State Name: of the associated state variable. See the following figure for an example. Also change the Initial condition: for (pendulum angle) to "pi" to represent that the pendulum begins pointing straight up.
• Insert four Multiplexer (Mux) blocks from the Simulink/Signal Routing library, one for each Fcn block.
• Insert two Out1 blocks and one In1 block from the Simulink/Sinks and Simulink/Sources libraries, respectively. Then double-click on the labels for the blocks to change their names. The two outputs are for the "Position" of the cart and the "Angle" of the pendulum, while the one input is for the "Force" applied to the cart.
• Connect each output of the Mux blocks to the input of the corresponding Fcn block.
• Connect the output of the and Fcn blocks to two consecutive integrators to generate the cart's position and the pendulum's angle. Your current model should now appear as follows.
Generating the open-loop response
We will now simulate the response of the inverted pendulum system to an impulsive force applied to the cart. This simulation requires an impulse input. Since there is no such block in the Simulink library, we will use the Pulse Generator block to approximate a unit impulse input. Follow the steps given below.
• Open the inverted pendulum model generated above.
• Add a Pulse Generator block from the Simulink/Sources library. Double-click on the block and change the parameters as shown below. In particular, change the Period: to "10". Since we will run our simulation for 10 seconds, this will ensure that only a single "pulse" is generated. Also change the Amplitude to "1000" and the Pulse Width (% of period): to "0.01". Together, these settings generate a pulse that approximates a unit impulse in that the magnitude of the input is very large for a very short period of time and the area of the pulse equals 1.
• Add a Scope block from the Simulink/Sinks library.
• In order display two inputs on the scope, double-click on the Scope block, choose the Parameters icon, and change the Number of axes: to "2".
Extracting a linear model from the simulation
Aside from comparing our simulation model to our prior results, it may also be desirable to extract a linear model for the purposes of analysis and design. Much of the analytical techniques that are commonly applied to the analysis of dynamic systems and the design of their associated control can only be applied to linear models. Therefore, it may be desirable to extract an approximate linear model from the nonlinear simulation model. We will accomplish this from within Simulink.
• To begin, open the Simulink model generated above, Pend_Model.mdl.
• If you generated your simulation model using variables, it is necessary to define the physical constants in the MATLAB workspace before performing the linearization. This can be accomplished by entering the following commands in the MATLAB command window.
M = 0.5;
m = 0.2;
b = 0.1;
I = 0.006;
g = 9.8;
l = 0.3;
• Next choose from the menus at the top of the model window Tools > Control Design > Linear Analysis. This will cause the Linear Analysis Tool window to open.
• In order to perform our linearization, we need to first identify the inputs and outputs for the model and the operating point that we wish to perform the linearization about. First right-click on the signal representing the Force input in the Simulink model. Then choose Linearization Points > Input Point from the resulting menu. Similarly, right-click on each of the two output signals of the model (pendulum angle and cart position) and select Linearization Points > Output Point from the resulting menu in each case. The resulting inputs and outputs should now be identified on your model by arrow symbols as shown in the figure below.
• Next we need to identify the operating point to be linearized about. From the Operating Point: menu choose Linearize At... > Trim model... as shown in the figure below. This will open the TRIM MODEL tab. Within this tab, select the Trim button indicated by the green triangle. This will create the operating point op_trim1.
• Since we wish to examine the impulse response of this system, return to the EXACT LINEARIZATION tab and choose New Impulse from the Plot Result: drop-down menu near the top window as shown in the figure below.
• Finally, choose op_trim1 from the Operating Point: drop-down menu and click the Linearize button indicated by the green triangle. This automatically generates an impulse response plot and the linearized model linsys1.
• In order to compare the results to those plots generated in the Inverted Pendulum: System Analysis page, it is necessary to change the -axis scaling. This can be achieved from by choosing Properties from the right-click menu. The resulting window should then appear as follows, where the top plot is response of the pendulum angle and the bottom plot is the response of the cart position.
Implementing PID control for the nonlinear model
In the Inverted Pendulum: PID Controller Design page a PID controller was designed with proportional, integral, and derivative gains equal to 100, 1, and 20, respectively. To implement this closed-loop system, we will start with one of our plant models from the Inverted Pendulum: Simulink Modeling page. Following the steps below, we will build a closed-loop model with reference input of pendulum position and a disturbance force applied to the cart.
• To begin, open either of the Simulink models generated previously, Pend_Model.mdl.
• Insert two Add blocks from Simulink/Math Operations library.
• Change the List of signs: of one of the Add blocks to "+-".
• Insert a Constant block from Simulink/Sources library. Change its value to 0. This is the reference input that corresponds to the pendulum vertically upward. Note, the model (and the rest of the pages in this example) define the pendulum angle to equal pi when pointing straight up.
• Insert a PID Controller block from the Simulink/Continuous library.
• Edit the PID block by doubleclicking on it. Change the Proportional (P): gain to "100", leave the Integral (I): gain as "1", and change the Derivative (D): gain to "20".
Attachment:- Inverted-Pendulum.rar