Control Tutorials for MATLAB and Simulink (2024)


  • Purpose
  • Running the GUI
  • Using the GUI


The purpose of this Graphical User Interface (GUI) is to allow the user to view an animation of the Inverted Pendulum system with the step response plot. This allows the user to see the correlation between the plot and the systems physical response.

The animation and GUI are based on the Inverted Pendulum: State-Space Controller Design page. This method was used because we can easily return the cart position and pendulum angle as well as their respective velocities. For more information on the system model please refer to the Inverted Pendulum: System Modeling page.

Running the GUI

To run the GUI you will need 3 files. Copy each of them to the directory in which you are running MATLAB.

invgui.fig - contains the graphical interface.

invgui.m - contains the GUI callback function.

invODE.m - contains the ode file necessary to run the nonlinear simulation.

Once these files are copied into your MATLAB directory, simply enter the following command:


Neither of the other two files need to be run from the command window, they will be called separately by the GUI. The following figure should appear on your screen after the command has been executed:

Control Tutorials for MATLAB and Simulink (1)

Once you click on Run, the following figure should appear on your screen.

Control Tutorials for MATLAB and Simulink (2)

Using the GUI

Below are descriptions of each of the controls found in the GUI. These descriptions are intended to give the user a better understanding of what each control actually does. However, feel free to experiment with the controls and use this section as a reference for any questions you might have.

The first group of controls contains the Run, Repeat, Clear, and Exit buttons. These controls perform most of the work in the GUI.

Control Tutorials for MATLAB and Simulink (3)

Run - This button performs the simulation, plots the response in the upper-right portion of the window and runs the animation in the lower-right portion of the window. In the step response plot the red line is the cart's position and the blue line is the pendulum's angle.

Repeat - The purpose of this button is to re-plot the response and re-run the animation. It uses the results from the previous simulation performed by choosing the Run button. This is especially useful for the nonlinear simulation, which can take some time to run.

Clear - This control clears both the plots. If the plots are not cleared, then during the next run the step response will be graphed on the same plot. This is useful if you want to graphically see the effect of varying a parameter.

Exit - This button closes the GUI.

An example of the animation and response plot are shown below. As you can see, both the cart's position and pendulum's angle were plotted in the step response plot.

Control Tutorials for MATLAB and Simulink (4)

The next group of controls allows you to set the weighting factor of the Q matrix for the LQR design method utilized in the animation. For more information on LQR and weighting factors for this problem click here.

Control Tutorials for MATLAB and Simulink (5)

X Factor - This editable text field weights the cart's position in the LQR controller. Increasing the weighting factor improves the cart's response, making it reach it's commanded position faster.

Theta Factor - This editable text field weights the pendulum's angle. Similar to the x weighting factor, making this larger will quicken the pendulum's response.

Feel free to change the weighting factors to see what happens!

The control shown below allows you to change the step disturbance.

Control Tutorials for MATLAB and Simulink (6)

Step Slider - The slider allows you to change the magnitude of the step disturbance on the cart. You can click on the arrows to move the slider, grab the the slider bar and move it, or click on the slider to change the step input. The current value of the step input is displayed in the upper portion of the box.

This next group of controls contains checkboxes that allow the user to change various features of the GUI.

Control Tutorials for MATLAB and Simulink (7)

Manual Advance - If this control is checked, the user is able to advance the animation and plot one frame at a time. The frames are advanced by pressing any key on the keyboard. This function is useful if the animation moves too fast for the user and will allow the user to better visualize the entirety of the system's motion.

Plot Separately - By checking this box the step response plot is graphed in its entirety before the animation is run.

Reference Input - This box is automatically checked when the GUI is run. By un-checking it the user removes the reference input term, Nbar, from the simulation. The reference input is used to correct steady-state errors common to full-state feedback systems.

Non-Linear System - This checkbox allows the user to switch the model from the linear representation used throughout the tutorials to the non-linear representation of the system. Through the non-linear system the user may get a better idea of what actually happens in the system.

Remember, this GUI is intended to be an interactive learning tool that will allow the user to get a feeling for how some basic control techniques and ideas are represented in the real world. Therefore, the user is encouraged to play around with this tool to enhance their understanding of controls.

Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)


Top Articles
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5765

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.