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
System Models
LQR Control Design


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).




System Definition


Define the Variables and the Parameters that describe the system.

Parameters


Name

Value

Units

Parameters

Moment of inertia of the motor ()



Damping of the mechanical system ()



Electromotive force constant ()



Motor coil resistance ()



Motor coil inductance ()





Retrieve Parameters Defined in Table


Variables


Name

Description

Input Variables


Applied Voltage

Output Variables


Motor Shaft Angular Position


Motor Current






System Models



Differential Equation Model


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 command we get:
 (2.1.1) 
Second, we model the mechanical component of the motor as a second order differential system with moment of inertia and damping ratio of . The torque is proportional to the current driving the motor.
 (2.1.2) 
The overall differential equation model in terms of the voltage, , and angular position, , is:
 (2.1.3) 


State Space Model


The state space model of a system is defined as follows:

Name

Description


System input signal, p × 1 vector


System output signal, m × 1 vector


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 , and represent current, , angular position, , and angular velocity, , respectively.
To obtain the state space model of our system, we convert the overall differential equation model ( into a state space model using command.
 (2.3.1) 


Model Analysis


The command can be used to plot the angular position with parameter set, , initial conditions, and input voltage signal, defined below:
 (2.4.1) 
 (2.4.2) 
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:
 (2.4.3) 
The above transfer function can be plotted as a magnitude plot and a phase plot.



LQR Control Design



Step Responses


LQR procedure
# LQR procedure
Our objective is to be able to rotate the shaft position, , 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, , in the Q matrix in our LQR controller design.
 (3.1.1) 
 (3.1.2) 
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 the result is the gain vector given by:
 (3.1.3) 
The numeric solution can now be obtained for the step response of the open loop (uncontrolled) and closed loop (controlled) cases.
Define Open loop and Closed loop responses
Open loop (uncontrolled) response

Closed loop (controlled) response

Input functions used examine the open loop and closed loop response are defined as:
 (3.1.4) 

Determine the open loop Differential Equation Model in terms of the State Space variables , and .
 (3.1.5) 

The open loop response is defined as:
 (3.1.6) 

The closed loop response is defined as:
 (3.1.7) 

The plot of the open loop state response is:

The plot of the closed loop state response is:

The plot of the open loop state response is:

The plot of the closed loop angular position step response is:



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.


How varying R affects the System Response


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.
Define Step response and Control Effort
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 energylike 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.





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 energylike) 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.
Procedure to calculate total cost
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.
Procedure controlling slider bar


