Multidomain—A Servo Mechanism
This example shows how to develop a servo mechanism model step by step in SystemModeler. It illustrates the multi-engineering capabilities and shows how you can use Simulation Center to analyze models created in Model Center, synthesize controllers, and carry out comparison studies.
MODELS USED IN THIS TUTORIAL
|DCMotor | StiffAxis | WeakAxis | StiffServoMechanism | WeakServoMechanism|
A simple dynamic model of a controlled DC motor consists of a variable voltage source, a resistor, an inductor, and an electromotoric force element representing the coupling between electric energy and mechanical energy provided by the magnetic field in the DC motor. The motor axis is represented by a rotating mass or inertia.
All of these components can be found in the Modelica Standard Library, included with SystemModeler. With the help of drag-and-drop, they can be used to compose the model as illustrated in the figure below.
The Diagram View of a DC motor in Model Center.
To build this model, we need to create a new model, find the appropriate components, drag and drop the components into the diagram area, and finally connect the components using the Connection Line Tool.
We begin by creating a new model with the name DCMotor. The components that we will use are all available in the Modelica Standard Library. To locate the components, we can either search for them, or if we know their exact location, open the package that contains them in the Class Browser. We will show how to do both.
You should see the top 10 matches for "step" in the Class Browser. The component we want to use is the Modelica.Blocks.Sources.Step component, highlighted in the figure above.
The signal voltage component is located in the Modelica.Electrical.Analog.Sources package. As we know the exact location of the component, we will use the tree view of the Class Browser and expand the branches of the tree all the way down to the branch that represents the package Sources, in which the component is located.
As you can see, the Modelica package contains several packages. We will continue by expanding the Electrical package, followed by the Analog package, and finally the Sources package, in which we will find the signal voltage component.
Add the SignalVoltage component to the DCMotor by dragging it to the Diagram View of the class window.
We have now added two of the seven components. The remaining four electrical components (Resistor, Inductor, Ground, and EMF) are all found in the Modelica.Electrical.Analog.Basic package. As we already have the Modelica.Electrical.Analog package expanded, we can easily locate the Basic package and expand it in order to find the remaining components.
Expanding the Modelica.Electrical.Analog.Basic package.
When you have added the electrical components to the DCMotor model, there is only one component left to add, the inertia. It is located in the Modelica.Mechanics.Rotational.Components package. You can choose if you want to search for it or browse to it directly by expanding the Modelica, Mechanics, Rotational, and Components packages.
For instance, to connect the ground to the negative pin of the signal voltage component, place the mouse cursor above the ground pin, press the left mouse button, and hold it down while moving the mouse cursor to the negative pin of the signal voltage component. To make the connection, release the mouse button.
While dropping and connecting the components, Model Center generates the Modelica code corresponding to the actions. Switch to the Modelica Text View to view the textual representation of the model. In the textual representation of the model, each component is declared, and each connection between two components is represented by connect equations in the equation section.
The order of the declarations and equations depends on in which order you dropped the components and made the connections. Therefore, the order of the declarations and equations may be slightly different in your model. Also, for readability, all graphical annotations have been removed from the definition of the DCMotor above.
The DCMotor model is now complete and possible to simulate. First, however, we want to specify certain simulation settings. Click the down arrow next to the Simulate Class button in the toolbar and choose Experiment Setup. In the Class Properties dialog box that pops up, set the simulation time to 25 seconds by editing the Stop time. Clicking OK or pressing Enter will apply the settings to the model and automatically update the experiment annotations in the text view. Now click the Simulate Class button in the toolbar to open Simulation Center and simulate the model.
Setting the simulation time to 25 seconds for the DCMotor model.
Plotting inertia1.w and signalVoltage1.v for the DCMotor model with default parameter values.
It is also easy to change parameter values in order to modify the system behavior. We will change the resistance of the resistor, the inductance of the inductor, and the moment of the inertia in order to yield a damped step response instead of an oscillative step response.
Switch to the Parameters view in the Experiment Browser. To edit a parameter value in the Parameters view, double-click the current value. Set the resistance of resistor1 to 10 ohm, the inductance of inductor1 to 0.1 H, and the moment of inertia1 to 0.3 kgm.
Plotting inertia1.w and signalVoltage1.v for the DCMotor model with customized parameter values.
In this section we will begin by developing a stiff axis model, study its step response by adding a step torque as illustrated below, and show how the axis can be more accurately modeled by including an additional weakness to the stiff axis model.
We begin by developing the stiff axis model. The components (Step, Torque, Inertia, and IdealGear) of the model can all be found by expanding the Modelica.Blocks.Sources, Modelica.Mechanics.Rotational.Sources, and Modelica.Mechanics.Rotational.Components packages in the Class Browser, or by simply searching for them. You can give the model any name you want. The different stages of the model are also available in the IntroductoryExamples.MultiDomain package.
The Diagram View of the IntroductoryExamples.MultiDomain.StiffAxis model.
Give the ratio parameter a value of 3. This means that angles and angular velocity are amplified three times and the torque is attenuated by a factor of three from one side of the gear to the other. Also, change the start time of the step source by changing the value of the parameter startTime to 1 second.
After simulating the system for 6 seconds, we observe that a constant torque results in a constant angular acceleration, i.e. a ramp in angular velocity and a square curve for the angle of the axis, as seen below.
Plotting the torque, the angular velocity of inertia2, and the angle of inertia2 for the IntroductoryExamples.MultiDomain.StiffAxis model.
By including an additional weakness, the axis can be more accurately modeled. This is possible by substituting the above axis model with a model consisting of two rotating masses connected by a torsion spring, according to the figure below. The torsion spring is found in the Modelica.Mechanics.Rotational.Components package.
The Diagram View of the IntroductoryExamples.MultiDomain.WeakAxis model.
Component inertia1 has been given a moment of 1 kgm, whereas inertia2 and inertia3 have moments of 0.5 kgm. The spring constant of spring1 is set to 5 Nm/rad. We will simulate this subsystem for 6 seconds and study the result (see below). Note that inertia3, and not inertia2 as earlier, is the last element of the axis, and is therefore the selected plot variable.
Plotting the torque, the angle of inertia3, and the angular velocity of inertia3 for the IntroductoryExamples.MultiDomain.WeakAxis model.
Make a simple DC motor with a torsional spring to the outgoing shaft and another inertia element. Simulate and study the results. Adjust some parameters and compare results. You may also want to add an input torque and connect it to inertia2, then study the system.
The structure of the control system is shown in the schematic picture below. This system consists of an input signal, a sensor, a feedback loop, and a regulator. The physical system consists of the DC motor and one of the axis systems. Since the physical system has negative static gain, the PI gain must also be negative.
We begin by developing a control system for the DC motor and the stiff axis developed earlier. As seen in the figure below, three new components are introduced: a feedback component, a PI controller, and a speed sensor.
The Diagram View of the IntroductoryExamples.MultiDomain.StiffServoMechanism model.
Plotting the angular velocity of inertia1 and inertia2 for the IntroductoryExamples.MultiDomain.StiffServoMechanism model.
Until now we have used default parameters for the controller. By varying the controller gain k, we can control the response. In this case, we vary the gain from 1 to 2 by intervals of 0.25. We can compare the results of all the simulations by creating a new experiment for each simulation and then plotting the results in the same window. New experiments are created by choosing New from the File menu in Simulation Center. Set the appropriate parameter values for each experiment, simulate, and plot the results.
Plotting the angular velocity of inertia1 and inertia2 for the IntroductoryExamples.MultiDomain.StiffServoMechanism model with different controller gain.
The Diagram View of the IntroductoryExamples.MultiDomain.WeakServoMechanism model.
In this section, we will study how sensitive our control design is to changes of different system parameters. This is done using the CVODES solver that supports forward sensitivity analysis. The sensitivity si(t) for a state yi(t) with respect to the parameter p is given by
Let us study the sensitivity of our control design with respect to the three inertias in WeakServoMechanism. To do so, we select the CVODES solver in the Settings view and check the SA checkboxes in the Parameters view for inertia1.J, inertia2.J, and inertia3.J.
The screen shot below shows the sensitivities for inertia3.w with respect to inertia1.J, inertia2.J, and inertia3.J. There we can see that inertia1.J has a minor impact on the solution of inertia3.w at the beginning of the simulation. This impact diminishes toward the end of the simulation. Furthermore, inertia2.J has a negligible impact on the solution during the whole simulation. inertia3.J, on the other hand, has a significantly larger impact on the solution. From this we can conclude that our control design is most sensitive to changes of inertia3.J.
- WeakServoMechanism 2: changing inertia1.J has some impact at the beginning of the simulation, but it diminishes toward the end.
- WeakServoMechanism 4: changing inertia3.J has the most impact; it leads to a phase shift of the oscillations as well as increased amplitude.