Harmonic Oscillator
1. System Definition
2. Design of a P controller
3. Design of a PI controller
4. Design of a PID controller
The model of a harmonic oscillator corresponds to a second order system with ut as the input and yt as the output. The system is defined by the angular frequency ω, the attenuation θ, and the gain A.
Parameters
Variables
Attenuation θ
Input ut
Angular frequency ω
Output yt
Gain A
The system is defined with the following differential equation
sysde≔ⅆ2ⅆt2⁢yt+2⁢ω⁢θ ⅆⅆt⁢y⁡t+ω2⁢yt=ω2⁢A⁢ut
sysde≔ⅆ2ⅆt2y⁡t+2⁢ω⁢θ⁢ⅆⅆty⁡t+ω2⁢y⁡t=ω2⁢A⁢u⁡t
The transfer function that results from this differential equation can be obtained using the DynamicSystems[TransferFunction] command.
withDynamicSystems:
systf≔TransferFunctionsysde,inputvariable=ut,outputvariable=yt:PrintSystemsystf
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u⁡soutputvariable=y⁡stf1,1=ω2⁢As2+2⁢ω⁢θ⁢s+ω2
The step response for the corresponding system can be observed by changing the slider values for θ and ω in the following application.
In this example, θ controls the damping, such that a system with θ<1 results in a system that is under damped and results in an overshoot. For the cases with θ>1⁢the system is over damped and the response has no overshoot. If θ=1 the system is critically damped, resulting in the fastest rise time of the system without overshooting the final value. The parameter ω is the natural frequency of the system.
The amplitude A is set to 1 for this example.
Uncontrolled Step Response
set θ value
set ω value
Pcontroller≔Kp:
OpenLoopEq≔Pcontroller⋅systf:-tf1,1
OpenLoopEq≔Kp⁢ω2⁢As2+2⁢ω⁢θ⁢s+ω2
ClosedLoopEq≔simplifyOpenLoopEq1+OpenLoopEq
ClosedLoopEq≔Kp⁢ω2⁢As2+2⁢ω⁢θ⁢s+Kp⁢ω2⁢A+ω2
ClosedLoopSys≔TransferFunctionClosedLoopEq:
PrintSystemClosedLoopSys
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=Kp⁢ω2⁢As2+2⁢ω⁢θ⁢s+Kp⁢ω2⁢A+ω2
The response to the system to changing proportional gain controller can be seen below. It is important to note that the P controller is not able to get the system to actually reach the desired final value. The controller has an offset error.
Controlled Step Response - P controller
θ value
ω value
Kp value
PIcontroller≔Kp+Kis
PIcontroller≔Kp+Kis
OpenLoopEq1≔PIcontroller⋅systf:-tf1,1
OpenLoopEq1≔Kp+Kis⁢ω2⁢As2+2⁢ω⁢θ⁢s+ω2
ClosedLoopEq1≔simplifyOpenLoopEq11+OpenLoopEq1
ClosedLoopEq1≔Kp⁢s+Ki⁢ω2⁢AA⁢Kp⁢s+A⁢Ki+s⁢ω2+2⁢ω⁢θ⁢s2+s3
ClosedLoopSys1≔TransferFunctionClosedLoopEq1:
PrintSystemClosedLoopSys1
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=A⁢Kp⁢ω2⁢s+A⁢Ki⁢ω2s3+2⁢ω⁢θ⁢s2+Kp⁢ω2⁢A+ω2⁢s+A⁢Ki⁢ω2
The effects of adjusting the proportional controller gain Kp and integral controller gain Ki values is displayed below. In most cases, the offset error can be eliminated by adding an integral component to the proportional controller.
It is important to note, that a system may become unstable and begin to oscillate out of control if the value of Ki is too large and the value of Kp too small (relative to Ki).
Controlled Step Response - PI controller
Ki value
PIDcontroller≔Kp + Kis+Kd⋅s
PIDcontroller≔Kp+Kis+Kd⁢s
OpenLoopEq2≔PIDcontroller⋅systf:-tf1,1
OpenLoopEq2≔Kp+Kis+Kd⁢s⁢ω2⁢As2+2⁢ω⁢θ⁢s+ω2
ClosedLoopEq2≔simplifyOpenLoopEq21+OpenLoopEq2
ClosedLoopEq2≔Kd⁢s2+Kp⁢s+Ki⁢ω2⁢As3+ω⁢A⁢Kd⁢ω+2⁢θ⁢s2+ω2⁢A⁢Kp+1⁢s+A⁢Ki⁢ω2
ClosedLoopSys2≔TransferFunctionClosedLoopEq2:
PrintSystemClosedLoopSys2
Transfer Functioncontinuous1 output(s); 1 input(s)inputvariable=u1⁡soutputvariable=y1⁡stf1,1=A⁢Kd⁢ω2⁢s2+A⁢Kp⁢ω2⁢s+A⁢Ki⁢ω2s3+Kd⁢ω2⁢A+2⁢ω⁢θ⁢s2+Kp⁢ω2⁢A+ω2⁢s+A⁢Ki⁢ω2
The system response to changes in the proportional, integral and derivative gains are shown below.
Controlled Step Response - PID controller
Kd value
Download Help Document