Example: DC Motor Speed Modeling in Simulink


Physical setup
Building the model
Open-loop response
Extracting the Model
Implementing PI control
Closed-loop response

Physical setup

A common actuator in control systems is the DC motor. It directly provides rotary motion and, coupled with wheels or drums and cables, can provide transitional motion. The electric circuit of the armature and the free body diagram of the rotor are shown in the following figure:

For this example, we will assume the following values for the physical parameters.

* moment of inertia of the rotor (J) = 0.01 kg.m^2/s^2
* damping ratio of the mechanical system (b) = 0.1 Nms
* electromotive force constant (K=Ke=Kt) = 0.01 Nm/Amp
* electric resistance (R) = 1 ohm
* electric inductance (L) = 0.5 H
* input (V): Source Voltage
* output (theta): position of shaft
* The rotor and shaft are assumed to be rigid

The motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, is related to the rotational velocity by the following equations:

In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant).

Building the Model

This system will be modeled by summing the torques acting on the rotor inertia and integrating the acceleration to give the velocity. Also, Kirchoff's laws will be applied to the armature circuit.

First, we will model the integrals of the rotational acceleration and of the rate of change of armature current.

Next, we will start to model both Newton's law and Kirchoff's law. These laws applied to the motor system give the following equations:

The angular acceleration is equal to 1/J multiplied by the sum of two terms (one pos., one neg.). Similarly, the derivative of current is equal to 1/L multiplied by the sum of three terms (one pos., two neg.).

Now, we will add in the torques which are represented in Newton's equation. First, we will add in the damping torque.

Next, we will add in the torque from the armature.

Now, we will add in the voltage terms which are represented in Kirchoff's equation. First, we will add in the voltage drop across the coil resistance.

Next, we will add in the back emf from the motor.

The third voltage term in the Kirchoff equation is the control input, V. We will apply a step input.

You can download a model file for the complete system here.

Open-loop response

To simulate this system, first, an appropriate simulation time must be set. Select Parameters from the Simulation menu and enter "3" in the Stop Time field. 3 seconds is long enough to view the open-loop response. The physical parameters must now be set. Run the following commands at the MATLAB prompt: Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished, double-click on the scope and hit its autoscale button. You should see the following output.

Extracting a Linear Model into MATLAB

A linear model of the system (in state space or transfer function form) can be extracted from a Simulink model into MATLAB. This is done through the use of In and Out Connection blocks and the MATLAB function linmod. First, replace the Step Block and Scope Block with an In Connection Block and an Out Connection Block, respectively (these blocks can be found in the Connections block library). This defines the input and output of the system for the extraction process.

Save your file as "motormod.mdl" (select Save As from the File menu). MATLAB will extract the linear model from the saved model file, not from the open model window. At the MATLAB prompt, enter the following commands:

You should see the following output, providing both state-space and transfer function models of the system. To verify the model extraction, we will generate an open-loop step response of the extracted transfer function in MATLAB. Enter the following command in MATLAB. You should see the following plot which is equivalent to the Scope's output.

Implementing Lag Compensator Control

In the motor speed control root locus example a Lag Compensator was designed with the following transfer function.

To implement this in Simulink, we will contain the open-loop system from earlier in this page in a Subsystem block.

Now, we will insert a Lag Compensator into a closed-loop around the plant model. First, we will feed back the plant output.

The output of the Sum block will provide the error signal. We will feed this into a Lag Compensator.

Finally, we will apply a step input and view the output on a scope.

You can download our version of the closed-loop system here.

Closed-loop response

To simulate this system, first, an appropriate simulation time must be set. Select Parameters from the Simulation menu and enter "3" in the Stop Time field. The design requirements included a settling time of less than 2 sec, so we simulate for 3 sec to view the output. The physical parameters must now be set. Run the following commands at the MATLAB prompt: Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished, double-click on the scope and hit its autoscale button. You should see the following output.


Simulink Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam

Motor Speed Examples
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

Tutorials
MATLAB Basics | MATLAB Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink Basics | Simulink Modeling | Examples