In this example, we will show how to design a PID controller for controlling the position of a DC motor shaft. We will apply the Ziegler-Nichols method for empirically tuning the PID controller using Collimator.
The motor is conceptually modeled as in Figure 1 with the parameters given in Table 1.
Table 1 DC motor model parameters:
\begin{array} {|l|l|}\hline Symbol & Description & Value & Unit \\ \hline R & \text{Shunt Resistance} & 4 & \Omega \\ \hline L & \text{Coil inductance} & .25 & H \\ \hline K & \text{Motor Electromotive/torque constant} & .05 & N.m/A \\ \hline j & \text{Rotor intertia} & .02 & Kg.m2 \\ \hline b & \text{Friction constant} & 0.1 & N.m.s \\ \hline \end{array}
The transfer function of the DC motor position to the input voltage is described in the following Equation:
$$\frac{Φ(s)}{U(s)} =\frac{K}{LJs^3+(RJ+Lb) s^2+(Rb+K^2 )s}$$
We can build the simulation diagram for the DC motor position with the PID controller using Collimator's model editor as in Figure 2. We have also added a disturbance to later assess the disturbance rejection capability of the tuned controller.
We configure the DC Motor Position block from the in order to define the transfer function with the following parameters:
$$Numerator= [0.05]$$
$$Denominator= [0.005,0.105,0.4025,0]$$
Then, we add the controller parameters to the model parameters configuration tab:
Before we start analyzing the model and tuning the controller, we will need to import some useful libraries:
We will also define a function that returns the step response information as overshoot, rising time, and settling time:
The first step is to list the available models within our workspace and define a variable that links the simulation diagram within the notebook.
Then, we run a test simulation to check that we implemented our model correctly with no syntactical error:
To tune the PID controller, we begin with a simple P controller with \(K_p=1\)
The step response for the DC motor position with the P controller is shown from the visualizer in Figure 4.
The initially tuned P controller yields a very slow step response:
\begin{array} {|l|l|}\hline \text{Overshoot} & 0.00000\% \\ \hline \text{Raise Time (90%) } & 18.080000s \\ \hline \text{Settling time (2%)} & 30.080000s \\ \hline \end{array}
Therefore, we will consider the Ziegler-Nichols table for empirical tuning of the PID controller. The Ziegler-Nichols tuning rule is defined in Table 2
Table 2 Ziegler-Nichols tuning rules:
\begin{array} {|l|l|}\hline \text{Controller Type} & Kp & Ki & Kd \\ \hline P & 0.5K_u & 0 & 0 \\ \hline PI & 0.45K_u & 0.54\frac{K_u}{T_u} & 0 \\ \hline PD & 0.8K_u & 0 & 0.1K_uT_u \\ \hline \text{PID} 1 & 0.6K_u & 1.2\frac{K_u}{T_u} & 0.075K_uT_u \\ \hline \text{PID} 2 & 0.33K_u & 0.66\frac{K_u}{T_u} & 0.11K_uT_u \\ \hline \text{PID} 3 & 0.20K_u & 0.40\frac{K_u}{T_u} & 0.066K_uT_u \\ \hline \end{array}
The tuning rules depend on determining the ultimate gain \(K_u\) and the oscillation period \(T_u.\) To determine these values, we perform a sweep for the P gain until we get a pure oscillatory response:
From Figure 5, we can see that the ultimate gain is and the ultimate period is approximately \(T_u. = 0.65\).
Consequently, we apply the extracted gain to find the PID controller gains as defined in the Ziegler-Nichols tuning rules:
From the step responses, we can see that “PID 2” yields the best step response among the available controllers. Therefore, we will have another look at the “PID 2” controller to investigate the step response the characteristics:
Finally, we investigate the tuned PID controller parameters in the model editor to further study the disturbance rejection of the controller. The characteristics of controller disturbance rejection are illustrated in Figure 8.