DC Motor Control Design
Given a model of a DC motor as a set of differential equations, we want to obtain both the transfer function and the state space model of the system. Then, we want to use the state space model to design a LQR controller and study the effect the R parameter in the LQR control design has on the controlled performance of the system.
System Definition
Parameters
Variables
System Models
Differential Equation Model
Transfer Function Model
State Space Model
Model Analysis
LQR Control Design
Step Responses
How varying R affects the System Response
A DC motor converts electrical signals (voltage and current) into mechanical motion. The electrical and mechanical characteristics can be illustrated by a circuit diagram and a free body diagram respectively (shown in the diagram above).
Define the Variables and the Parameters that describe the system.
Name
Value
Units
Moment of inertia of the motor (J)
kg⋅m2
Damping of the mechanical system (b)
N⋅m⋅s
Electromotive force constant (K)
N⋅mA
Motor coil resistance (R)
Ω
Motor coil inductance (L)
H
J=0.01,K=0.01,L=0.5,R=1,b=0.1
Description
Input Variables
Vt
Applied Voltage
Output Variables
Θt
Motor Shaft Angular Position
it
Motor Current
To derive the model of the system, first, we apply Kirchhoff's voltage law around the circuit. The back EMF is proportional to the angular velocity of the motor shaft. Using the DiffEquation command we get:
sysElectrical ≔ DiffEquationL⋅i't+R⋅it = Vt−K⋅θ't, Vt, θt: PrintSystemsysElectrical
Diff. Equationcontinuous1 output(s); 1 input(s)inputvariable=V⁡toutputvariable=θ⁡tde=L⁢ⅆⅆti⁡t+R⁢i⁡t=V⁡t−K⁢ⅆⅆtθ⁡t
Second, we model the mechanical component of the motor as a second order differential system with moment of inertia J and damping ratio of b. The torque is proportional to the current i(t) driving the motor.
sysMechanical ≔ DiffEquationJ⋅θ''t+b⋅θ't = K⋅it, it, θt: PrintSystemsysMechanical
Diff. Equationcontinuous1 output(s); 1 input(s)inputvariable=i⁡toutputvariable=θ⁡tde=J⁢ⅆ2ⅆt2θ⁡t+b⁢ⅆⅆtθ⁡t=K⁢i⁡t
The overall differential equation model in terms of the voltage, Vt, and angular position, Θt, is:
sysOverall ≔ DiffEquationL⋅i't+R⋅it = Vt−K⋅θ't, J⋅θ''t+b⋅θ't = K⋅it, Vt, θt: PrintSystemsysOverall
Diff. Equationcontinuous1 output(s); 1 input(s)inputvariable=V⁡toutputvariable=θ⁡tde={[L⁢ⅆⅆti⁡t+R⁢i⁡t=V⁡t−K⁢ⅆⅆtθ⁡t, J⁢ⅆ2ⅆt2θ⁡t+b⁢ⅆⅆtθ⁡t=K⁢i⁡t]
To obtain the transfer function model of our system, we convert the overall differential equation model (sysOverall) into a transfer function model using the TransferFunction command. TFopen is the open loop transfer function for the angular position Θt from the input Vt and is defined as:
TFopen ≔TransferFunctionsysOverall:PrintSystemTFopen
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=V⁡soutputvariable=θ⁡stf1,1=KJ⁢L⁢s3+J⁢R+L⁢b⁢s2+K2+R⁢b⁢s
The state space model of a system is defined as follows:
ⅆⅆt⁢xt=A⁢xt+B⁢ut
y(t)=C⁢x(t)+D⁢u(t)
u(t)
System input signal, p × 1 vector
y(t)
System output signal, m × 1 vector
x(t)
System state vector, n × 1 vector
A
System matrix, n × n matrix
B
Input matrix, n × p matrix
C
Output Matrix, m × n matrix
D
Direct through matrix, m × p matrix
For the case of the DC motor, the states x1(t), x2(t) and x3(t) represent current, it, angular position, Θt, and angular velocity, Θ't, respectively.
To obtain the state space model of our system, we convert the overall differential equation model (sysOverall) into a state space model using the StateSpace command.
SSopen ≔ StateSpacesysOverall:PrintSystemSSopen
State Spacecontinuous1 output(s); 1 input(s); 3 state(s)inputvariable=V⁡toutputvariable=θ⁡tstatevariable=x1⁡t,x2⁡t,x3⁡ta=−RL0−KL001KJ0−bJb=1L00c=010d=0
The ResponsePlot command can be used to plot the angular position Θt with parameter set, params, initial conditions, ic, and input voltage signal, Vin, defined below:
params
ic≔ θ0 = 0, Dθ0 = 0, i0 = 0
ic≔θ⁡0=0,D⁡θ⁡0=0,i⁡0=0
ResponsePlotTFopen,Heavisidet, output=θt, initialconditions=ic, parameters=params, duration=3, thickness=2,gridlines=true,title=Change of shaft position: theta(t), labels=time[sec], theta(t)[rad], labeldirections=horizontal,vertical, font=HELVETICA,10, labelfont=HELVETICA,10
The system can also be analyzed in the frequency domain. Substituting the parameter values into the open loop transfer function in (2.2.1) results in:
evalTFopen:-tf, params
0.010.005⁢s3+0.06⁢s2+0.1001⁢s
The above transfer function can be plotted as a magnitude plot and a phase plot.
BodePlotTFopen, parameters=params, hertz=true, thickness=2,labelfont=HELVETICA,10, font=HELVETICA,10
# LQR procedure
Our objective is to be able to rotate the shaft position, Θt, of the motor to specified desired positions. In control terms, this translates to minimizing the motor shaft position error. As such, we put higher weighting on the position state, x2(t), in the Q matrix in our LQR controller design.
A≔evalSSopen:-a,params;B≔evalSSopen:-b,params;
B≔2.00000000000
Qlqr
0.100010000.1
The controller gain for the full state feedback LQR controller is then computed using the custom procedure LQR( ). With the Q matrix defined in (3.1.2) and Rlqr=0.1 the result is the gain vector Kss given by:
Kss ≔ LQRA, B, Qlqr, Rlqr
Kss≔0.5238909487433373.162277660168380.322243623661871
The numeric solution can now be obtained for the step response of the open loop (uncontrolled) and closed loop (controlled) cases.
Open loop (uncontrolled) response
Closed loop (controlled) response
Input functions used examine the open loop and closed loop response are defined as:
InputSig;
PrintSystemDEopen
Diff. Equationcontinuous1 output(s); 1 input(s)inputvariable=V⁡toutputvariable=θ⁡tde={[ⅆⅆtx1⁡t=−R⁢x1⁡tL−K⁢x3⁡tL+V⁡tL, ⅆⅆtx2⁡t=x3⁡t, ⅆⅆtx3⁡t=K⁢x1⁡tJ−b⁢x3⁡tJ, θ⁡t=x2⁡t]
The open loop response is defined as:
PrintSystemsysOpenLoop
The closed loop response is defined as:
PrintSystemsysClosedLoop
Diff. Equationcontinuous4 output(s); 1 input(s)inputvariable=trim⁡toutputvariable=x1⁡t,x2⁡t,x3⁡t,V⁡tde={[ⅆⅆtx1⁡t=−R⁢x1⁡tL−K⁢x3⁡tL+V⁡tL, ⅆⅆtx2⁡t=x3⁡t, ⅆⅆtx3⁡t=K⁢x1⁡tJ−b⁢x3⁡tJ, θ⁡t=x2⁡t, V⁡t=−0.523890948743337415⁢x1⁡t−3.16227766016837997⁢x2⁡t+3.16227766016837997⁢trim⁡t−0.322243623661871481⁢x3⁡t]
The plot of the open loop state response is:
StatePlot1
The plot of the closed loop state response is:
StatePlot2
OutputPlot1
The plot of the closed loop angular position Θt step response is:
OutputPlot2
In the controlled case, the shaft position of the DC motor follows the step change in the desired position (defined by the step input) and settles into the desired steady state value as expected.
We want to vary the weighting factor R for the LQR controller to see how it affects the system output response.
The R factor is the weighting coefficient for the input signal. By increasing R, we are putting more penalty on the control signal.
As such, the resulting controller will try to minimize the control efforts used to achieve the desired output.
Consider the results obtained earlier for R = 0.1.
Step response
Control Effort
First, recall the system step response output for the case R=0.1 developed previously. This will serve as our benchmark for comparison.
For comparison, we define an energy-like quantity (square of the input voltage) to give us an idea of the cost or the control effort required in operating the DC motor. Here, we show the control effort over time for the case R = 0.1.
StepResponse
EffortPlot
Next, we generate the controller and the corresponding step time response for each value of R from 0.1 to 2. To compare the performance of each of the controllers, we define the control effort of the controller as the square of the input signal, summed over time. This associated control effort (or energy-like) value for each controller is the total cost in operating the individual controllers.
The following plot illustrates the total cost (integral of the energy like control function) for different values of R.
TotalCostPlot
To see the effect of varying R, you can drag the slider to select different values of R and observe the resulting step response and the control effort.
Max R
Min R
R =
Download Help Document