PID Control Design - MapleSim Help







Using the MapleSim Control Design Toolbox to Design a PID Controller

 1. Introduction 2. Pole Placement Method 3. Exact Pole Placement Method 4. Gain-Phase Margin Method 5. Automatic Tuning

 1. Introduction This worksheet illustrates how the MapleSim Control Design Toolbox can be used to design PID controllers using several methods. This worksheet is divided into 3 sections. In the first section, we will use the Pole Placement method to design a PI controller for a second-order system so that we can confine the closed-loop poles to a desired region. In the second section, we will use the Exact Pole Placement method to design a PID controller so that we can specify the exact location of the dominant poles. Finally, in the last section, we will use the Gain-Phase Margin method to design a PID controller for a fifth-order system.

2. Pole Placement Method

The Pole Placement method is a unique feature of the MapleSim ControlDesign toolbox. It allows you to specify a desired region for the closed-loop poles based on damping ratio, $\mathrm{ζ}$, and the natural frequency, $\mathrm{ωn}$.  In this section, we will show how the Pole Placement method can be used to design a PI controller for an arbitrary second-order system.

We can create a second-order system using the DynamicSystems[NewSystem] command

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{sys1}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{s}{+}{3}}{{{s}}^{{2}}{-}{3}{}{s}{+}{5}}\end{array}\right$ (1)

As mentioned above, the desired region for the closed-loop poles is defined by the damping ratio, $\mathrm{ζ}$, and the natural frequency, $\mathrm{ωn}$. For this example, the values of 0.7 and 5/2 have been chosen for the damping ratio and natural frequency, respectively.

$\mathrm{ζ1}≔0.7$

 ${0.7}$ (2)

$\mathrm{ωn1}≔\frac{5}{2}$

 $\frac{{5}}{{2}}$ (3)

Based on the values of $\mathrm{ζ1}$ and $\mathrm{ωn1}$, the command ControlDesign[FeasibleGain] provides you with the option to output a list of 3 possible gain values for the PI controller as sample designs for which all the closed-loop poles will lie in the desired region. Alternatively, the command gives you the option to plot a region of feasible gain values.

 $\left[{K}{=}{20}{,}{\mathrm{Ki}}{=}{56}\right]{,}\left[{K}{=}{22}{,}{\mathrm{Ki}}{=}{64}\right]{,}\left[{K}{=}\frac{{3544762151115}}{{137438953472}}{,}{\mathrm{Ki}}{=}{64}\right]$ (4)

For this example, we will use the gain values for $\mathrm{kc}$ and $\mathrm{ki}$ as provided in (4)

$\mathrm{kp1}≔\mathrm{rhs}\left(\left[\mathrm{solution1}\right]\left[2\right]\left[1\right]\right);\mathrm{ki1}≔\mathrm{rhs}\left(\left[\mathrm{solution1}\right]\left[2\right]\left[2\right]\right)$

 ${64}$ (5)

Using these gain values, the transfer function for the PI controller can be determined as:

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{Gc1}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{22}{}{s}{+}{64}}{{s}}\end{array}\right$ (6)

At this point, we can automatically obtain the transfer function for the closed-loop system using the command ControlDesign[PIDClosedLoop].

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{ClosedLoopSys1}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{y1_ref}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{22}{}{{s}}^{{2}}{+}{130}{}{s}{+}{192}}{{{s}}^{{3}}{+}{19}{}{{s}}^{{2}}{+}{135}{}{s}{+}{192}}\end{array}\right$ (7)

As expected, the poles of the closed-loop reside in the region defined by $\mathrm{ζ1}$ and $\mathrm{ωn1}$.

The pole locations can be determined using the following command:

$\mathrm{poles}≔\mathrm{DynamicSystems}\left[\mathrm{ZeroPolePlot}\right]\left(\mathrm{ClosedLoopSys1},\mathrm{output}=\mathrm{data}\right)\left[2\right]:$



 Pole Locations $\mathrm{poles}\left[1\right]$ = ${-}{8.56867710107268}{-}{5.44581967628199}{}{I}$  $\mathrm{poles}\left[2\right]$ = ${-}{8.56867710107268}{+}{5.44581967628199}{}{I}$ $\mathrm{poles}\left[3\right]$ = ${-}{1.86264579785464}$

The step response of the open and closed-loop system can be determined using the DynamicSystems[ResponsePlot] command. From the plots, we can see how the including of a PI controller was able to stabilize the system.

$\mathrm{plots}\left[\mathrm{dualaxisplot}\right]\left(\mathrm{p1},\mathrm{p2}\right)$

${}$

3. Exact Pole Placement Method

In this section, we will show how the Exact Pole Placement method is used to design a PID controller for a 2nd order system.

As in the previous section, the transfer function of the open loop system can be defined as follows:

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{sys2}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{3}}{{{s}}^{{2}}{+}{3}{}{s}{+}{5}}\end{array}\right$ (8)

Let us assume that the desired closed-loop pole locations are:

$\mathrm{poles2}≔\left[-4+2\cdot I,-4-2\cdot I,-\frac{5}{2}\right]$

 $\left[{-}{4}{+}{2}{}{I}{,}{-}{4}{-}{2}{}{I}{,}{-}\frac{{5}}{{2}}\right]$ (9)

Using the ControlDesign[DominantPole] command we can obtain the PID controller transfer function

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{15}{}{{s}}^{{2}}{+}{70}{}{s}{+}{100}}{{6}{}{s}}\end{array}\right$ (10)

At this point, we can automatically obtain the transfer function for the closed-loop system using the command ControlDesign[PIDClosedLoop].

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{y1_ref}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{15}{}{{s}}^{{2}}{+}{70}{}{s}{+}{100}}{{2}{}{{s}}^{{3}}{+}{21}{}{{s}}^{{2}}{+}{80}{}{s}{+}{100}}\end{array}\right$ (11)

The step response of the open and closed-loop system is shown in the following plots. The closed-loop response in addition to tracking the input signal is much faster than then open-loop response.

$\mathrm{p3}≔\mathrm{DynamicSystems}\left[\mathrm{ResponsePlot}\right]\left(\mathrm{ClosedLoopSys2},\mathrm{Step}\left(\right),\mathrm{duration}=7,\mathrm{numpoints}=300,\mathrm{color}=\mathrm{blue},\mathrm{legend}="Closed Loop Response",\mathrm{parameters}=\left[a=3,b=5,c=2\right]\right):$

${}$

4. Gain-Phase Margin Method

In this section, we will show how the Gain-Phase Margin method is used to design a PID controller for the following fifth-order system.

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{sys3}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{70}{}{s}{+}{70}}{{{s}}^{{5}}{+}{10}{}{{s}}^{{4}}{+}{40}{}{{s}}^{{3}}{+}{80}{}{{s}}^{{2}}{+}{80}{}{s}{+}{32}}\end{array}\right$ (12)

The system gain margin (in decibels) and associated crossover frequency (in rad/sec) is:

$\mathrm{DynamicSystems}\left[\mathrm{GainMargin}\right]\left(\mathrm{sys3},\mathrm{decibels}=\mathrm{true}\right)$

 $\left[{3.736886602}{,}{2.329625869}\right]$ (13)

Similarly, the system phase margin (in degrees) and crossover frequency (in rad/sec) is:

$\mathrm{DynamicSystems}\left[\mathrm{PhaseMargin}\right]\left(\mathrm{sys3},\mathrm{radians}=\mathrm{false}\right)$

 $\left[{29.28289234}{,}{1.826456270}\right]$ (14)

Using the ControlDesign[GainPhaseMargin] command we can obtain the PID gain values so that the desired gain and phase margin for the closed-loop system is at least,  and $60°$, respectively.

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.1091140582}{}{{s}}^{{2}}{+}{0.1653439858}{}{s}{+}{0.2796556965}}{{s}}\end{array}\right$ (15)

At this point, we can automatically obtain the transfer function for the closed-loop system using the command ControlDesign[PIDClosedLoop].

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{ClosedLoopSys3}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{y1_ref}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{7.637984074}{}{{s}}^{{3}}{+}{19.21206308}{}{{s}}^{{2}}{+}{31.14997776}{}{s}{+}{19.57589876}}{{{s}}^{{6}}{+}{10.}{}{{s}}^{{5}}{+}{40.}{}{{s}}^{{4}}{+}{87.63798407}{}{{s}}^{{3}}{+}{99.21206308}{}{{s}}^{{2}}{+}{63.14997776}{}{s}{+}{19.57589876}}\end{array}\right$ (16)

The gain and phase margin and crossover frequencies for the loop transfer function are shown below. These values exceed the minimum requirements specified above.

$\mathrm{LoopTf}≔\mathrm{DynamicSystems}\left[\mathrm{TransferFunction}\right]\left(\mathrm{sys3}:-\mathrm{tf}\left[1,1\right]\cdot \mathrm{Gc3}:-\mathrm{tf}\left[1,1\right]\right):$

 $\left[{24.84114154}{,}{4.262178342}\right]$ (17)

 $\left[{62.28336593}{,}{0.5475206098}\right]$ (18)

The step response of the open and closed-loop system is shown in the following plots. Unlike the open-loop response which was more than 100% off in the steady state, the closed-loop response now tracks the input signal.

$\mathrm{p5}≔\mathrm{DynamicSystems}\left[\mathrm{ResponsePlot}\right]\left(\mathrm{ClosedLoopSys3},\mathrm{Step}\left(\right),\mathrm{duration}=20,\mathrm{numpoints}=300,\mathrm{color}=\mathrm{blue},\mathrm{legend}="Closed Loop Response"\right):$

The bode plots of the open-loop system and the loop transfer function are shown below.

$\mathrm{DynamicSystems}\left[\mathrm{BodePlot}\right]\left(\mathrm{LoopTf},\mathrm{color}="Blue"\right)$

5. Automatic Tuning

In this section, we will show how to tune the parameters of a PID controller using a single tuning parameter t, which is equivalent to the desired time constant of the closed-loop system.

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{sys4}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{5}}{{15}{}{{s}}^{{3}}{+}{23}{}{{s}}^{{2}}{+}{9}{}{s}{+}{1}}\end{array}\right$ (19)

The desired closed-loop time constant t is 1.0 second (for a settling time of approximately $6\cdot \mathrm{τ}=6$ seconds).

$\mathrm{τ}≔1.0$

 ${1.0}$ (20)

$\mathrm{infolevel}\left[\mathrm{ControlDesign}\right]≔3:$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{2.359777777}{}{{s}}^{{2}}{+}{1.136444444}{}{s}{+}{0.1333333333}}{{0.02333333333}{}{{s}}^{{2}}{+}{s}}\end{array}\right$ (21)

$\mathrm{DynamicSystems}\left[\mathrm{PrintSystem}\right]\left(\mathrm{ClosedLoopSys4}\right)$

 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{y1_ref}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{11.79888888}{}{{s}}^{{2}}{+}{5.682222220}{}{s}{+}{0.6666666665}}{{0.3500000000}{}{{s}}^{{5}}{+}{15.53666667}{}{{s}}^{{4}}{+}{23.21000000}{}{{s}}^{{3}}{+}{20.82222221}{}{{s}}^{{2}}{+}{6.682222220}{}{s}{+}{0.6666666665}}\end{array}\right$ (22)

$\mathrm{p7}≔\mathrm{DynamicSystems}\left[\mathrm{ResponsePlot}\right]\left(\mathrm{ClosedLoopSys4},\mathrm{Step}\left(\right),\mathrm{duration}=30,\mathrm{numpoints}=300,\mathrm{color}=\mathrm{blue},\mathrm{legend}="Closed Loop Response"\right):$

Verify the resulting closed-loop settling time

 $\left[{6.04634199312517}{,}{1.02000000000000}\right]$ (23)