Skip to content

Commit 9094109

Browse files
committed
add comments
1 parent 4cf7319 commit 9094109

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,18 @@ Here we simulated a linear plant, in which case we were able to call `ControlSys
7676
For comparison, we also perform the same simulation with a two degree-of-freedom PID controller
7777
```julia
7878
using ControlSystemsBase, DiscretePIDs, Plots
79-
C = pid_2dof(K, Ti, Td; Ts)
80-
Gcl = feedback(P, C, W1=1, U2=2, W2=1, Z2=1, pos_feedback=true)
8179
t = 0:Ts:Tf
8280
u = [ones(length(t)) t .>= 15]' # Input signal [d; r]
81+
C = pid_2dof(K, Ti, Td; Ts, N=10)
82+
Gcl = feedback(P, C, W1=1, U2=2, W2=1, Z2=1, pos_feedback=true)
8383
simres = lsim(Gcl, u)
8484
plot(simres, plotu=true, lab=["y" "u" "d" "r"], layout=(2,1), sp=[1 2 2 1], ylabel="")
8585
```
8686
![Simulation result](https://github.com/user-attachments/assets/1267fc64-72f1-4560-ba66-ccf88bcae150)
8787

8888

89+
Please note: The result of simulation with a controller computed by `pid_2dof` will be _slightly_ different due to a difference in discretization. DiscretePIDs uses a forward-Euler approximation for the integrator and a backward Euler approximation for the derivative, while `pid_2dof` uses a Tustin approximation (default) for both.
90+
8991
### Example using DifferentialEquations.jl
9092

9193
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.
@@ -203,7 +205,7 @@ Once again, the output looks identical and is therefore omitted here.
203205
- The derivative term only acts on the (filtered) measurement and not the command signal. It is thus safe to pass step changes in the reference to the controller. The parameter $b$ can further be set to zero to avoid step changes in the control signal in response to step changes in the reference.
204206
- Bumpless transfer when updating `K` is realized by updating the state `I`. See the docs for `set_K!` for more details.
205207
- The total control signal $u(t)$ (PID + feedforward) is limited by the integral anti-windup.
206-
- The integrator is discretized using a forward difference (no direct term between the input and output through the integral state) while the derivative is discretized using a backward difference.
208+
- The integrator is discretized using a forward difference (no direct term between the input and output through the integral state) while the derivative is discretized using a backward difference. This approximation has the advantage that it is always stable and that the sampled pole goes to zero when $T_d$ goes to zero. Tustin's approximation gives an approximation such that the pole instead goes to $z = −1$ as $T_d$ goes to zero.
207209
- This particular implementation of a discrete-time PID controller is detailed in Chapter 8 of [Wittenmark, Björn, Karl-Erik Årzén, and Karl Johan Åström. ‘Computer Control: An Overview’. IFAC Professional Brief. International Federation of Automatic Control, 2002](https://www.ifac-control.org/publications/list-of-professional-briefs/pb_wittenmark_etal_final.pdf/view).
208210
- When used with input arguments of standard types, such as `Float64` or `Float32`, the controller is guaranteed not to allocate any memory or contain any dynamic dispatches. This analysis is carried out in the tests, and is performed using [AllocCheck.jl](https://github.com/JuliaLang/AllocCheck.jl).
209211

0 commit comments

Comments
 (0)