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
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.
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, ζ, and the natural frequency, ω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
sys1 ≔ DynamicSystemsNewSystems+3s2−3⋅s+5:
DynamicSystemsPrintSystemsys1
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=s+3s2−3⁢s+5
As mentioned above, the desired region for the closed-loop poles is defined by the damping ratio, ζ, and the natural frequency, ωn. For this example, the values of 0.7 and 5/2 have been chosen for the damping ratio and natural frequency, respectively.
ζ1≔0.7
0.7
ωn1≔52
52
Based on the values of ζ1 and ω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.
solution1≔ControlDesignFeasibleGainssys1,ζ1, ωn1, 'output'=samplepoints, 'condition' =all, posgains=true, controller= 'PI'
K=20,Ki=56,K=22,Ki=64,K=3544762151115137438953472,Ki=64
ControlDesignFeasibleGainssys1,ζ1, ωn1, 'output' =region, 'condition' =all, 'posgains' =false, 'controller' = 'PI'
For this example, we will use the gain values for kc and ki as provided in (4)
kp1≔rhssolution121;ki1≔rhssolution122
64
Using these gain values, the transfer function for the PI controller can be determined as:
Gc1 ≔ DynamicSystemsNewSystemkp1+ki1s:
DynamicSystemsPrintSystemGc1
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=22⁢s+64s
At this point, we can automatically obtain the transfer function for the closed-loop system using the command ControlDesign[PIDClosedLoop].
ClosedLoopSys1 ≔ ControlDesignPIDClosedLoopsys1,Gc1:
DynamicSystemsPrintSystemClosedLoopSys1
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=y1_ref⁡soutputvariable=y1⁡stf1,1=22⁢s2+130⁢s+192s3+19⁢s2+135⁢s+192
As expected, the poles of the closed-loop reside in the region defined by ζ1 and ωn1.
ControlDesignRegionPolesClosedLoopSys1,ζ1,ωn1
The pole locations can be determined using the following command:
poles≔DynamicSystemsZeroPolePlotClosedLoopSys1,output=data2:
Pole Locations
poles1 = −8.56867710107268−5.44581967628199⁢I
poles2 = −8.56867710107268+5.44581967628199⁢I
poles3 = −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.
p1≔DynamicSystemsResponsePlotClosedLoopSys1,Step, 'duration' =5, 'numpoints' =300, 'color' =blue, 'legend' =Closed Loop Response, 'labels' =time,Amplitude:
p2≔DynamicSystemsResponsePlotsys1,Step, 'duration' =3, 'numpoints' =300, 'color' =red, 'legend' = Open Loop Response, 'labels' =time,Amplitude:
plotsdualaxisplotp1,p2
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:
sys2 ≔ DynamicSystemsNewSystem3s2+3⋅s+5:
DynamicSystemsPrintSystemsys2
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=3s2+3⁢s+5
Let us assume that the desired closed-loop pole locations are:
poles2≔−4+2⋅I,−4−2⋅I,−52
−4+2⁢I,−4−2⁢I,−52
Using the ControlDesign[DominantPole] command we can obtain the PID controller transfer function
Gc2≔ControlDesignDominantPolesys2,poles2, 'controller' =PID, 'returntype' = system: DynamicSystemsPrintSystemGc2;
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=15⁢s2+70⁢s+1006⁢s
ClosedLoopSys2≔ControlDesignPIDClosedLoopsys2, Gc2:DynamicSystemsPrintSystemClosedLoopSys2
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=y1_ref⁡soutputvariable=y1⁡stf1,1=15⁢s2+70⁢s+1002⁢s3+21⁢s2+80⁢s+100
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.
p3≔DynamicSystemsResponsePlotClosedLoopSys2,Step,duration=7,numpoints=300,color=blue,legend=Closed Loop Response,parameters=a=3,b=5,c=2:
p4≔DynamicSystemsResponsePlotsys2,Step,duration=7,numpoints=300, color=red, legend = Open Loop Response,parameters=a=3,b=5,c=2:
plotsdisplayp3,p4, labels=time,Amplitude
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.
sys3 ≔ NewSystem70⋅s+1s+25:
DynamicSystemsPrintSystemsys3
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=70⁢s+70s5+10⁢s4+40⁢s3+80⁢s2+80⁢s+32
The system gain margin (in decibels) and associated crossover frequency (in rad/sec) is:
DynamicSystemsGainMarginsys3,decibels=true
3.736886602,2.329625869
Similarly, the system phase margin (in degrees) and crossover frequency (in rad/sec) is:
DynamicSystemsPhaseMarginsys3,radians=false
29.28289234,1.826456270
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, 15 dB and 60°, respectively.
Gc3 ≔ ControlDesignGainPhaseMarginsys3,15,60, 'controller' =PID, 'decibels' =true, 'radians' =false, 'returntype' = system: DynamicSystemsPrintSystemGc3;
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=0.1091140582⁢s2+0.1653439858⁢s+0.2796556965s
ClosedLoopSys3 ≔ ControlDesignPIDClosedLoopsys3, Gc3:
DynamicSystemsPrintSystemClosedLoopSys3
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=y1_ref⁡soutputvariable=y1⁡stf1,1=7.637984074⁢s3+19.21206308⁢s2+31.14997776⁢s+19.57589876s6+10.⁢s5+40.⁢s4+87.63798407⁢s3+99.21206308⁢s2+63.14997776⁢s+19.57589876
The gain and phase margin and crossover frequencies for the loop transfer function are shown below. These values exceed the minimum requirements specified above.
LoopTf≔DynamicSystemsTransferFunctionsys3:-tf1,1⋅Gc3:-tf1,1:
DynamicSystemsGainMarginLoopTf, decibels=true
24.84114154,4.262178342
DynamicSystemsPhaseMarginLoopTf, radians=false
62.28336593,0.5475206098
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.
p5≔DynamicSystemsResponsePlotClosedLoopSys3,Step,duration=20,numpoints=300,color=blue,legend=Closed Loop Response:
p6≔DynamicSystemsResponsePlotsys3,Step,duration=20,numpoints=300, color=red, legend = Open Loop Response:
plotsdisplayp5,p6, labels=time,Amplitude
The bode plots of the open-loop system and the loop transfer function are shown below.
DynamicSystemsBodePlotsys3, color=Red
DynamicSystemsBodePlotLoopTf,color=Blue
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.
sys4 ≔ NewSystem5s+1⋅3⋅ s+1⋅5⋅ s+1:
DynamicSystemsPrintSystemsys4
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=515⁢s3+23⁢s2+9⁢s+1
The desired closed-loop time constant t is 1.0 second (for a settling time of approximately 6⋅τ=6 seconds).
τ≔1.0
1.0
infolevelControlDesign≔3:
pidtf ≔ ControlDesignPIDAutosys4, τ, 'returntype' = system: DynamicSystemsPrintSystempidtf
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=2.359777777⁢s2+1.136444444⁢s+0.13333333330.02333333333⁢s2+s
ClosedLoopSys4 ≔ ControlDesignPIDClosedLoopsys4, pidtf:
DynamicSystemsPrintSystemClosedLoopSys4
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=y1_ref⁡soutputvariable=y1⁡stf1,1=11.79888888⁢s2+5.682222220⁢s+0.66666666650.3500000000⁢s5+15.53666667⁢s4+23.21000000⁢s3+20.82222221⁢s2+6.682222220⁢s+0.6666666665
p7≔DynamicSystemsResponsePlotClosedLoopSys4,Step,duration=30,numpoints=300,color=blue,legend=Closed Loop Response:
p8≔DynamicSystemsResponsePlotsys4,Step,duration=30,numpoints=300, color=red, legend = Open Loop Response:
plotsdisplayp7,p8, labels=time,Amplitude
Verify the resulting closed-loop settling time
tsettling ≔ DynamicSystemsStepPropertiesClosedLoopSys47
6.04634199312517,1.02000000000000
Download Help Document