20-sim+tutorial

=20-sim Tutorial= //**Modelling and experimenting with 20-sim**//

toc

Download tutorial as //pdf// file//**:**//



=Modelling in 20-sim= 20-sim is a program in which you can make a model of a physical system and simulate that model. There are a few different ways to make a model of a system. In this manual only 1 method is shown.

The physical system
The system we are going to model in this guide is a simple mass-spring-damper system as shown in figure 1. The system is a mass M hanging from a spring and damper. The mass is pulled down by gravity.



Modelling method: Iconic
The first and for most people the easiest method, is the iconic diagram method in 20-sim. With this method it is possible to model the system like you were making a sketched diagram. So a mass is simply a mass-icon, a damper is a damper icon and a force actuator is a force icon. These icons have to be connected to each other so that forces and velocities can 'flow' between the elements of the model.

Open 20-sim, the program starts with a list in the Library on the left and an empty screen on the right. Now we have to select the components we want to use and place them on the worksheet: code Library → Iconic Diagrams → Mechanical → Translation → Components code From the mechanical iconic diagrams, we have selected the translational diagrams. Here we can select the mass, a damper and a spring, and also important, a fixed world. Drag these icons onto the worksheet.

code Drag a mass, spring, damper and fixed world onto worksheet. Also drag a Force from Library → Iconic Diagrams → Mechanical → Translational → Actuators → Force code In figure 2 you can see what it should look like. When all components are on the worksheet, you have to connect them. To do this, you have to enable the connection mode in 20-sim. This can be toggled by pressing the space-bar on your keyboard, or by selecting the connection mode button in 20-sim.

code Press space-bar to enable the connection mode. Then click on the force and on the mass, to connect these two components. Also connect the mass to the spring and damper, and connect the spring and damper to the fixed world. code After connecting the blocks, press space-bar again to enable selection mode.



In figure 3 you can see how you can connect these blocks. The mass and spring have two connection ports, a high port and a low port. These ports determine the internal direction of forces. It is best to select them in such a way that 'the wires do not cross'. So like in figure 3, connect the mass to the filled dark green ports (high) and the fixed world to the light, open, ports (low).



Now we have a model with different connected components, but we haven't put in the right parameters yet. Each component in 20-sim has its own default parameters, but for our model it is necessary to adapt these parameters. By double-clicking a component, you can edit the internals of this component. This means that you can change the behavior, by altering the equations in the component, or you can change the parameters of a component. So if we want to set the following parameters: We have to double click each component and change these parameters. When you want to go back to the worksheet, you have to press the 'Go up' button (red dot with green triangle above it). By pressing the go down button, you can edit a selected component (same as double clicking).
 * Mass: m=1 Kg
 * Spring stiffness: k= 15 N/m
 * Damping constant: d=3 N.s/m
 * Force (gravity): F=-9.8 N

code Select 'Force' block and press 'Go Down' or double click. Then set: real F = -9.8 {N};. Press 'Go up'. code

Repeat this for all components and set the right values. Make sure that you only edit the value, not the rest of the text in the block. We now have a complete model of the physical system.

=Simulating in 20-sim= Now that we have a model of the system, we can simulate it and see if it behaves like expected. 20-sim has a designated simulator, in which all simulations are performed. In the simulator you can set simulation properties like simulation time, integration method and plotting properties. It is also possible to change parameters of the model in this simulator.

Simulating the model
Start the simulator by pressing the simulator icon (graph icon in the top bar in 20-sim). In here you can change parameters of the model by clicking on the 'parameters' button (red triangles). You can also set the simulation properties by clicking on the 'Run' button (blue triangle with pencil). For now we leave these settings to default and concentrate on the plotting properties. These are available from the 'Plot' button (graph with pencil). In this plot dialogue you have to select which properties the simulator has to plot. We are interested in the position x of the mass.

code Click on the 'Plot' button (graph with pencil), and click on 'add curve'. Now you can select a property to plot. Choose the mass in the left column, and then the x, from the right column, see figure 4. Exit these dialogues by clicking OK. code

In the simulator you can see that the position x has appeared as a legend item in the plot-window. We are all set to perform a simulation, so press the 'Run Simulation' button (blue play button). In figure 5 you can see what this should look like.





=20-sim and transfer functions= In the previous part we have made a model of a system in iconic diagrams and simulated in time domain. In control engineering we are almost always more interested in the frequency domain than time domain, so we also have to make a frequency domain model of this system.

Making a transfer function in 20-sim
We are going to make a transfer function of this system by hand and put it into 20-sim. First you have to derive this transfer function by hand. For this system this is easy and results in:

math H(s) = \dfrac{1}{ms^2 + ds + k} math

In 20-sim you have to select the 'LinearSystem' block from the signal toolbox, and fill in the numerator and denominator.

code Select: Library → Signal → Transfer Functions → LinearSystem and drag it into the worksheet. Leave the old model in place for reference. See figure 6 code

code Double click the LinearSystem block or press 'Go Down'. In this window, make sure that the 'Transfer Function' is selected as System Description. Press 'Edit' and change the numerator to 1, and the denominator to 1 3 15. See figure 7. Close this window by clicking OK. code



Now the transfer function is in the Linear System Editor. And it can be analyzed in different ways. By clicking on the different plot options (Bode, Nyquist, Pole Zero, Step and Nichols), you can see that particular plot. code Inspect the bode, pole zero and step plot. code If you close the Linear System Editor, it asks if you want to update the graph, press yes to get a small representation of the transfer function in the block.

=Controllers in 20-sim= Now we have a model of the system and have some simulation results, we want to design and implement a controller. There are a lot of different ways of designing and implementing controllers, and in this manual only two ways are shown. The first method is to design and implement the controller in time domain and tune the controller by looking at its time domain responses.

Time domain controller design and implementation
In this part we again take the mass-spring-damper model, but assume that there is no gravity. So we can remove the static gravitational force. We also assume that we have an actuator that can generate a force on the mass. The position of the mass can be measured with a position sensor.

code Open the mass-spring-damper model and remove the force. Add a Force actuator: Library → Iconic Diagrams → Mechanical → Translation → Actuators → Force Actuator. Also add an absolute position sensor: Library → Iconic Diagrams → Mechanical → Translation → Sensors → PositioSensor-Absolute. Connect the force actuator and the position sensor to the mass. code We now have a model with actuator and sensor. We can add a reference signal and a simple PD controller from the library. Also a plus-minus block is needed to subtract the sensor signal from the reference signal to produce the error signal for the controller.

code Library → Signal → Sources → SignalGenerator-Step. Library → Signal → Block Diagram → PlusMinus. And the controller: Library → Signal → Control → PID Control → Continuous → ControllerWizard. code Connect all the blocks in the right order, so connect the sensor output to the minus of the plusminus block. Connect the reference (Step) to the plus side of the plusminus block, and connect the output of the plusminus block to the input of the controller wizard. Connect the controller to the force actuator. Your model should look like figure 8.



With this controller wizard you can implement a lot of different controllers and filters. From the ControllerWizard, you can go directly to the Linear System Editor to analyze your controller in frequency domain with bode plots and pole zero plots, and in time domain with a step response. So this is a very useful tool.

We are going to implement a PD controller, so open the Controller Wizard and select the PD controller from the list. Leave the parameters at their default values and run a simulation of the controlled system.

code Open ControllerWizard and select 'PD Controller'. Close the window by clicking OK and update the graph if it ask you to. Now open the simulator (press simulator button). Now press the plot button to set the plot properties. Select the property you want to plot (x-position of mass), and simulate this model (Run simulation from the Simulator). code You should see a plot of the x-position of the mass versus the time. Now we can investigate the effect of the different PD parameters on the behavior of this feedback controlled system. Within the simulator you can change parameters and run a second simulation. The results of the first simulation are also shown, so you can compare the results.

code In the simulator, click on the 'parameters' icon (2 red triangles) and locate the ControllerWizard in the left screen. When you click on the ControllerWizard, you should see the 3 parameters of this controller. Change the Kp value from 1 to 15. Click OK to close this dialogue. Run another simulation and inspect the result. It should look like figure 9 code If you would like to clear the plot screen, you can use the reset button (rewind, two blue triangles pointing left).



Linearisation of the model
In the previous section we analyzed the system and controller in time-domain, we looked at the time response of the system as result of a step function. Now we want to analyze the system in frequency domain and also analyze the controller this way.

The first thing we need to do, is to make a frequency domain description (e.g. a transfer function) of the system. We already did this manually (see 3.1), but now we let 20-sim do this for us.

There are different ways to do this, like: Tools frequency domain toolbox model → → linearization, and then select an input and output. The other option is directly from the simulator, where you can define multiple frequency responses, and select later which of them you would like to simulate.

code From the simulator, choose Properties → Frequency Response. In this menu, you can define an input and output probe. These probes define the input and output of your desired transfer function. As input probe, choose the force of the force actuator (ForceActuator\F), and as output choose the position of the mass (Mass\x). Add this response by clicking on Add Frequency response, you can change some settings here but that is not necessary now. Click OK to close this window. In the simulator, you can choose which response you want to see by clicking Simulation → Frequency Response, and then select one from the list. code A bode diagram should pop-up which describes the frequency domain behavior of the system. Also the Linear System Editor should appear in which a transfer function is shown. You should notice that this transfer function does not match the one we derived earlier. This is because 20-sim makes small mistakes when linearizing a model. You can see that in the numerator as well as in the denominator, an extra s appears. These s'es cancel each other out, so they don't have an effect on the behavior, but it is better when this transfer function is just correct. code Click on Edit → Reduce system, and accept the default tolerance. code Now the correct transfer function should appear. Now you have this transfer function in the Linear System Editor, you can analyze the system in frequency domain (Bode, Nyquist, Pole Zero) or time domain (Step).

Implementation of controller in frequency domain Since we have a transfer function of the system, we can use that to design a controller. We could do that the same way as in section 4.1, but we want to use a more sophisticated method. In 20-sim you can use the so called 'Controlled Linear System' block. This is a tool which combines a transfer function of the plant (model of the system), a transfer function of the controller with the power of the Linear System Editor. So you can design a controller and see the effect of this controller on the behaviour of the system from the same window. If you want to make the most use out of this tool, it is best if you already have a transfer function of your model. Luckily we made this transfer function it the previous section, so we can use that one. To do this, copy the transfer function to the clipboard.

code In the Linear System Editor, make sure you have the Transfer function selected as system description, and click on Edit → Copy. code If you had already closed this Linear System Editor, you can repeat section 4.2 or calculate it by hand. We don't need the iconic model anymore, so we open a new model. code File → New → Graphical Model code In this new model, we are going to use the ControlledLinearSystem tool. In this tool, we can define our plant (transfer function of the model), by pasting the, just copied, transfer function.

code Library → Signal → Control → Controlled Linear Systems → ControlledLinearSystem, and place this block onto the worksheet. Double click this block to open it. Make sure that 'Plant (P)' is selected as subsystem, and click on Edit → Paste. code

The transfer function of the plant should be shown in the window. You can also put in this transfer function manually, by using the edit button.

Like in the Linear System Editor, it is now possible to show the bode plot, pole-zero and Nyquist plot for this plant. Also a step response can be shown. These plots are the plots of the selected Sub-System (top left in figure 10), so if you select the controller C, than the plot is for the controller. On the left side of this Sub system window, are the real sub-systems. On the right there are the loop-transfers. So the loop transfer (L) is the open loop transfer of the controller and plant. The Sensitivity (S) is the sensitivity function. The Complementary Sensitivity (T) is the closed loop response.

So if you would like to design a controller for this system (Plant), these plots are very useful!

Now we are going to implement a controller in this editor. We have to select the Compensator/Controller (C) as sub-system, and we can edit it's transfer function with the 'edit' button. It is also possible to use the Filter editor, in which you can choose a controller and set the parameters, exactly the same as the Controller Design Wizard in 4.1.

code Select the Compensator (C) as subsystem and click on Filter. In this Filter Editor, select the PD Controller and set the parameters to Kp=15, Kd=1 and Fd=1. Now use the 'Linear System Editor' button to place this PD Controller into the Controller block of the Controller Design Editor (yes). Click on OK to close this window and do not save the model. Now the transfer function of the PD controller is shown in the Controller Design Editor. code



We can look at the open loop response of the system by selecting the Loop Transfer (L) as subsystem and show the bode plot. If we want to see a step response of the closed loop feedback system, we can select the Complementary Sensitivity (T) and plot the step response (figure 11).