Skip to content

Commit f410c6e

Browse files
committed
Add components.md
1 parent 02a1877 commit f410c6e

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

docs/components.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## Generic control components
2+
A number of components (struct Types plus functions working on these types) of this package are generic and can be used for any type of controller.
3+
4+
They are documented on this page.
5+
6+
### Types
7+
```julia
8+
Integrator
9+
UnitDelay
10+
RateLimiter
11+
Mixer_2D
12+
Mixer_3D
13+
```
14+
#### Usage of the Integrator
15+
```julia
16+
int = Integrator()
17+
int = Integrator(0.05, 2, 3) # dt, integration constant, inital output
18+
reset(int) # reset the integrator
19+
input = 2
20+
out = calc_output(int, input) # calculate the output
21+
on_timer(int) # must be called on each timestep
22+
```
23+
#### Usage of UnitDelay
24+
```julia
25+
ud = UnitDelay()
26+
for i in 1:3
27+
out = calc_output(ud, i) # updates the input and calculates the output
28+
on_timer(ud) # next timestep
29+
println(out)
30+
end
31+
```
32+
Expected output: `0.0 1.0 2.0`
33+
34+
#### Usage of RateLimiter
35+
```julia
36+
using KiteControllers, ControlPlots
37+
rl = RateLimiter(1.0, 0.8)
38+
input = [0,0,1,2,3,3,3,3,3,2,1,0,0,0,0,0]
39+
out = zeros(16)
40+
for i in 1:16
41+
out[i] = calc_output(rl, input[i])
42+
on_timer(rl)
43+
end
44+
plot(1:16, [input, out]; labels=["input", "output"])
45+
```
46+
Expected output:
47+
<p align="center"><img src="./rate_limiter.png" width="500" /></p>
48+
49+
### Mixer_2D
50+
This component is equivalent to the following model:
51+
<p align="center"><img src="./mixer_2ch.png" width="500" /></p>
52+
It has two analog inputs, one digital input and one analog output. It selects either input a or input b depending on the value of the digital input and implements soft switching with a blend time t_blend.
53+
54+
```julia
55+
m2 = Mixer_2CH(0.2, 1.0) # dt=0.2s, t_blend = 1.0s
56+
x = ones(10)
57+
y = 2*x
58+
out = zeros(10)
59+
for i in 1:length(x)
60+
in1=x[i]
61+
in2=y[i]
62+
out[i] = calc_output(m2, x[i], y[i])
63+
select_b(m2, i > 2)
64+
on_timer(m2)
65+
end
66+
@test all(out .≈ [1.0, 1.0, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.0, 2.0])
67+
```
68+
### Mixer_3D
69+
This component is equivalent to the following model:
70+
<p align="center"><img src="./mixer_3ch.png" width="500" /></p>
71+
It has three analog inputs, two digitals input and one analog output. It selects either input a or input b or input c depending on the values of the digital inputs and implements soft switching with a blend time t_blend.
72+
73+
Example:
74+
```julia
75+
for i in 1:SAMPLES
76+
if time(i) T1
77+
select_b(mix3, true)
78+
elseif time(i) T2
79+
select_c(mix3, true)
80+
elseif time(i) T3
81+
select_c(mix3, false)
82+
end
83+
factor_b[i] = mix3.factor_b
84+
factor_c[i] = mix3.factor_c
85+
out[i] = calc_output(mix3, SIN1[i], SIN2[i], NOISE[i])
86+
on_timer(mix3)
87+
end
88+
```
89+
You can find the full example under the name `test_mixer3.jl` in the test folder.
90+
<p align="center"><img src="./mixer3.png" width="500" /></p>
91+
92+
Continue with [README](../README.md)

0 commit comments

Comments
 (0)