You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here we simulated a linear plant, in which case we were able to call `ControlSystems.lsim` specialized for linear systems. Below, we show two methods for simulation that works with a nonlinear plant, but we still use a linear system to make the comparison easier.
75
75
76
+
For comparison, we also perform the same simulation with a two degree-of-freedom PID controller
This example is identical to the one above except for using [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/) for the simulation, which makes it possible to consider more complex plants, in particular nonlinear ones.
@@ -89,7 +102,7 @@ We use `DiffEqCallbacks.PeriodicCallback`, in which we perform the PID-controlle
89
102
```julia
90
103
using DiscretePIDs, ControlSystemsBase, OrdinaryDiffEq, DiffEqCallbacks, Plots
91
104
92
-
Tf =15# Simulation time
105
+
Tf =30# Simulation time
93
106
K =1# Proportional gain
94
107
Ti =1# Integral time
95
108
Td =1# Derivative time
@@ -109,16 +122,17 @@ end
109
122
110
123
cb =PeriodicCallback(Ts) do integrator
111
124
p = integrator.p # Extract the parameter object from the integrator
112
-
(; C, r, d) = p # Extract the reference and disturbance from the parameter object
125
+
(; C, d) = p # Extract the reference and disturbance from the parameter object
113
126
x = integrator.u[1:P.nx] # Extract the state (the integrator uses the variable name `u` to refer to the state, in control theory we typically use the variable name `x`)
127
+
r = (integrator.t >=15) # Reference
114
128
y = (C*x)[] # Simulated measurement
115
129
u =pid(r, y) # Compute the control signal
116
130
integrator.u[P.nx+1:end] .= u # Update the control-signal state variable
0 commit comments