# Control instructions in MATLAB and Simulink (2023)

• The act of controlling the temperature
• Motor control activity

## Contents

• Open loop plant model
• Implementation of the PID controller in Simulink
• Run the closed-loop model
• Model extraction in MATLAB

## Open loop plant model

Think of a model of the Simulink toy train system, carried out inIntroduction: Modeling in Simulinkpage and picture below.

You can generate this model yourself or download the finished model by right-clicking on itHerethen selectSave link as.... Assuming the train runs in only one dimension (along the track), we want to control the locomotive so that it starts and stops smoothly and can follow a given constant speed with minimal parking errors.

## Implementation of the PID controller in Simulink

First, let's create a structure that simulates a train system in a unique feedback loop with a PID controller. To make our Simulink model easier to understand, we first store the train model in its own subsystem block. To achieve this, remove the three range blocks and replace each block with an Out1 block from the Sinks library. Label each Out1 block with the appropriate variable name, "x1_dot", "x1" and "x2". Then remove the signal generator block and replace it with the In1 block from the resource library. Label this element with an "F" for the force generated between the train's locomotive and the rail. Your model should now look like this.

Then select all blocks in your model (Ctrl A) and selectSelection subsystemright-click in the model window. After a little editing and marking, your model should look like the one shown below.

Now we can add the controller to our system. We will be using a PID controller which can be implemented with a PID controller block from the Continuous library. Putting this block in series with the train subsystem, your model will look like this. Below we model the regulator so that it directly generates the force "F". This ignores the dynamics by which the train engine produces torque applied to the wheels and then ignores the dynamics of power generation at the wheel/rail interface. This simplified approach has been chosen at this point because we only want to introduce the basic functionality of Simulink for driver design and analysis.

By double-clicking on the PID controller block, we will pre-set itintegral(s)will gain a square of 0 and leaveProportional (P)Iderivative (D)get the default values ​​1 and 0 respectively. Then add a sum block from the math operations library. Double click on this block and customizeCharacter listfield to "|+-". Since we want to control the motor speed of the toy train, we return the motor speed. This is done by touching the "x1_dot" signal line and connecting it to the minus sign of the sum block. The output of the sum block is the speed error for the train motor and must be connected to the input of the PID control block. By connecting the blocks as described and adding labels, your model should look like this.

Then add a Signal Builder block from the source library to display the speed set for the train. Since we want to design a controller that smoothly accelerates the train and smoothly stops it, we test the system with the command to increase the speed to 1 m/s and then go back to 0 m/s (remember that our system istoys-train). Double-click the Signal Builder block to generate this type of command signal. Then selectChange the time rangevanshaftsmenu at the top of the block dialog. organize somethingmaximum timefield for "300" seconds. Then set the step up to 10 seconds and the step down to 150 seconds. This is achieved by clicking on the relevant parts of the signal graph (left and right vertical lines) and dragging the line to the desired position or entering the desired timeTbox at the bottom of the window. When you're done, your signal should look like this.

Also add a Scope block from the Sinks library and use it to replace the Out1 train speed block. If you change the block labels, your model will look like this.

We are now ready to run the closed loop simulation. If you want to skip the steps above, you can right-click to download the finished modelHerethen selectSave link as....

## Run the closed-loop model

Before running the model, we need to assign numeric values ​​to each of the variables used in the model. We will use the following values ​​for the train system.

• = 1 kg
• = 0,5 kg
• = 1 N/sek
• = 1 N
• = 0,02 s/m
• = 9,8 m/s^2

Create a new onem-bestandand enter the following commands.

`M1 = 1; M2 = 0,5; k = 1; fa = 1; mu = 0,02; g = 9,8;`

Run the m file in the MATLAB command window to define these values. Simulink will recognize these MATLAB variables for use in the model. Next, we need to set the amount of time our simulation will run to match the timeframe of the Signal Builder block command. This is achieved through selectionModel configuration parametersvanSimulationmenu at the top of the model view and editstop timefield for "300". Now run the simulation and open the "x1_dot" range to examine the output speed. The result below shows that the closed-loop system is stable for this controller.

Since the performance achieved above is unsatisfactory due to steady state error, let's see how to redesign our controller. First, we'll show you how to extract a Simulink model into MATLAB for analysis and design. Next, we'll show you how to design a controller directly in Simulink.

## Model extraction in MATLAB

The Simulink Control Design tool provides the functionality to extract models from Simulink to the MATLAB workspace. This is especially useful for complex or non-linear simulation models. It is also useful for generating discrete-time (sampled) models. For this example, let's extract the continuous time model of our train subsystem. First we need to identify the inputs and outputs of the model we want to extract. The input to the train system is power. We can highlight this fact by right-clicking on the signal representing "F" (PID block output) and selecting itLinear Analysis Points > Open Loop Inputfrom the resulting menu. Similarly, we can highlight the output of the train system by right-clicking on the "x1_dot" signal and selectingLinear Analysis Points > Open Loop Outputfrom the resulting menu. These inputs and outputs are now indicated by small arrow symbols as shown in the image below. Also, since we only want to extract the train model, no control, we need to clear the feedback signal, otherwise we will extract the closed loop modelAct. Your model should now look like this.

Now we can extract the model by opening itLinear analysis tool. This is achieved through selectionControl Design > Linear AnalysisbelowAnalyzingmenu at the top of the model window. After these steps, the following window will open.

This tool generates an LTI object from a (possibly non-linear) Simulink model and allows you to specify a point around which linearization is performed. Since our Simulink model is already linear, our operating point selection is unaffected and we can leave it as the defaultInitial state of the model. Select to generate a linearized modelStepin the image above, which is marked with a small green triangle. TheLinear analysis toola window should now appear as shown below.

Checking the above automatically generated the step response of the linearized model. If we compare this step response with the response generated by simulating the open loop train system in the programIntroduction: Modeling in Simulinkthe website shows that the answers are identical. This makes sense since the simulation model was already linear. In addition, the linearization process generated an objectlinsys1shown inWorkspace for linear analysisabove. This LTI object can be exported for use in MATLAB by simply exporting the object toMATLAB workspaceOfLinear analysis toolwindow.

After unpacking this model, we can now use all the possibilities offered by MATLAB to design a controller. For example, let's use the commands below to generate and analyze a closed-loop system that reflects the Simulink model created above.

`sys_cl = loopback (linsys1,1); p = pool (sys_cl) z = zero (sys_cl)`
`p = -0,9237 + 0,0000i 0,0000 + 0,0000i -0,2342 + 1,6574i -0,2342 - 1,6574i`
`z = -0.0980 + 1.4108i -0.0980 - 1.4108i 0.0000 + 0.0000i`

If you check the above, you will see that there is a zero outage at the source. In addition, the other poles have a negative real part, and the two "slowest" poles are composite. This shows that the loop system in its current form is stable and that the dominant poles are underdamped. This is consistent with the result of our closed-loop simulation above. We could then use MATLAB to design a new controller to dampen oscillations in the response, for example. In this case, we prefer to show how some MATLAB functions can be accessed directly in Simulink.

We can run interactive tools to tune our controller in Simulink. One way to do this is to double-click and select the PID controller in the modelPleasestart buttonTuner PIDtools. Instead, let's start more generallyOperating systems designertool by selectingOperating Design > Operating System DesignerbelowAnalyzingmenu at the top of the model window. After these steps, the following window will open.

The first thing to do is identify the controller block that needs to be configured. You do this by first clicking a buttonAdd blocksand then in the window that appears, select the PID controller block as shown below. Then clickAgreeknob. Note that controllers represented by other types of blocks (transfer function, state space, etc.) can also be tuned.

Before we start tuning our controller, we first need to identify the inputs and outputs of the closed-loop system we want to analyze. This is done in a similar way to how we extracted the linearized model in MATLAB. Right click on the speed command signal (Signal Builder block output) and selectLinear Analysis Points > Input Distortionfrom the resulting menu to identify the input of our closed loop system. Then right click on the train engine speed signal ("x1_dot") and selectLinear Analysis Points > Output Measurementfrom the output selection menu of our system. Your model should now look like this, with small arrows pointing to the inputs and outputs of the model.

Now that we have identified the settings block and our inputs and outputs, we can start configuring the controller. To chooseAgreeu buttonEdit architecturewindow. We should now see the window below.

By clickingAdjustment methodsuse the button to select the drawings that we want to use to design our controller. In this example, we use the root locus design approach and will choose accordinglyLocus main editorpod belowGraphics adjustmentas shown above. The root locus design approach uses a diagram representing all possible poles of a closed loop as a parameter (loop gain) ranging from zero to infinity. In particular, we make the following choiceSelect Reply to editwindow and selectGrunt.

We should then get a root locus diagram as shown below, showing all possible pole locations in a closed-loop closed-loop train system under simple proportional control. By examining the graph, you can see that all loop gain values ​​will place the closed loop poles in the left half of the plane, indicating a stable response.

If we reduce the loop gain sufficiently, we can move the closed loop poles further to the left half of the plane and we can change the efficiency of our system. This can be achieved by graphically grabbing the pink boxes representing the position of the closed-loop bars and dragging them to the position of the open-loop bars (markedX'With). By clicking, we can check the corresponding step response in a closed loopnew episodebelowCONTROL SYSTEMtab and selectA new step. When the next window appears, we selectNew input-output responsevanOdaberite answer to the plotdrop-down menu as shown.

We then specify the inputs and outputs within the frameworkA new stage of drawingwindow as shown below.

Then clickGruntknob. From the resulting closed-loop step response, it can be seen that the response is stable but with some stationary error.

Recall that adding integral control is one way to reduce the stationary error of a closed loop system. In this case, adding the integrator via the driver makes the system type 1 where type 1 systems can follow step references without steady state error. Call the following form of the PI controller.

(1)

Checking this equation shows that the PI controller adds an integrator and zero to our open loop system. An integrator can be added to the system by right-clicking on the root site field and selectingAdd Pool/Zero > Integratorfrom the resulting menu. Similarly, zero can be added by right-clicking on the root spot graph and selectingAdd pole/zero > true zerofrom the resulting menu. Then click on the right axis where you want to put the zero. You can move the zero by clicking and dragging it to a new location. The compensator can also be edited by entering the pole and zero position directly. This can be achieved by right-clicking on the home page diagram and selectingEdit compensatorfrom the resulting menu. The window that will open is shown below. We set the integrator, real zero, to -0.15 and select a loop gain of 0.05.

Below is a closed-loop response diagram showing a smooth stop of the train engine without the idle fault for a constant speed command.

The selected control gains can then be applied to the Simulink model by clickingUpdate blocksbutton insideCONTROL SYSTEMtab as shown above. The simulation can then be run with this newly configured driver. Clicking on the Scope block for the train engine speed will give you a graph similar to the one shown below.

Overall, this response seems to meet our goals of getting the train up to speed and back to a smooth stop while keeping the stationary error to a minimum. This answer matches the result generated byOperating systems designerabove, because this analysis and the Simulink model used exactly the same linear model.

Released with MATLAB® 9.2

## FAQs

### What is control model in Simulink? ›

Simulink Control Design™ lets you design and analyze control systems modeled in Simulink®. You can automatically tune arbitrary SISO and MIMO control architectures, including PID controllers. PID autotuning can be deployed to embedded software for automatically computing PID gains in real time.

What is a control system in MATLAB? ›

Control System Toolbox™ provides algorithms and apps for systematically analyzing, designing, and tuning linear control systems. You can specify your system as a transfer function, state-space, zero-pole-gain, or frequency-response model.

What are control flow statements in MATLAB? ›

A control flow subsystem executes one or more times at the current time step when enabled by a control flow block. A control flow block implements control logic similar to that expressed by control flow statements of programming languages (e.g., if-then , while-do , switch , and for ).

What are looping control statements? ›

Loop control statements are used to change the flow of execution. These can be used if you wish to skip an iteration or stop the execution. The three types of loop control statements in python are break statement, continue statement, and pass statement.

What are the different types of control models? ›

Control models are widely classified into centralized and event-based control models. Centralized models are classified into call-return model and manager model whilst event-based models are classified into broadcast models and interrupt-driven models.

What are the three types of control systems? ›

Three basic types of control systems are available to executives: (1) output control, (2) behavioral control, and (3) clan control. Different organizations emphasize different types of control, but most organizations use a mix of all three types.

What are the four types of control systems explain? ›

The four types of control systems are belief systems, boundary systems, diagnostic systems, and interactive system. The first two of these belief systems and boundaries systems overlap with the two main elements of organizations that we've already covered.

What are the two types of control system? ›

There are two types of control systems commonly used: open-loop and closed-loop systems.

What are the different types of control statements in MATLAB? ›

MATLAB Language Syntax
if, elseif, elseExecute statements if condition is true
switch, case, otherwiseExecute one of several groups of statements
forfor loop to repeat specified number of times
whilewhile loop to repeat when condition is true
try, catchExecute statements and catch resulting errors
6 more rows

What are the different control statements? ›

There are three types of control statements:
• Conditional/Selection statements.
• Iteration/Loop statements.
• Jump statements.

### What are the 4 important components in a control loop? ›

In a tension control closed-loop system there are four primary elements: the controller, the torque device (brake, clutch, or drive), the tension measurement device, and the measurement signal.

What is a control statement? ›

A control statement allows structured control of the sequence of application statements, such as loops, and conditional tests. It also allows switching the input stream to another file, opening and closing files, and various other operations.

What are the three basic components of a control loop? ›

The core components
• Sensors and transducers. Sensors are the initial measurement devices in a control loop. ...
• Controllers. ...
• Final control elements and actuators.
May 6, 2020

What is PID Controller in MATLAB Simulink? ›

PID control respectively stands for proportional, integral and derivative control, and is the most commonly used control technique in industry.

How do you control a switch in Simulink? ›

To toggle between inputs, double-click the block. You control the signal flow by setting the switch before you start the simulation or by changing the switch while the simulation is executing. The Manual Switch block retains its current state when you save the model.

What is MATLAB and Simulink used for? ›

Simulink provides a graphical editor, customizable block libraries, and solvers for modeling and simulating dynamic systems. It is integrated with MATLAB®, enabling you to incorporate MATLAB algorithms into models and export simulation results to MATLAB for further analysis.

What is the most common control system? ›

Control Systems: Industrial Applications

The most common control type used today in industry is a PID controller (proportional, integral, derivative), which allows the operator to apply different control techniques that can be used to achieve different settings in an experiment or process.

What is the most common type of control system? ›

Role-based access control (RBAC)

As the most common access control system, it determines access based on the user's role in the company—ensuring lower-level employees aren't gaining access to high-level information.

What are the 5 basic elements of control system? ›

The framework consists of five components that together create an effective and integrated enterprise controls system.
• Control Environment. ...
• Risk Assessment. ...
• Control Activities. ...
• Information and Communication. ...
• Monitoring Activities.
Oct 31, 2022

What are the different types of variables in control system? ›

• Types of variables.
• Independent vs. dependent.
• Explanatory vs. response.
• Mediator vs. moderator.
• Extraneous variables.
• Confounding variables.
• Control variables.
• Correlation vs. causation.
Mar 1, 2021

### What are the five elements of system control? ›

Determining whether a particular internal control system is effective is a judgement resulting from an assessment of whether the five components - Control Environment, Risk Assessment, Control Activities, Information and Communication, and Monitoring - are present and functioning.

What are the two basic control processes? ›

The basic control process, wherever it is found and whatever it is found and whatever it controls, involves three steps: (1) establishing standards. (2) measuring performance against these standards. and (3) correcting deviations from standards and plans.

What is basic control system? ›

A control system manages, commands, directs, or regulates the behavior of other devices or systems using control loops. It can range from a single home heating controller using a thermostat controlling a domestic boiler to large industrial control systems which are used for controlling processes or machines.

What are the basic components of control system? ›

A feedback control system consists of five basic components: (1) input, (2) process being controlled, (3) output, (4) sensing elements, and (5) controller and actuating devices.

What are the two types of loops in MATLAB? ›

There are two types of loops: for statements loop a specific number of times, and keep track of each iteration with an incrementing index variable. while statements loop as long as a condition remains true.

How many types of MATLAB are there? ›

There are 17 fundamental classes in MATLAB. Each of these classes is in the form of a matrix or array.

How many types of variables are there in MATLAB? ›

Data Types Available in MATLAB

MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a matrix or array. The size of this matrix or array is a minimum of 0-by-0 and this can grow up to a matrix or array of any size.

Which is the most basic control flow statement? ›

The most basic control flow statement supported by the Java programming language is the if-then statement. The switch statement allows for any number of possible execution paths. The do-while statement is similar to the while statement, but evaluates its expression at the bottom of the loop.

What is the difference between a control statement and a control structure? ›

Control Structure, as name suggests, is basically a set of statements and control statements that are controlling their execution. 2. Control Statement : Control Statement, as name suggests, is basically a statement that is used to determine control flow of set of statements.

What are the 8 categories of control flow mechanism? ›

In this chapter we introduced the principal forms of control flow found in programming languages: sequencing, selection, iteration, procedural abstraction, recursion, concurrency, exception handling and speculation, and nondeterminacy.

### How many types of control structures are there? ›

The following are the different types of control structures: Sequential control structure. Selection control structure. Iteration control structure.

How many conditional control statements are there? ›

There are three forms of IF statements: IF-THEN , IF-THEN-ELSE , and IF-THEN-ELSIF .

What is a control model? ›

Business control models display the primary processes that take place within an organization, and show which business functions are used to control those primary processes. A business control model consists of one or more business control diagrams which can be structured hierarchically.

What is the use of control model? ›

Purposes of a Control Model

The purposes of this model include: The application of a control mechanism to a process to ensure that the objectives, targets or standards are reached. Analysis of a process. Analysis of Control problems.

What is a control system model? ›

The control systems can be represented with a set of mathematical equations known as mathematical model. These models are useful for analysis and design of control systems. Analysis of control system means finding the output when we know the input and mathematical model.

What is the difference between plant model and controller model? ›

The plant model is compiled and run on a real-time simulation platform, while the controller is compiled and programmed to the target hardware that will be used in deployment.

What are 4 types of control? ›

4 Different Types of Controls determined primarily by the time – Explained!
• Pre-controls: These controls are also known as “feed-forward” controls and are basically preventive in nature. ...
• Steering controls: ...
• Yes/No controls: ...
• Post-action-controls:

What are three types of control? ›

Three basic types of control systems are available to executives: (1) output control, (2) behavioural control, and (3) clan control. Different organizations emphasize different types of control, but most organizations use a mix of all three types.

What is an example of control? ›

She hired an accountant to take control of her money. He lost all muscle control in his left arm. The soccer player showed good control of the ball. a teacher with good control of her students The farmer used an organic pest control on his crops.

What is an example of a control process? ›

An example of feedback control is when a sales goal is set, the sales team works to reach that goal for three months, and at the end of the three-month period, managers review the results and determine whether the sales goal was achieved.

### Why is control system needed? ›

A control system manages, commands, directs, or regulates the behavior of other devices or systems using control loops. It can range from a single home heating controller using a thermostat controlling a domestic boiler to large industrial control systems which are used for controlling processes or machines.

What are the 3 elements of control system? ›

The constitution of a closed-loop control system is discussed in chapter 1; the basic system is defined in terms of three elements, the error detector, the controller and the output element.

What are the four 4 steps in control system? ›

Establishing Performance Standards. Measuring the Actual Performance. Comparing Actual Performance to the Standards. Taking Corrective Action.

What are two types of control systems? ›

There are two types of control systems commonly used: open-loop and closed-loop systems.

What is plant model in Simulink? ›

Plants with complex characteristics such as long time delays, higher-order dynamics, or strong interactions are particularly well-suited for model predictive control. To create a linear plant model, you can directly specify a linear model, linearize a Simulink® model, or identify a linear model using measured data.

What is the relationship between model and controller? ›

In simplest form: Models are code representation of what you have in database. Controllers are responsible for accepting request, calling appropriate logic and returning a response.

## References

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated: 08/02/2023

Views: 5789

Rating: 4.1 / 5 (42 voted)

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.