Skip to content

Commit e5e6ab7

Browse files
Merge pull request #41 from AayushSabharwal/new_docstrings
Electrical Component Docstrings
2 parents 4b081e6 + f74f1d4 commit e5e6ab7

File tree

8 files changed

+897
-137
lines changed

8 files changed

+897
-137
lines changed

docs/src/API/electrical.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ CurrentModule = ModelingToolkitStandardLibrary.Electrical
88
```@docs
99
Pin
1010
OnePort
11+
DigitalPin
1112
```
1213

1314
## Analog Components
1415

1516
```@docs
16-
Capacitor
1717
Ground
18-
Inductor
1918
Resistor
19+
Capacitor
20+
Inductor
2021
IdealOpAmp
2122
```
2223

@@ -30,7 +31,7 @@ PowerSensor
3031
MultiSensor
3132
```
3233

33-
## Analogue Sources
34+
## Analog Sources
3435

3536
```@docs
3637
ConstantVoltage
@@ -49,4 +50,33 @@ SquareCurrent
4950
TriangularCurrent
5051
CosineCurrent
5152
ExpSineCurrent
53+
```
54+
55+
## Digital Gates
56+
```@docs
57+
Not
58+
And
59+
Nand
60+
Or
61+
Nor
62+
Xor
63+
Xnor
64+
```
65+
66+
## Digital Components
67+
```@docs
68+
HalfAdder
69+
FullAdder
70+
MUX
71+
DEMUX
72+
Encoder
73+
Decoder
74+
```
75+
76+
## Digital Sources
77+
```@docs
78+
PulseDiff
79+
Set
80+
Reset
81+
Pulse
5282
```

src/Electrical/Analog/ideal_components.jl

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
"""
2-
Ground(;name)
2+
```julia
3+
function Ground(; name)
4+
```
35
4-
Ground of an electrical circuit. The potential at the ground node is zero. Every circuit must have one ground node.
6+
Ground node with the potential of zero and connector `g`. Every circuit must have one ground
7+
node.
8+
9+
# Connectors
10+
- `g`
511
"""
612
function Ground(;name)
713
@named g = Pin()
@@ -10,12 +16,25 @@ function Ground(;name)
1016
end
1117

1218
"""
13-
Resistor(;name, R=1.0)
19+
```julia
20+
function Resistor(; name, R = 1.0)
21+
```
22+
23+
Creates an ideal Resistor following Ohm's Law.
24+
25+
# States
26+
- `v(t)`: [`V`]
27+
The voltage across the resistor, given by `p.i * R`
1428
15-
Ideal linear electrical resistor.
29+
# Connectors
30+
- `p`
31+
Positive pin
32+
- `n`
33+
Negative pin
1634
1735
# Parameters:
18-
- `R`: [Ω] Resistance
36+
- `R`: [`Ω`]
37+
Resistance
1938
"""
2039
function Resistor(;name, R=1.0)
2140
@named oneport = OnePort()
@@ -28,13 +47,27 @@ function Resistor(;name, R=1.0)
2847
end
2948

3049
"""
31-
Capacitor(;name, C=1.0, v_start=0.0)
50+
```julia
51+
function Capacitor(; name, C = 1.0)
52+
```
53+
54+
Creates an ideal Capacitor.
55+
56+
# States
57+
- `v(t)`: [`V`]
58+
The voltage across the capacitor, given by `D(v) ~ p.i / C`
3259
33-
Ideal linear electrical capacitor.
60+
# Connectors
61+
- `p`
62+
Positive pin
63+
- `n`
64+
Negative pin
3465
3566
# Parameters:
36-
- `C`: [F] Capacity
37-
- `v_start`: [V] Initial voltage of capacitor
67+
- `C`: [`F`]
68+
Capacitance
69+
- `v_start`: [`V`]
70+
Initial voltage of capacitor
3871
"""
3972
function Capacitor(;name, C=1.0, v_start=0.0)
4073
@named oneport = OnePort(;v_start=v_start)
@@ -47,13 +80,27 @@ function Capacitor(;name, C=1.0, v_start=0.0)
4780
end
4881

4982
"""
50-
Inductor(;name, L=1.0e-6, i_start=0.0)
83+
```julia
84+
function Inductor(; name, L = 1.0)
85+
```
5186
52-
Ideal linear electrical inductor.
87+
Creates an ideal Inductor.
88+
89+
# States
90+
- `v(t)`: [`V`]
91+
The voltage across the inductor, given by `D(p.i) ~ v / L`
92+
93+
# Connectors
94+
- `p`
95+
Positive pin
96+
- `n`
97+
Negative pin
5398
5499
# Parameters:
55-
- `L`: [H] Inductance
56-
- `i_start`: [A] Initial current through inductor
100+
- `L`: [`H`]
101+
Inductance
102+
- `i_start`: [`A`]
103+
Initial current through inductor
57104
"""
58105
function Inductor(;name, L=1.0e-6, i_start=0.0)
59106
@named oneport = OnePort(;i_start=i_start)
@@ -66,11 +113,33 @@ function Inductor(;name, L=1.0e-6, i_start=0.0)
66113
end
67114

68115
"""
69-
IdealOpAmp(;name)
116+
```julia
117+
function IdealOpAmp(; name)
118+
```
70119
71120
Ideal operational amplifier (norator-nullator pair).
72-
The ideal OpAmp is a two-port. The left port is fixed to v1=0 and i1=0 (nullator).
73-
At the right port both any voltage v2 and any current i2 are possible (norator).
121+
The ideal OpAmp is a two-port. The left port is fixed to `v1 = 0` and `i1 = 0` (nullator).
122+
At the right port both any voltage `v2` and any current `i2` are possible (norator).
123+
124+
# States
125+
- `v1(t)`: [`V`]
126+
Voltage of left port
127+
- `v2(t)`: [`V`]
128+
Voltage of right port
129+
- `i1(t)`: [`A`]
130+
Current of left port
131+
- `i2(t)`: [`A`]
132+
Current of right port
133+
134+
# Connectors
135+
- `p1`
136+
Positive pin (left port)
137+
- `p2`
138+
Positive pin (right port)
139+
- `n1`
140+
Negative pin (left port)
141+
- `n2`
142+
Negative pin (right port)
74143
"""
75144
function IdealOpAmp(;name)
76145
@named p1 = Pin()

src/Electrical/Analog/sensors.jl

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
"""
2-
CurrentSensor(; name)
2+
```julia
3+
function CurrentSensor(; name)
4+
```
5+
6+
Creates a circuit component that measures the current flowing through it. Analogous to
7+
an ideal ammeter.
38
4-
Sensor to measure the current through a branch in amperes.
9+
# States
10+
- `i(t)`: [`A`]
11+
Current through the sensor
12+
13+
# Connectors
14+
- `p`
15+
Positive pin
16+
- `n`
17+
Negative pin
518
"""
619
function CurrentSensor(; name)
720
@named p = Pin()
@@ -16,9 +29,19 @@ function CurrentSensor(; name)
1629
end
1730

1831
"""
19-
PotentialSensor(; name)
32+
```julia
33+
function PotentialSensor(; name)
34+
```
2035
21-
Sensor to measure the potential in volt.
36+
Creates a circuit component which measures the potential at a pin.
37+
38+
# States
39+
- `phi(t)`: [`V`]
40+
The potential at this point
41+
42+
# Connectors
43+
- `p`
44+
Pin at which potential is to be measured
2245
"""
2346
function PotentialSensor(; name)
2447
@named p = Pin()
@@ -31,9 +54,22 @@ function PotentialSensor(; name)
3154
end
3255

3356
"""
34-
VoltageSensor(; name)
57+
```julia
58+
function VoltageSensor(; name)
59+
```
60+
61+
Creates a circuit component that measures the voltage across it. Analogous to
62+
an ideal voltmeter.
3563
36-
Sensor to measure the potential difference between two pins in volt.
64+
# States
65+
- `v(t)`: [`V`]
66+
The voltage across this component
67+
68+
# Connectors
69+
- `p`
70+
Positive pin
71+
- `n`
72+
Negative pin
3773
"""
3874
function VoltageSensor(; name)
3975
@named p = Pin()
@@ -48,9 +84,26 @@ function VoltageSensor(; name)
4884
end
4985

5086
"""
51-
PowerSensor(; name)
87+
```julia
88+
function PowerSensor(; name)
89+
```
90+
91+
Combines a [`VoltageSensor`](@ref) and a [`CurrentSensor`](@ref) to measure the power being
92+
consumed by a circuit.
93+
94+
# States
95+
- `power(t)`: [`W`]
96+
The power being consumed, given by the product of voltage and current.
5297
53-
Sensor to measure the power in watt.
98+
# Connectors
99+
- `pc`
100+
Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
101+
- `nc`
102+
Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
103+
- `pv`
104+
Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
105+
- `nv`
106+
Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
54107
"""
55108
function PowerSensor(; name)
56109
@named pc = Pin()
@@ -71,9 +124,27 @@ function PowerSensor(; name)
71124
end
72125

73126
"""
74-
MultiSensor(; name)
127+
```julia
128+
function MultiSensor(; name)
129+
```
130+
131+
Combines a [`VoltageSensor`](@ref) and a [`CurrentSensor`](@ref).
132+
133+
# States
134+
- `v(t)`: [`V`]
135+
The voltage across the [`VoltageSensor`](@ref)
136+
- `i(t)`: [`A`]
137+
The current across the [`CurrentSensor`](@ref)
75138
76-
Sensor to measure current [A], voltage [V] and power [W].
139+
# Connectors
140+
- `pc`
141+
Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
142+
- `nc`
143+
Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
144+
- `pv`
145+
Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
146+
- `nv`
147+
Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
77148
"""
78149
function MultiSensor(; name)
79150
@named pc = Pin()

0 commit comments

Comments
 (0)