-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathblocks.ts
More file actions
1836 lines (1831 loc) · 193 KB
/
Copy pathblocks.ts
File metadata and controls
1836 lines (1831 loc) · 193 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Auto-generated by scripts/extract.py - DO NOT EDIT
// Re-run 'npm run extract' to update
export interface ExtractedParam {
type: string;
default: string | null;
description: string;
min?: number;
max?: number;
options?: string[];
}
export interface ExtractedBlock {
blockClass: string;
description: string;
docstringHtml: string;
params: Record<string, ExtractedParam>;
inputs: string[] | null; // null = variable/unlimited, [] = none, [...] = fixed
outputs: string[] | null; // null = variable/unlimited, [] = none, [...] = fixed
}
export const extractedBlocks: Record<string, ExtractedBlock> =
{
"Constant": {
"blockClass": "Constant",
"description": "Produces a constant output signal (SISO).",
"docstringHtml": "<p>Produces a constant output signal (SISO).</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = const.\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>value <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>constant defining block output</dd>\n</dl>\n</div>\n",
"params": {
"value": {
"type": "integer",
"default": "1",
"description": "constant defining block output"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"Source": {
"blockClass": "Source",
"description": "Source that produces an arbitrary time dependent output defined by `func` (callable).",
"docstringHtml": "<p>Source that produces an arbitrary time dependent output defined by <cite>func</cite> (callable).</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\mathrm{func}(t)\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its internal function (<cite>func</cite>) will\nbe called multiple times per timestep, each time when <cite>Simulation._update(t)</cite>\nis called in the global simulation loop.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>For example a ramp:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">Source</span><span class=\"whitespace\">\n\n</span><span class=\"name\">src</span> <span class=\"operator\">=</span> <span class=\"name\">Source</span><span class=\"punctuation\">(</span><span class=\"keyword\">lambda</span> <span class=\"name\">t</span> <span class=\"punctuation\">:</span> <span class=\"name\">t</span><span class=\"punctuation\">)</span>\n</pre>\n<p>or a simple sinusoid with some frequency:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">import</span><span class=\"whitespace\"> </span><span class=\"name namespace\">numpy</span><span class=\"whitespace\"> </span><span class=\"keyword\">as</span><span class=\"whitespace\"> </span><span class=\"name namespace\">np</span><span class=\"whitespace\">\n</span><span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">Source</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#some parameter</span><span class=\"whitespace\">\n</span><span class=\"name\">omega</span> <span class=\"operator\">=</span> <span class=\"literal number integer\">100</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#the function that gets evaluated</span><span class=\"whitespace\">\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">f</span><span class=\"punctuation\">(</span><span class=\"name\">t</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">sin</span><span class=\"punctuation\">(</span><span class=\"name\">omega</span> <span class=\"operator\">*</span> <span class=\"name\">t</span><span class=\"punctuation\">)</span><span class=\"whitespace\">\n\n</span><span class=\"name\">src</span> <span class=\"operator\">=</span> <span class=\"name\">Source</span><span class=\"punctuation\">(</span><span class=\"name\">f</span><span class=\"punctuation\">)</span>\n</pre>\n<p>Because the <cite>Source</cite> block only has a single argument, it can be\nused to decorate a function and make it a <cite>PathSim</cite> block. This might\nbe handy in some cases to keep definitions concise and localized\nin the code:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">import</span><span class=\"whitespace\"> </span><span class=\"name namespace\">numpy</span><span class=\"whitespace\"> </span><span class=\"keyword\">as</span><span class=\"whitespace\"> </span><span class=\"name namespace\">np</span><span class=\"whitespace\">\n</span><span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">Source</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#does the same as the definition above</span><span class=\"whitespace\">\n\n</span><span class=\"name decorator\">@Source</span><span class=\"whitespace\">\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">src</span><span class=\"punctuation\">(</span><span class=\"name\">t</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"name\">omega</span> <span class=\"operator\">=</span> <span class=\"literal number integer\">100</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">sin</span><span class=\"punctuation\">(</span><span class=\"name\">omega</span> <span class=\"operator\">*</span> <span class=\"name\">t</span><span class=\"punctuation\">)</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#'src' is now a PathSim block</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>func <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable</span></dt>\n<dd>function defining time dependent block output</dd>\n</dl>\n</div>\n",
"params": {
"func": {
"type": "callable",
"default": null,
"description": "function defining time dependent block output"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"SinusoidalSource": {
"blockClass": "SinusoidalSource",
"description": "Source block that generates a sinusoid wave",
"docstringHtml": "<p>Source block that generates a sinusoid wave</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>frequency <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>frequency of the sinusoid</dd>\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplitude of the sinusoid</dd>\n<dt>phase <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>phase of the sinusoid</dd>\n</dl>\n</div>\n",
"params": {
"frequency": {
"type": "integer",
"default": "1",
"description": "frequency of the sinusoid"
},
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the sinusoid"
},
"phase": {
"type": "integer",
"default": "0",
"description": "phase of the sinusoid"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"StepSource": {
"blockClass": "StepSource",
"description": "Discrete time unit step (or multi step) source block.",
"docstringHtml": "<p>Discrete time unit step (or multi step) source block.</p>\n<p>Utilizes a scheduled event to set the block output\nto the specified output levels at the defined event times.</p>\n<p>The arguments can be vectorial and in that case, the output is set to the\namplitude that corresponds to the defined delay like a zero-order-hold stage.\nThis functionality enables adding external or time series measurement data\ninto the system.</p>\n<div class=\"section\" id=\"examples\">\n<h3>Examples</h3>\n<p>This is how to use the source as a unit step source:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">StepSource</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#default, starts at 0, jumps to 1</span><span class=\"whitespace\">\n</span><span class=\"name\">stp</span> <span class=\"operator\">=</span> <span class=\"name\">StepSource</span><span class=\"punctuation\">()</span>\n</pre>\n<p>And this is how to configure it with multiple consecutive steps:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">StepSource</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#starts at 0, jumps to 1 at 1, jumps to -1 at 2 and jumps back to 0 at 3</span><span class=\"whitespace\">\n</span><span class=\"name\">stp</span> <span class=\"operator\">=</span> <span class=\"name\">StepSource</span><span class=\"punctuation\">(</span><span class=\"name\">amplitude</span><span class=\"operator\">=</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">,</span> <span class=\"operator\">-</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">0</span><span class=\"punctuation\">],</span> <span class=\"name\">tau</span><span class=\"operator\">=</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">3</span><span class=\"punctuation\">])</span>\n</pre>\n<p>Similarly implementing measured time series data via zoh:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">import</span><span class=\"whitespace\"> </span><span class=\"name namespace\">numpy</span><span class=\"whitespace\"> </span><span class=\"keyword\">as</span><span class=\"whitespace\"> </span><span class=\"name namespace\">np</span><span class=\"whitespace\">\n</span><span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">StepSource</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#some random time series arrays</span><span class=\"whitespace\">\n</span><span class=\"name\">times</span><span class=\"punctuation\">,</span> <span class=\"name\">data</span> <span class=\"operator\">=</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">linspace</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">0</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">100</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">1000</span><span class=\"punctuation\">),</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">random</span><span class=\"operator\">.</span><span class=\"name\">rand</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">1000</span><span class=\"punctuation\">)</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#pass them to the block</span><span class=\"whitespace\">\n</span><span class=\"name\">stp</span> <span class=\"operator\">=</span> <span class=\"name\">StepSource</span><span class=\"punctuation\">(</span><span class=\"name\">amplitude</span><span class=\"operator\">=</span><span class=\"name\">data</span><span class=\"punctuation\">,</span> <span class=\"name\">tau</span><span class=\"operator\">=</span><span class=\"name\">times</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float | list[float]</span></dt>\n<dd>amplitude of the step signal, or amplitudes / output\nlevels of the multiple steps</dd>\n<dt>tau <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float | list[float]</span></dt>\n<dd>delay of the step, or delays of the different steps</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>Evt <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">ScheduleList</span></dt>\n<dd>internal scheduled event directly accessible</dd>\n<dt>events <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[ScheduleList]</span></dt>\n<dd>list of interna events</dd>\n</dl>\n</div>\n",
"params": {
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the step signal, or amplitudes / output levels of the multiple steps"
},
"tau": {
"type": "number",
"default": "0.0",
"description": "delay of the step, or delays of the different steps"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"PulseSource": {
"blockClass": "PulseSource",
"description": "Generates a periodic pulse waveform with defined rise and fall times.",
"docstringHtml": "<p>Generates a periodic pulse waveform with defined rise and fall times.</p>\n<p>Scheduled events trigger phase changes (low, rising, high, falling),\nand the <cite>update</cite> method calculates the output value based on the\ncurrent phase, performing linear interpolation during rise and fall.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Peak amplitude of the pulse. Default is 1.0.</dd>\n<dt>T <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Period of the pulse train. Must be positive. Default is 1.0.</dd>\n<dt>t_rise <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Duration of the rising edge. Default is 0.0.</dd>\n<dt>t_fall <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Duration of the falling edge. Default is 0.0.</dd>\n<dt>tau <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Initial delay before the first pulse cycle begins. Default is 0.0.</dd>\n<dt>duty <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>Duty cycle, ratio of the pulse ON duration (plateau time only)\nto the total period T (must be between 0 and 1). Default is 0.5.\nThe high plateau duration is <cite>T * duty</cite>.</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>events <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[Schedule]</span></dt>\n<dd>Internal scheduled events triggering phase transitions.</dd>\n<dt>_phase <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">str</span></dt>\n<dd>Current phase of the pulse ('low', 'rising', 'high', 'falling').</dd>\n<dt>_phase_start_time <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>Simulation time when the current phase began.</dd>\n</dl>\n</div>\n",
"params": {
"amplitude": {
"type": "number",
"default": "1.0",
"description": "Peak amplitude of the pulse. Default is 1.0."
},
"T": {
"type": "number",
"default": "1.0",
"description": "Period of the pulse train. Must be positive. Default is 1.0."
},
"t_rise": {
"type": "number",
"default": "0.0",
"description": "Duration of the rising edge. Default is 0.0."
},
"t_fall": {
"type": "number",
"default": "0.0",
"description": "Duration of the falling edge. Default is 0.0."
},
"tau": {
"type": "number",
"default": "0.0",
"description": "Initial delay before the first pulse cycle begins. Default is 0.0."
},
"duty": {
"type": "number",
"default": "0.5",
"description": "Duty cycle, ratio of the pulse ON duration (plateau time only) to the total period T (must be between 0 and 1). Default is 0.5. The high plateau duration is `T * duty`."
}
},
"inputs": [],
"outputs": [
"out"
]
},
"TriangleWaveSource": {
"blockClass": "TriangleWaveSource",
"description": "Source block that generates an analog triangle wave",
"docstringHtml": "<p>Source block that generates an analog triangle wave</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>frequency <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>frequency of the triangle wave</dd>\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplitude of the triangle wave</dd>\n<dt>phase <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>phase of the triangle wave</dd>\n</dl>\n</div>\n",
"params": {
"frequency": {
"type": "integer",
"default": "1",
"description": "frequency of the triangle wave"
},
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the triangle wave"
},
"phase": {
"type": "integer",
"default": "0",
"description": "phase of the triangle wave"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"SquareWaveSource": {
"blockClass": "SquareWaveSource",
"description": "Discrete time square wave source.",
"docstringHtml": "<p>Discrete time square wave source.</p>\n<p>Utilizes scheduled events to periodically set\nthe block output at discrete times.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplitude of the square wave signal</dd>\n<dt>frequency <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>frequency of the square wave signal</dd>\n<dt>phase <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>phase of the square wave signal</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>events <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[Schedule]</span></dt>\n<dd>internal scheduled events</dd>\n</dl>\n</div>\n",
"params": {
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the square wave signal"
},
"frequency": {
"type": "integer",
"default": "1",
"description": "frequency of the square wave signal"
},
"phase": {
"type": "integer",
"default": "0",
"description": "phase of the square wave signal"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"GaussianPulseSource": {
"blockClass": "GaussianPulseSource",
"description": "Source block that generates a gaussian pulse",
"docstringHtml": "<p>Source block that generates a gaussian pulse</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplitude of the gaussian pulse</dd>\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>maximum frequency component of the gaussian pulse (steepness)</dd>\n<dt>tau <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>time delay of the gaussian pulse</dd>\n</dl>\n</div>\n",
"params": {
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the gaussian pulse"
},
"f_max": {
"type": "number",
"default": "1000.0",
"description": "maximum frequency component of the gaussian pulse (steepness)"
},
"tau": {
"type": "number",
"default": "0.0",
"description": "time delay of the gaussian pulse"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"ChirpPhaseNoiseSource": {
"blockClass": "ChirpPhaseNoiseSource",
"description": "Chirp source, sinusoid with frequency ramp up and ramp down, plus phase noise.",
"docstringHtml": "<p>Chirp source, sinusoid with frequency ramp up and ramp down, plus phase noise.</p>\n<p>This works by using a time dependent triangle wave for the frequency\nand integrating it with a numerical integration engine to get a\ncontinuous phase. This phase is then used to evaluate a sinusoid.</p>\n<p>Additionally the chirp source can have white and cumulative phase noise.\nMathematically it looks like this for the contributions to the phase from\nthe triangular wave:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\varphi_t(t) = \\int_0^t \\mathrm{tri}_{f_0, B, T}(\\tau) \\, d\\tau\n\\end{equation*}\n</div>\n<p>And from the white (w) and cumulative (c) noise:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\varphi_n(t) = \\sigma_w \\, n_w(t) + \\sigma_c \\int_0^t n_c(\\tau) \\, d\\tau\n\\end{equation*}\n</div>\n<p>The phase contributions are then used to evaluate a sinusoid to get the final chirp signal:</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = A \\sin(\\varphi_t(t) + \\varphi_n(t) + \\varphi_0)\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>amplitude <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplitude of the chirp signal</dd>\n<dt>f0 <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>start frequency of the chirp signal</dd>\n<dt>BW <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>bandwidth of the frequency ramp of the chirp signal</dd>\n<dt>T <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>period of the frequency ramp of the chirp signal</dd>\n<dt>phase <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>phase of sinusoid (initial, radians)</dd>\n<dt>sig_cum <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>weight for cumulative phase noise contribution</dd>\n<dt>sig_white <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>weight for white phase noise contribution</dd>\n<dt>sampling_period <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, None</span></dt>\n<dd>time between phase noise samples. If None,\nnoise is sampled every timestep (default is 0.1)</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>noise_1 <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>internal noise value for white phase noise</dd>\n<dt>noise_2 <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>internal noise value for cumulative phase noise</dd>\n<dt>events <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[Schedule]</span></dt>\n<dd>scheduled event for periodic sampling (only if sampling_period is set)</dd>\n</dl>\n</div>\n",
"params": {
"amplitude": {
"type": "integer",
"default": "1",
"description": "amplitude of the chirp signal"
},
"f0": {
"type": "integer",
"default": "1",
"description": "start frequency of the chirp signal"
},
"BW": {
"type": "integer",
"default": "1",
"description": "bandwidth of the frequency ramp of the chirp signal"
},
"T": {
"type": "integer",
"default": "1",
"description": "period of the frequency ramp of the chirp signal"
},
"phase": {
"type": "integer",
"default": "0",
"description": "phase of sinusoid (initial, radians)"
},
"sig_cum": {
"type": "integer",
"default": "0",
"description": "weight for cumulative phase noise contribution"
},
"sig_white": {
"type": "integer",
"default": "0",
"description": "weight for white phase noise contribution"
},
"sampling_period": {
"type": "number",
"default": "0.1",
"description": "time between phase noise samples. If None, noise is sampled every timestep (default is 0.1)"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"ClockSource": {
"blockClass": "ClockSource",
"description": "Discrete time clock source block.",
"docstringHtml": "<p>Discrete time clock source block.</p>\n<p>Utilizes scheduled events to periodically set\nthe block output to 0 or 1 at discrete times.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>T <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>period of the clock</dd>\n<dt>tau <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>clock delay</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>events <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[Schedule]</span></dt>\n<dd>internal scheduled event list</dd>\n</dl>\n</div>\n",
"params": {
"T": {
"type": "integer",
"default": "1",
"description": "period of the clock"
},
"tau": {
"type": "integer",
"default": "0",
"description": "clock delay"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"WhiteNoise": {
"blockClass": "WhiteNoise",
"description": "White noise source with Gaussian distribution.",
"docstringHtml": "<p>White noise source with Gaussian distribution.</p>\n<p>Generates uncorrelated random samples with either constant amplitude\n(<tt class=\"docutils literal\">standard_deviation</tt> mode) or timestep-scaled amplitude for stochastic\nintegration (<tt class=\"docutils literal\">spectral_density</tt> mode).</p>\n<p>In spectral density mode, output is scaled as √(S₀/dt) so that integrating\nthe noise yields correct statistical properties (Wiener process).</p>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>If <tt class=\"docutils literal\">spectral_density</tt> is provided, it takes precedence over <tt class=\"docutils literal\">standard_deviation</tt>.\nIf <tt class=\"docutils literal\">sampling_period</tt> is set, noise is sampled at fixed intervals (zero-order hold).</p>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>standard_deviation <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>output standard deviation for constant-amplitude mode (default: 1.0)</dd>\n<dt>spectral_density <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>power spectral density S₀ in [signal²/Hz]</dd>\n<dt>sampling_period <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>time between samples, if None samples every timestep</dd>\n<dt>seed <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int, optional</span></dt>\n<dd>random seed for reproducibility</dd>\n</dl>\n</div>\n",
"params": {
"standard_deviation": {
"type": "number",
"default": "1.0",
"description": "output standard deviation for constant-amplitude mode (default: 1.0)"
},
"spectral_density": {
"type": "any",
"default": null,
"description": "power spectral density S₀ in [signal²/Hz]"
},
"sampling_period": {
"type": "any",
"default": null,
"description": "time between samples, if None samples every timestep"
},
"seed": {
"type": "any",
"default": null,
"description": "random seed for reproducibility"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"PinkNoise": {
"blockClass": "PinkNoise",
"description": "Pink noise (1/f noise) source using the Voss-McCartney algorithm.",
"docstringHtml": "<p>Pink noise (1/f noise) source using the Voss-McCartney algorithm.</p>\n<p>Generates noise with power spectral density proportional to 1/f, where\nlower frequencies have more power than higher frequencies.</p>\n<p>The algorithm maintains <tt class=\"docutils literal\">num_octaves</tt> independent random values representing\ndifferent frequency bands. At each sample, one octave is updated based on the\nbinary representation of the sample counter, creating the characteristic 1/f\nspectrum through the superposition of different update rates.</p>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>If <tt class=\"docutils literal\">spectral_density</tt> is provided, it takes precedence over <tt class=\"docutils literal\">standard_deviation</tt>.\nIf <tt class=\"docutils literal\">sampling_period</tt> is set, noise is sampled at fixed intervals (zero-order hold).</p>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>standard_deviation <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>approximate output standard deviation (default: 1.0)</dd>\n<dt>spectral_density <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>power spectral density, output scaled as √(S₀/(N·dt))</dd>\n<dt>num_octaves <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int</span></dt>\n<dd>number of frequency bands in algorithm (default: 16)</dd>\n<dt>sampling_period <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, optional</span></dt>\n<dd>time between samples, if None samples every timestep</dd>\n<dt>seed <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int, optional</span></dt>\n<dd>random seed for reproducibility</dd>\n</dl>\n</div>\n",
"params": {
"standard_deviation": {
"type": "number",
"default": "1.0",
"description": "approximate output standard deviation (default: 1.0)"
},
"spectral_density": {
"type": "any",
"default": null,
"description": "power spectral density, output scaled as √(S₀/(N·dt))"
},
"num_octaves": {
"type": "integer",
"default": "16",
"description": "number of frequency bands in algorithm (default: 16)"
},
"sampling_period": {
"type": "any",
"default": null,
"description": "time between samples, if None samples every timestep"
},
"seed": {
"type": "any",
"default": null,
"description": "random seed for reproducibility"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"RandomNumberGenerator": {
"blockClass": "RandomNumberGenerator",
"description": "Generates a random output value using `numpy.random.rand`.",
"docstringHtml": "<p>Generates a random output value using <cite>numpy.random.rand</cite>.</p>\n<p>If no <cite>sampling_period</cite> (None) is specified, every simulation timestep gets\na random value. Otherwise an internal <cite>Schedule</cite> event is used to periodically\nsample a random value and set the output like a zero-order-hold stage.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>sampling_period <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, None</span></dt>\n<dd>time between random samples</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>_sample <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>internal random number state in case that\nno <cite>sampling_period</cite> is provided</dd>\n<dt>Evt <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Schedule</span></dt>\n<dd>internal event that periodically samples a random\nvalue in case <cite>sampling_period</cite> is provided</dd>\n</dl>\n</div>\n",
"params": {
"sampling_period": {
"type": "any",
"default": null,
"description": "time between random samples"
}
},
"inputs": [],
"outputs": [
"out"
]
},
"Integrator": {
"blockClass": "Integrator",
"description": "Integrates the input signal.",
"docstringHtml": "<p>Integrates the input signal.</p>\n<p>Uses a numerical integration engine like this:</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\int_0^t u(\\tau) \\ d \\tau\n\\end{equation*}\n</div>\n<p>or in differential form like this:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x}(t) &= u(t) \\\\\n y(t) &= x(t)\n\\end{align}\n\\end{equation*}\n</div>\n<p>The Integrator block is inherently MIMO capable, so <cite>u</cite>\nand <cite>y</cite> can be vectors.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>This is how to initialize the integrator:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#initial value 0.0</span><span class=\"whitespace\">\n</span><span class=\"name\">i1</span> <span class=\"operator\">=</span> <span class=\"name\">Integrator</span><span class=\"punctuation\">()</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#initial value 2.5</span><span class=\"whitespace\">\n</span><span class=\"name\">i2</span> <span class=\"operator\">=</span> <span class=\"name\">Integrator</span><span class=\"punctuation\">(</span><span class=\"literal number float\">2.5</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>initial_value <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, array</span></dt>\n<dd>initial value of integrator</dd>\n</dl>\n</div>\n",
"params": {
"initial_value": {
"type": "number",
"default": "0.0",
"description": "initial value of integrator"
}
},
"inputs": null,
"outputs": null
},
"Differentiator": {
"blockClass": "Differentiator",
"description": "Differentiates the input signal.",
"docstringHtml": "<p>Differentiates the input signal.</p>\n<p>Uses a first order transfer function with a pole at the origin which implements\na high pass filter. Supports vector input.</p>\n<div class=\"math\">\n\\begin{equation*}\nH_\\mathrm{diff}(s) = \\frac{s}{1 + s / f_\\mathrm{max}}\n\\end{equation*}\n</div>\n<p>The approximation holds for signals up to a frequency of approximately f_max.</p>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>Depending on <cite>f_max</cite>, the resulting system might become stiff or ill conditioned!\nAs a practical choice set <cite>f_max</cite> to 3x the highest expected signal frequency.</p>\n</div>\n<div class=\"section\" id=\"note-1\">\n<h3>Note</h3>\n<p>Since this is an approximation of real differentiation, the approximation will not hold\nif there are high frequency components present in the signal. For example if you have\ndiscontinuities such as steps or squere waves.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#cutoff at 1kHz</span><span class=\"whitespace\">\n</span><span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Differentiator</span><span class=\"punctuation\">(</span><span class=\"name\">f_max</span><span class=\"operator\">=</span><span class=\"literal number float\">1e3</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>highest expected signal frequency</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal dynamic operator for ODE component</dd>\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {
"f_max": {
"type": "number",
"default": "100.0",
"description": "highest expected signal frequency"
}
},
"inputs": null,
"outputs": null
},
"Delay": {
"blockClass": "Delay",
"description": "Delays the input signal by a time constant 'tau' in seconds.",
"docstringHtml": "<p>Delays the input signal by a time constant 'tau' in seconds.</p>\n<p>Supports two modes of operation:</p>\n<p><strong>Continuous mode</strong> (default, <tt class=\"docutils literal\">sampling_period=None</tt>):\nUses an adaptive interpolating buffer for continuous-time delay.</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) =\n\\begin{cases}\nx(t - \\tau) & , t \\geq \\tau \\\\\n0 & , t < \\tau\n\\end{cases}\n\\end{equation*}\n</div>\n<p><strong>Discrete mode</strong> (<tt class=\"docutils literal\">sampling_period</tt> provided):\nUses a ring buffer with scheduled sampling events for N-sample delay,\nwhere <tt class=\"docutils literal\">N = round(tau / sampling_period)</tt>.</p>\n<div class=\"math\">\n\\begin{equation*}\ny[k] = x[k - N]\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>In continuous mode, the internal adaptive buffer uses interpolation for\nthe evaluation. This is required to be compatible with variable step solvers.\nIt has a drawback however. The order of the ode solver used will degrade\nwhen this block is used, due to the interpolation.</p>\n</div>\n<div class=\"section\" id=\"note-1\">\n<h3>Note</h3>\n<p>This block supports vector input, meaning we can have multiple parallel\ndelay paths through this block.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>Continuous-time delay:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#5 time units delay</span><span class=\"whitespace\">\n</span><span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Delay</span><span class=\"punctuation\">(</span><span class=\"name\">tau</span><span class=\"operator\">=</span><span class=\"literal number integer\">5</span><span class=\"punctuation\">)</span>\n</pre>\n<p>Discrete-time N-sample delay (10 samples):</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Delay</span><span class=\"punctuation\">(</span><span class=\"name\">tau</span><span class=\"operator\">=</span><span class=\"literal number float\">0.01</span><span class=\"punctuation\">,</span> <span class=\"name\">sampling_period</span><span class=\"operator\">=</span><span class=\"literal number float\">0.001</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>tau <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>delay time constant in seconds</dd>\n<dt>sampling_period <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float, None</span></dt>\n<dd>sampling period for discrete mode, default is continuous mode</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>_buffer <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">AdaptiveBuffer</span></dt>\n<dd>internal interpolatable adaptive rolling buffer (continuous mode)</dd>\n<dt>_ring <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">deque</span></dt>\n<dd>internal ring buffer for N-sample delay (discrete mode)</dd>\n</dl>\n</div>\n",
"params": {
"tau": {
"type": "number",
"default": "0.001",
"description": "delay time constant in seconds"
},
"sampling_period": {
"type": "any",
"default": null,
"description": "sampling period for discrete mode, default is continuous mode"
}
},
"inputs": null,
"outputs": null
},
"ODE": {
"blockClass": "ODE",
"description": "Ordinary differential equation (ODE) defined by its right hand side function.",
"docstringHtml": "<p>Ordinary differential equation (ODE) defined by its right hand side function.</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x}(t) &= \\mathrm{func}(x(t), u(t), t) \\\\\n y(t) &= x(t)\n\\end{align}\n\\end{equation*}\n</div>\n<p>with inhomogenity (input) <cite>u</cite> and state vector <cite>x</cite>. The function can be nonlinear\nand the ODE can be of arbitrary order. The block utilizes the integration engine\nto solve the ODE by integrating the <cite>func</cite>, which is the right hand side function.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>For example a linear 1st order ODE:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">ode</span> <span class=\"operator\">=</span> <span class=\"name\">ODE</span><span class=\"punctuation\">(</span><span class=\"keyword\">lambda</span> <span class=\"name\">x</span><span class=\"punctuation\">,</span> <span class=\"name\">u</span><span class=\"punctuation\">,</span> <span class=\"name\">t</span><span class=\"punctuation\">:</span> <span class=\"operator\">-</span><span class=\"name\">x</span><span class=\"punctuation\">)</span>\n</pre>\n<p>Or something more complex like the <cite>Van der Pol</cite> system, where it makes sense to\nalso specify the jacobian, which improves convergence for implicit solvers but is\nnot needed in most cases:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">import</span><span class=\"whitespace\"> </span><span class=\"name namespace\">numpy</span><span class=\"whitespace\"> </span><span class=\"keyword\">as</span><span class=\"whitespace\"> </span><span class=\"name namespace\">np</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#initial condition</span><span class=\"whitespace\">\n</span><span class=\"name\">x0</span> <span class=\"operator\">=</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">array</span><span class=\"punctuation\">([</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">0</span><span class=\"punctuation\">])</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#van der Pol parameter</span><span class=\"whitespace\">\n</span><span class=\"name\">mu</span> <span class=\"operator\">=</span> <span class=\"literal number integer\">1000</span><span class=\"whitespace\">\n\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">func</span><span class=\"punctuation\">(</span><span class=\"name\">x</span><span class=\"punctuation\">,</span> <span class=\"name\">u</span><span class=\"punctuation\">,</span> <span class=\"name\">t</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">array</span><span class=\"punctuation\">([</span><span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">],</span> <span class=\"name\">mu</span><span class=\"operator\">*</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">1</span> <span class=\"operator\">-</span> <span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">0</span><span class=\"punctuation\">]</span><span class=\"operator\">**</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">)</span><span class=\"operator\">*</span><span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">]</span> <span class=\"operator\">-</span> <span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">0</span><span class=\"punctuation\">]])</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#analytical jacobian (optional)</span><span class=\"whitespace\">\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">jac</span><span class=\"punctuation\">(</span><span class=\"name\">x</span><span class=\"punctuation\">,</span> <span class=\"name\">u</span><span class=\"punctuation\">,</span> <span class=\"name\">t</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">array</span><span class=\"punctuation\">(</span><span class=\"whitespace\">\n</span> <span class=\"punctuation\">[[</span><span class=\"literal number integer\">0</span> <span class=\"punctuation\">,</span> <span class=\"literal number integer\">1</span> <span class=\"punctuation\">],</span><span class=\"whitespace\">\n</span> <span class=\"punctuation\">[</span><span class=\"operator\">-</span><span class=\"name\">mu</span><span class=\"operator\">*</span><span class=\"literal number integer\">2</span><span class=\"operator\">*</span><span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">0</span><span class=\"punctuation\">]</span><span class=\"operator\">*</span><span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">]</span><span class=\"operator\">-</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">,</span> <span class=\"name\">mu</span><span class=\"operator\">*</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">1</span> <span class=\"operator\">-</span> <span class=\"name\">x</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">0</span><span class=\"punctuation\">]</span><span class=\"operator\">**</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">)]]</span><span class=\"whitespace\">\n</span> <span class=\"punctuation\">)</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#finally the block</span><span class=\"whitespace\">\n</span><span class=\"name\">vdp</span> <span class=\"operator\">=</span> <span class=\"name\">ODE</span><span class=\"punctuation\">(</span><span class=\"name\">func</span><span class=\"punctuation\">,</span> <span class=\"name\">x0</span><span class=\"punctuation\">,</span> <span class=\"name\">jac</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>func <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable</span></dt>\n<dd>right hand side function of ODE</dd>\n<dt>initial_value <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array[float]</span></dt>\n<dd>initial state / initial condition</dd>\n<dt>jac <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable, None</span></dt>\n<dd>jacobian of 'func' or 'None'</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal dynamic operator for ODE right hand side 'func'</dd>\n</dl>\n</div>\n",
"params": {
"func": {
"type": "callable",
"default": null,
"description": "right hand side function of ODE"
},
"initial_value": {
"type": "number",
"default": "0.0",
"description": "initial state / initial condition"
},
"jac": {
"type": "any",
"default": null,
"description": "jacobian of 'func' or 'None'"
}
},
"inputs": null,
"outputs": null
},
"DynamicalSystem": {
"blockClass": "DynamicalSystem",
"description": "This block implements a nonlinear dynamical system / nonlinear state space model.",
"docstringHtml": "<p>This block implements a nonlinear dynamical system / nonlinear state space model.</p>\n<p>Its basically the same as the <cite>ODE</cite> block with the addition of an output equation\nthat takes the state, input and time as arguments:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x}(t) &= \\mathrm{func}_\\mathrm{dyn}(x(t), u(t), t) \\\\\n y(t) &= \\mathrm{func}_\\mathrm{alg}(x(t), u(t), t)\n\\end{align}\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>func_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable</span></dt>\n<dd>right hand side function of ode-part of the system</dd>\n<dt>func_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable</span></dt>\n<dd>output function of the system</dd>\n<dt>initial_value <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array[float]</span></dt>\n<dd>initial state / initial condition</dd>\n<dt>jac_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable | None</span></dt>\n<dd>optional jacobian of <cite>func_dyn</cite> to improve convergence\nfor implicit ode solvers</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal dynamic operator for <cite>func_dyn</cite></dd>\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal dynamic operator for <cite>func_alg</cite></dd>\n</dl>\n</div>\n",
"params": {
"func_dyn": {
"type": "callable",
"default": null,
"description": "right hand side function of ode-part of the system"
},
"func_alg": {
"type": "callable",
"default": null,
"description": "output function of the system"
},
"initial_value": {
"type": "number",
"default": "0.0",
"description": "initial state / initial condition"
},
"jac_dyn": {
"type": "any",
"default": null,
"description": "optional jacobian of `func_dyn` to improve convergence for implicit ode solvers"
}
},
"inputs": null,
"outputs": null
},
"StateSpace": {
"blockClass": "StateSpace",
"description": "Linear time invariant (LTI) multi input multi output (MIMO) state space model.",
"docstringHtml": "<p>Linear time invariant (LTI) multi input multi output (MIMO) state space model.</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x} &= \\mathbf{A} x + \\mathbf{B} u \\\\\n y &= \\mathbf{C} x + \\mathbf{D} u\n\\end{align}\n\\end{equation*}\n</div>\n<p>where <cite>A</cite>, <cite>B</cite>, <cite>C</cite> and <cite>D</cite> are the state space matrices, <cite>x</cite> is the state,\n<cite>u</cite> the input and <cite>y</cite> the output vector.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>A SISO state space block with two internal states can be initialized\nlike this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">S</span> <span class=\"operator\">=</span> <span class=\"name\">StateSpace</span><span class=\"punctuation\">(</span><span class=\"whitespace\">\n</span> <span class=\"name\">A</span><span class=\"operator\">=-</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">eye</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">),</span><span class=\"whitespace\">\n</span> <span class=\"name\">B</span><span class=\"operator\">=</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">ones</span><span class=\"punctuation\">((</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">1</span><span class=\"punctuation\">)),</span><span class=\"whitespace\">\n</span> <span class=\"name\">C</span><span class=\"operator\">=</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">ones</span><span class=\"punctuation\">((</span><span class=\"literal number integer\">1</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">2</span><span class=\"punctuation\">)),</span><span class=\"whitespace\">\n</span> <span class=\"name\">D</span><span class=\"operator\">=</span><span class=\"literal number float\">1.0</span><span class=\"whitespace\">\n</span> <span class=\"punctuation\">)</span>\n</pre>\n<p>and a MIMO (2 in, 2 out) state space block with three internal states\ncan be initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">S</span> <span class=\"operator\">=</span> <span class=\"name\">StateSpace</span><span class=\"punctuation\">(</span><span class=\"whitespace\">\n</span> <span class=\"name\">A</span><span class=\"operator\">=-</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">eye</span><span class=\"punctuation\">(</span><span class=\"literal number integer\">3</span><span class=\"punctuation\">),</span><span class=\"whitespace\">\n</span> <span class=\"name\">B</span><span class=\"operator\">=</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">ones</span><span class=\"punctuation\">((</span><span class=\"literal number integer\">3</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">2</span><span class=\"punctuation\">)),</span><span class=\"whitespace\">\n</span> <span class=\"name\">C</span><span class=\"operator\">=</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">ones</span><span class=\"punctuation\">((</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">3</span><span class=\"punctuation\">)),</span><span class=\"whitespace\">\n</span> <span class=\"name\">D</span><span class=\"operator\">=</span><span class=\"name\">np</span><span class=\"operator\">.</span><span class=\"name\">ones</span><span class=\"punctuation\">((</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">2</span><span class=\"punctuation\">))</span><span class=\"whitespace\">\n</span> <span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>A, B, C, D <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>real valued state space matrices</dd>\n<dt>initial_value <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like, None</span></dt>\n<dd>initial state / initial condition</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_dyn <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal dynamic operator for state equation</dd>\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">DynamicOperator</span></dt>\n<dd>internal algebraic operator for mapping to outputs</dd>\n</dl>\n</div>\n",
"params": {
"A": {
"type": "number",
"default": "-1.0",
"description": ""
},
"B": {
"type": "number",
"default": "1.0",
"description": ""
},
"C": {
"type": "number",
"default": "-1.0",
"description": ""
},
"D": {
"type": "number",
"default": "1.0",
"description": "real valued state space matrices"
},
"initial_value": {
"type": "any",
"default": null,
"description": "initial state / initial condition"
}
},
"inputs": null,
"outputs": null
},
"PT1": {
"blockClass": "PT1",
"description": "First-order lag element (PT1).",
"docstringHtml": "<p>First-order lag element (PT1).</p>\n<p>The transfer function is defined as</p>\n<div class=\"math\">\n\\begin{equation*}\nH(s) = \\frac{K}{1 + T s}\n\\end{equation*}\n</div>\n<p>where <cite>K</cite> is the static gain and <cite>T</cite> is the time constant.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">pt1</span> <span class=\"operator\">=</span> <span class=\"name\">PT1</span><span class=\"punctuation\">(</span><span class=\"name\">K</span><span class=\"operator\">=</span><span class=\"literal number float\">2.0</span><span class=\"punctuation\">,</span> <span class=\"name\">T</span><span class=\"operator\">=</span><span class=\"literal number float\">0.5</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>K <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>static gain</dd>\n<dt>T <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>time constant in seconds (must be > 0)</dd>\n</dl>\n</div>\n",
"params": {
"K": {
"type": "number",
"default": "1.0",
"description": "static gain"
},
"T": {
"type": "number",
"default": "1.0",
"description": "time constant in seconds (must be > 0)"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"PT2": {
"blockClass": "PT2",
"description": "Second-order lag element (PT2).",
"docstringHtml": "<p>Second-order lag element (PT2).</p>\n<p>The transfer function is defined as</p>\n<div class=\"math\">\n\\begin{equation*}\nH(s) = \\frac{K}{1 + 2 d T s + T^2 s^2}\n\\end{equation*}\n</div>\n<p>where <cite>K</cite> is the static gain, <cite>T</cite> is the time constant\n(related to the natural frequency by <span class=\"math\">\\(\\omega_n = 1/T\\)</span>)\nand <cite>d</cite> is the damping ratio.</p>\n<p>The damping ratio <cite>d</cite> controls the transient behavior:</p>\n<ul class=\"simple\">\n<li><span class=\"math\">\\(d < 1\\)</span>: underdamped (oscillatory)</li>\n<li><span class=\"math\">\\(d = 1\\)</span>: critically damped</li>\n<li><span class=\"math\">\\(d > 1\\)</span>: overdamped</li>\n</ul>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#underdamped second-order system</span><span class=\"whitespace\">\n</span><span class=\"name\">pt2</span> <span class=\"operator\">=</span> <span class=\"name\">PT2</span><span class=\"punctuation\">(</span><span class=\"name\">K</span><span class=\"operator\">=</span><span class=\"literal number float\">1.0</span><span class=\"punctuation\">,</span> <span class=\"name\">T</span><span class=\"operator\">=</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">,</span> <span class=\"name\">d</span><span class=\"operator\">=</span><span class=\"literal number float\">0.3</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>K <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>static gain</dd>\n<dt>T <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>time constant in seconds (must be > 0)</dd>\n<dt>d <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>damping ratio (must be >= 0)</dd>\n</dl>\n</div>\n",
"params": {
"K": {
"type": "number",
"default": "1.0",
"description": "static gain"
},
"T": {
"type": "number",
"default": "1.0",
"description": "time constant in seconds (must be > 0)"
},
"d": {
"type": "number",
"default": "1.0",
"description": "damping ratio (must be >= 0)"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"LeadLag": {
"blockClass": "LeadLag",
"description": "Lead-Lag compensator.",
"docstringHtml": "<p>Lead-Lag compensator.</p>\n<p>The transfer function is defined as</p>\n<div class=\"math\">\n\\begin{equation*}\nH(s) = K \\frac{T_1 s + 1}{T_2 s + 1}\n\\end{equation*}\n</div>\n<p>where <cite>K</cite> is the static gain, <cite>T1</cite> is the lead time constant\nand <cite>T2</cite> is the lag time constant.</p>\n<ul class=\"simple\">\n<li><span class=\"math\">\\(T_1 > T_2\\)</span>: lead compensator (phase advance)</li>\n<li><span class=\"math\">\\(T_1 < T_2\\)</span>: lag compensator (phase lag)</li>\n<li><span class=\"math\">\\(T_1 = T_2\\)</span>: pure gain</li>\n</ul>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#lead compensator</span><span class=\"whitespace\">\n</span><span class=\"name\">ll</span> <span class=\"operator\">=</span> <span class=\"name\">LeadLag</span><span class=\"punctuation\">(</span><span class=\"name\">K</span><span class=\"operator\">=</span><span class=\"literal number float\">1.0</span><span class=\"punctuation\">,</span> <span class=\"name\">T1</span><span class=\"operator\">=</span><span class=\"literal number float\">0.5</span><span class=\"punctuation\">,</span> <span class=\"name\">T2</span><span class=\"operator\">=</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>K <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>static gain</dd>\n<dt>T1 <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>lead (numerator) time constant in seconds</dd>\n<dt>T2 <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>lag (denominator) time constant in seconds (must be > 0)</dd>\n</dl>\n</div>\n",
"params": {
"K": {
"type": "number",
"default": "1.0",
"description": "static gain"
},
"T1": {
"type": "number",
"default": "1.0",
"description": "lead (numerator) time constant in seconds"
},
"T2": {
"type": "number",
"default": "1.0",
"description": "lag (denominator) time constant in seconds (must be > 0)"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"PID": {
"blockClass": "PID",
"description": "Proportional-Integral-Differentiation (PID) controller.",
"docstringHtml": "<p>Proportional-Integral-Differentiation (PID) controller.</p>\n<p>The transfer function is defined as</p>\n<div class=\"math\">\n\\begin{equation*}\nH(s) = K_p + K_i \\frac{1}{s} + K_d \\frac{s}{1 + s / f_\\mathrm{max}}\n\\end{equation*}\n</div>\n<p>where the differentiation is approximated by a high pass filter that holds\nfor signals up to a frequency of approximately <cite>f_max</cite>.</p>\n<p>Internally realized as a linear state space model with two states\n(differentiator filter state and integrator state).</p>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>Depending on <cite>f_max</cite>, the resulting system might become stiff or ill conditioned!\nAs a practical choice set <cite>f_max</cite> to 3x the highest expected signal frequency.\nSince this block uses an approximation of real differentiation, the approximation will\nnot hold if there are high frequency components present in the signal. For example if\nyou have discontinuities such as steps or square waves.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#cutoff at 1kHz</span><span class=\"whitespace\">\n</span><span class=\"name\">pid</span> <span class=\"operator\">=</span> <span class=\"name\">PID</span><span class=\"punctuation\">(</span><span class=\"name\">Kp</span><span class=\"operator\">=</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"name\">Ki</span><span class=\"operator\">=</span><span class=\"literal number float\">0.5</span><span class=\"punctuation\">,</span> <span class=\"name\">Kd</span><span class=\"operator\">=</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">,</span> <span class=\"name\">f_max</span><span class=\"operator\">=</span><span class=\"literal number float\">1e3</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Kp <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>proportional controller coefficient</dd>\n<dt>Ki <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>integral controller coefficient</dd>\n<dt>Kd <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>differentiator controller coefficient</dd>\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>highest expected signal frequency</dd>\n</dl>\n</div>\n",
"params": {
"Kp": {
"type": "integer",
"default": "0",
"description": "proportional controller coefficient"
},
"Ki": {
"type": "integer",
"default": "0",
"description": "integral controller coefficient"
},
"Kd": {
"type": "integer",
"default": "0",
"description": "differentiator controller coefficient"
},
"f_max": {
"type": "integer",
"default": "100",
"description": "highest expected signal frequency"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"AntiWindupPID": {
"blockClass": "AntiWindupPID",
"description": "Proportional-Integral-Differentiation (PID) controller with anti-windup mechanism (back-calculation).",
"docstringHtml": "<p>Proportional-Integral-Differentiation (PID) controller with anti-windup mechanism (back-calculation).</p>\n<p>Anti-windup mechanisms are needed when the magnitude of the control signal\nfrom the PID controller is limited by some real world saturation. In these cases,\nthe integrator will continue to accumulate the control error and "wind itself up".\nOnce the setpoint is reached, this can result in significant overshoots. This\nimplementation adds a conditional feedback term to the internal integrator that\n"unwinds" it when the PID output crosses some limits. This is pretty much a\ndeadzone feedback element for the integrator.</p>\n<p>Mathematically, this block implements the following set of ODEs</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n\\dot{x}_1 &= f_\\mathrm{max} (u - x_1) \\\\\n\\dot{x}_2 &= u - w\n\\end{align}\n\\end{equation*}\n</div>\n<p>with the anti-windup feedback (depending on the pid output)</p>\n<div class=\"math\">\n\\begin{equation*}\nw = K_s (y - \\min(\\max(y, y_\\mathrm{min}), y_\\mathrm{max}))\n\\end{equation*}\n</div>\n<p>and the output itself</p>\n<div class=\"math\">\n\\begin{equation*}\ny = K_p u + K_d f_\\mathrm{max} (u - x_1) + K_i x_2\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>Depending on <cite>f_max</cite>, the resulting system might become stiff or ill conditioned!\nAs a practical choice set <cite>f_max</cite> to 3x the highest expected signal frequency.\nSince this block uses an approximation of real differentiation, the approximation will\nnot hold if there are high frequency components present in the signal. For example if\nyou have discontinuities such as steps or square waves.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#cutoff at 1kHz, windup limits at [-5, 5]</span><span class=\"whitespace\">\n</span><span class=\"name\">pid</span> <span class=\"operator\">=</span> <span class=\"name\">AntiWindupPID</span><span class=\"punctuation\">(</span><span class=\"name\">Kp</span><span class=\"operator\">=</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"name\">Ki</span><span class=\"operator\">=</span><span class=\"literal number float\">0.5</span><span class=\"punctuation\">,</span> <span class=\"name\">Kd</span><span class=\"operator\">=</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">,</span> <span class=\"name\">f_max</span><span class=\"operator\">=</span><span class=\"literal number float\">1e3</span><span class=\"punctuation\">,</span> <span class=\"name\">limits</span><span class=\"operator\">=</span><span class=\"punctuation\">[</span><span class=\"operator\">-</span><span class=\"literal number integer\">5</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">5</span><span class=\"punctuation\">])</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Kp <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>proportional controller coefficient</dd>\n<dt>Ki <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>integral controller coefficient</dd>\n<dt>Kd <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>differentiator controller coefficient</dd>\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>highest expected signal frequency</dd>\n<dt>Ks <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>feedback term for back calculation for anti-windup control of integrator</dd>\n<dt>limits <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like[float]</span></dt>\n<dd>lower and upper limit for PID output that triggers anti-windup of integrator</dd>\n</dl>\n</div>\n",
"params": {
"Kp": {
"type": "integer",
"default": "0",
"description": "proportional controller coefficient"
},
"Ki": {
"type": "integer",
"default": "0",
"description": "integral controller coefficient"
},
"Kd": {
"type": "integer",
"default": "0",
"description": "differentiator controller coefficient"
},
"f_max": {
"type": "integer",
"default": "100",
"description": "highest expected signal frequency"
},
"Ks": {
"type": "integer",
"default": "10",
"description": "feedback term for back calculation for anti-windup control of integrator"
},
"limits": {
"type": "array",
"default": "[-10, 10]",
"description": "lower and upper limit for PID output that triggers anti-windup of integrator"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"RateLimiter": {
"blockClass": "RateLimiter",
"description": "Rate limiter block that limits the rate of change of a signal.",
"docstringHtml": "<p>Rate limiter block that limits the rate of change of a signal.</p>\n<p>Implements a continuous-time rate limiter as a first-order tracking system\nwith clipped rate of change:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\dot{x} = \\mathrm{clip}\\left(f_\\mathrm{max} (u - x),\\; -r,\\; r\\right)\n\\end{equation*}\n</div>\n<p>where <cite>r</cite> is the maximum allowed rate and <cite>f_max</cite> controls the tracking\nbandwidth when the signal is not rate-limited. The output is the state\n<span class=\"math\">\\(y = x\\)</span>.</p>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>The parameter <cite>f_max</cite> should be set high enough that the output tracks\nthe input without lag when the rate is within limits.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#max rate of 10 units/s</span><span class=\"whitespace\">\n</span><span class=\"name\">rl</span> <span class=\"operator\">=</span> <span class=\"name\">RateLimiter</span><span class=\"punctuation\">(</span><span class=\"name\">rate</span><span class=\"operator\">=</span><span class=\"literal number float\">10.0</span><span class=\"punctuation\">,</span> <span class=\"name\">f_max</span><span class=\"operator\">=</span><span class=\"literal number float\">1e3</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>rate <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>maximum rate of change (positive value)</dd>\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>tracking bandwidth parameter</dd>\n</dl>\n</div>\n",
"params": {
"rate": {
"type": "number",
"default": "1.0",
"description": "maximum rate of change (positive value)"
},
"f_max": {
"type": "integer",
"default": "100",
"description": "tracking bandwidth parameter"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"Backlash": {
"blockClass": "Backlash",
"description": "Backlash (mechanical play) element.",
"docstringHtml": "<p>Backlash (mechanical play) element.</p>\n<p>Models the hysteresis-like behavior of mechanical backlash in gears,\ncouplings and other systems with play. The output only tracks the input\nafter the input has moved through the full backlash width.</p>\n<div class=\"math\">\n\\begin{equation*}\n\\dot{x} = f_\\mathrm{max} \\left((u - x) - \\mathrm{clip}(u - x,\\; -w/2,\\; w/2)\\right)\n\\end{equation*}\n</div>\n<p>where <cite>w</cite> is the total backlash width. Inside the dead zone <span class=\"math\">\\(|u - x| \\leq w/2\\)</span>\nthe output does not move. Once the input pushes past the edge, the output\ntracks with bandwidth <cite>f_max</cite>.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#backlash with 0.5 units of total play</span><span class=\"whitespace\">\n</span><span class=\"name\">bl</span> <span class=\"operator\">=</span> <span class=\"name\">Backlash</span><span class=\"punctuation\">(</span><span class=\"name\">width</span><span class=\"operator\">=</span><span class=\"literal number float\">0.5</span><span class=\"punctuation\">,</span> <span class=\"name\">f_max</span><span class=\"operator\">=</span><span class=\"literal number float\">1e3</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>width <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>total backlash width (play)</dd>\n<dt>f_max <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>tracking bandwidth parameter when engaged</dd>\n</dl>\n</div>\n",
"params": {
"width": {
"type": "number",
"default": "1.0",
"description": "total backlash width (play)"
},
"f_max": {
"type": "integer",
"default": "100",
"description": "tracking bandwidth parameter when engaged"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"Deadband": {
"blockClass": "Deadband",
"description": "Deadband (dead zone) element.",
"docstringHtml": "<p>Deadband (dead zone) element.</p>\n<p>Outputs zero when the input is within the dead zone, and passes\nthe signal shifted by the zone boundary otherwise:</p>\n<div class=\"math\">\n\\begin{equation*}\ny = \\begin{cases}\n u - u_\\mathrm{upper} & \\text{if } u > u_\\mathrm{upper} \\\\\n 0 & \\text{if } u_\\mathrm{lower} \\leq u \\leq u_\\mathrm{upper} \\\\\n u - u_\\mathrm{lower} & \\text{if } u < u_\\mathrm{lower}\n\\end{cases}\n\\end{equation*}\n</div>\n<p>or equivalently <span class=\"math\">\\(y = u - \\mathrm{clip}(u,\\; u_\\mathrm{lower},\\; u_\\mathrm{upper})\\)</span>.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#symmetric dead zone of width 0.2</span><span class=\"whitespace\">\n</span><span class=\"name\">db</span> <span class=\"operator\">=</span> <span class=\"name\">Deadband</span><span class=\"punctuation\">(</span><span class=\"name\">lower</span><span class=\"operator\">=-</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">,</span> <span class=\"name\">upper</span><span class=\"operator\">=</span><span class=\"literal number float\">0.1</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>lower <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>lower bound of the dead zone</dd>\n<dt>upper <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>upper bound of the dead zone</dd>\n</dl>\n</div>\n",
"params": {
"lower": {
"type": "number",
"default": "-1.0",
"description": "lower bound of the dead zone"
},
"upper": {
"type": "number",
"default": "1.0",
"description": "upper bound of the dead zone"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"TransferFunctionNumDen": {
"blockClass": "TransferFunctionNumDen",
"description": "This block defines a LTI (SISO) transfer function.",
"docstringHtml": "<p>This block defines a LTI (SISO) transfer function.</p>\n<p>The transfer function is defined in polynomial (numerator-denominator) form</p>\n<div class=\"math\">\n\\begin{equation*}\n\\mathbf{H}(s) = \\frac{b_n + b_{n-1} s + \\dots + b_{0} s^n}{a_m + a_{m-1} s + \\dots + a_{0} s^m}\n\\end{equation*}\n</div>\n<p>where <cite>Num</cite> is the list of numerator polynomial coefficients and <cite>Den</cite> the\nlist of denominator coefficients.</p>\n<p>Upon initialization, the state space realization of the transfer function is\ncomputed using <cite>scipy.signal.TransferFunction(Num, Den).to_ss()</cite>.</p>\n<p>The resulting state space model of the form</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x} &= \\mathbf{A} x + \\mathbf{B} u \\\\\n y &= \\mathbf{C} x + \\mathbf{D} u\n\\end{align}\n\\end{equation*}\n</div>\n<p>is handled the same as the 'StateSpace' block, where <cite>A</cite>, <cite>B</cite>, <cite>C</cite> and <cite>D</cite>\nare the state space matrices, <cite>x</cite> is the internal state, <cite>u</cite> the input and\n<cite>y</cite> the output vector.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Num <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>numerator polynomial coefficients</dd>\n<dt>Den <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>denominator polynomial coefficients</dd>\n</dl>\n</div>\n",
"params": {
"Num": {
"type": "array",
"default": "[1]",
"description": "numerator polynomial coefficients"
},
"Den": {
"type": "array",
"default": "[1, 1]",
"description": "denominator polynomial coefficients"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"TransferFunctionZPG": {
"blockClass": "TransferFunctionZPG",
"description": "This block defines a LTI (SISO) transfer function.",
"docstringHtml": "<p>This block defines a LTI (SISO) transfer function.</p>\n<p>The transfer function is defined in zeros-poles-gain (ZPG) form</p>\n<div class=\"math\">\n\\begin{equation*}\n\\mathbf{H}(s) = k \\frac{(s - z_1)(s - z_2)\\cdots(s - z_m)}{(s - p_1)(s - p_2)\\cdots(s - p_n)}\n\\end{equation*}\n</div>\n<p>where <cite>Zeros</cite> are the scalar (possibly complex conjugate) zeros of the\ntransfer function, and <cite>Poles</cite> are the poles (denominator zeros) of the\ntransfer function. <cite>Gain</cite> is the scalar factor <cite>k</cite>.</p>\n<p>Upon initialization, the state space realization of the transfer function is\ncomputed using <cite>scipy.signal.ZerosPolesGain(Zeros, Poles, Gain).to_ss()</cite>.</p>\n<p>The resulting state space model of the form</p>\n<div class=\"math\">\n\\begin{equation*}\n\\begin{align}\n \\dot{x} &= \\mathbf{A} x + \\mathbf{B} u \\\\\n y &= \\mathbf{C} x + \\mathbf{D} u\n\\end{align}\n\\end{equation*}\n</div>\n<p>is handled the same as the 'StateSpace' block, where <cite>A</cite>, <cite>B</cite>, <cite>C</cite> and <cite>D</cite>\nare the state space matrices, <cite>x</cite> is the internal state, <cite>u</cite> the input and\n<cite>y</cite> the output vector.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Poles <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>transfer function poles</dd>\n<dt>Zeros <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>transfer function zeros</dd>\n<dt>Gain <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>gain term of transfer function</dd>\n</dl>\n</div>\n",
"params": {
"Zeros": {
"type": "array",
"default": "[]",
"description": "transfer function zeros"
},
"Poles": {
"type": "array",
"default": "[-1]",
"description": "transfer function poles"
},
"Gain": {
"type": "number",
"default": "1.0",
"description": "gain term of transfer function"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"ButterworthLowpassFilter": {
"blockClass": "ButterworthLowpassFilter",
"description": "Direct implementation of a low pass butterworth filter block.",
"docstringHtml": "<p>Direct implementation of a low pass butterworth filter block.</p>\n<p>Follows the same structure as the 'StateSpace' block in the\n'pathsim.blocks' module. The numerator and denominator of the\nfilter transfer function are generated and then the transfer\nfunction is realized as a state space model.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Fc <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>corner frequency of the filter in [Hz]</dd>\n<dt>n <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int</span></dt>\n<dd>filter order</dd>\n</dl>\n</div>\n",
"params": {
"Fc": {
"type": "integer",
"default": "100",
"description": "corner frequency of the filter in [Hz]"
},
"n": {
"type": "integer",
"default": "2",
"description": "filter order"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"ButterworthHighpassFilter": {
"blockClass": "ButterworthHighpassFilter",
"description": "Direct implementation of a high pass butterworth filter block.",
"docstringHtml": "<p>Direct implementation of a high pass butterworth filter block.</p>\n<p>Follows the same structure as the 'StateSpace' block in the\n'pathsim.blocks' module. The numerator and denominator of the\nfilter transfer function are generated and then the transfer\nfunction is realized as a state space model.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Fc <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>corner frequency of the filter in [Hz]</dd>\n<dt>n <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int</span></dt>\n<dd>filter order</dd>\n</dl>\n</div>\n",
"params": {
"Fc": {
"type": "integer",
"default": "100",
"description": "corner frequency of the filter in [Hz]"
},
"n": {
"type": "integer",
"default": "2",
"description": "filter order"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"ButterworthBandpassFilter": {
"blockClass": "ButterworthBandpassFilter",
"description": "Direct implementation of a bandpass butterworth filter block.",
"docstringHtml": "<p>Direct implementation of a bandpass butterworth filter block.</p>\n<p>Follows the same structure as the 'StateSpace' block in the\n'pathsim.blocks' module. The numerator and denominator of the\nfilter transfer function are generated and then the transfer\nfunction is realized as a state space model.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Fc <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">list[float]</span></dt>\n<dd>corner frequencies (left, right) of the filter in [Hz]</dd>\n<dt>n <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int</span></dt>\n<dd>filter order</dd>\n</dl>\n</div>\n",
"params": {
"Fc": {
"type": "array",
"default": "[50, 100]",
"description": "corner frequencies (left, right) of the filter in [Hz]"
},
"n": {
"type": "integer",
"default": "2",
"description": "filter order"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"ButterworthBandstopFilter": {
"blockClass": "ButterworthBandstopFilter",
"description": "Direct implementation of a bandstop butterworth filter block.",
"docstringHtml": "<p>Direct implementation of a bandstop butterworth filter block.</p>\n<p>Follows the same structure as the 'StateSpace' block in the\n'pathsim.blocks' module. The numerator and denominator of the\nfilter transfer function are generated and then the transfer\nfunction is realized as a state space model.</p>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>Fc <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">tuple[float], list[float]</span></dt>\n<dd>corner frequencies (left, right) of the filter in [Hz]</dd>\n<dt>n <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">int</span></dt>\n<dd>filter order</dd>\n</dl>\n</div>\n",
"params": {
"Fc": {
"type": "array",
"default": "[50, 100]",
"description": "corner frequencies (left, right) of the filter in [Hz]"
},
"n": {
"type": "integer",
"default": "2",
"description": "filter order"
}
},
"inputs": [
"in"
],
"outputs": [
"out"
]
},
"Adder": {
"blockClass": "Adder",
"description": "Summs / adds up all input signals to a single output signal (MISO)",
"docstringHtml": "<p>Summs / adds up all input signals to a single output signal (MISO)</p>\n<p>This is how it works in the default case</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\sum_i u_i(t)\n\\end{equation*}\n</div>\n<p>and like this when additional operations are defined</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\sum_i \\mathrm{op}_i \\cdot u_i(t)\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>This is the default initialization that just adds up all the inputs:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">A</span> <span class=\"operator\">=</span> <span class=\"name\">Adder</span><span class=\"punctuation\">()</span>\n</pre>\n<p>and this is the initialization with specific operations that subtracts\nthe second from first input and neglects all others:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">A</span> <span class=\"operator\">=</span> <span class=\"name\">Adder</span><span class=\"punctuation\">(</span><span class=\"literal string single\">'+-'</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its operation (<cite>op_alg</cite>) will be called\nmultiple times per timestep, each time when <cite>Simulation._update(t)</cite> is\ncalled in the global simulation loop.</p>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>operations <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">str, optional</span></dt>\n<dd>optional string of operations to be applied before\nsummation, i.e. '+-' will compute the difference,\n'None' will just perform regular sum</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>_ops <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">dict</span></dt>\n<dd>dict that maps string operations to numerical</dd>\n<dt>_ops_array <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>operations converted to array</dd>\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {
"operations": {
"type": "any",
"default": null,
"description": "optional string of operations to be applied before summation, i.e. '+-' will compute the difference, 'None' will just perform regular sum"
}
},
"inputs": null,
"outputs": [
"out"
]
},
"Multiplier": {
"blockClass": "Multiplier",
"description": "Multiplies all signals from all input ports (MISO).",
"docstringHtml": "<p>Multiplies all signals from all input ports (MISO).</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\prod_i u_i(t)\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its operation (<cite>op_alg</cite>) will be called\nmultiple times per timestep, each time when <cite>Simulation._update(t)</cite> is\ncalled in the global simulation loop.</p>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator that wraps 'prod'</dd>\n</dl>\n</div>\n",
"params": {},
"inputs": null,
"outputs": [
"out"
]
},
"Divider": {
"blockClass": "Divider",
"description": "Multiplies and divides input signals (MISO).",
"docstringHtml": "<p>Multiplies and divides input signals (MISO).</p>\n<p>This is the default behavior (multiply all):</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\prod_i u_i(t)\n\\end{equation*}\n</div>\n<p>and this is the behavior with an operations string:</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\frac{\\prod_{i \\in M} u_i(t)}{\\prod_{j \\in D} u_j(t)}\n\\end{equation*}\n</div>\n<p>where <span class=\"math\">\\(M\\)</span> is the set of inputs with <tt class=\"docutils literal\">*</tt> and <span class=\"math\">\\(D\\)</span> the set with <tt class=\"docutils literal\">/</tt>.</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>Default initialization multiplies the first input and divides by the second:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Divider</span><span class=\"punctuation\">()</span>\n</pre>\n<p>Multiply the first two inputs and divide by the third:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Divider</span><span class=\"punctuation\">(</span><span class=\"literal string single\">'**/'</span><span class=\"punctuation\">)</span>\n</pre>\n<p>Raise an error instead of producing <tt class=\"docutils literal\">inf</tt> when a denominator input is zero:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Divider</span><span class=\"punctuation\">(</span><span class=\"literal string single\">'**/'</span><span class=\"punctuation\">,</span> <span class=\"name\">zero_div</span><span class=\"operator\">=</span><span class=\"literal string single\">'raise'</span><span class=\"punctuation\">)</span>\n</pre>\n<p>Clamp the denominator to machine epsilon so the output stays finite:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">D</span> <span class=\"operator\">=</span> <span class=\"name\">Divider</span><span class=\"punctuation\">(</span><span class=\"literal string single\">'**/'</span><span class=\"punctuation\">,</span> <span class=\"name\">zero_div</span><span class=\"operator\">=</span><span class=\"literal string single\">'clamp'</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its operation (<tt class=\"docutils literal\">op_alg</tt>) will be called\nmultiple times per timestep, each time when <tt class=\"docutils literal\">Simulation._update(t)</tt> is\ncalled in the global simulation loop.</p>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>operations <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">str, optional</span></dt>\n<dd>String of <tt class=\"docutils literal\">*</tt> and <tt class=\"docutils literal\">/</tt> characters indicating which inputs are\nmultiplied (<tt class=\"docutils literal\">*</tt>) or divided (<tt class=\"docutils literal\">/</tt>). Inputs beyond the length of\nthe string default to <tt class=\"docutils literal\">*</tt>. Defaults to <tt class=\"docutils literal\"><span class=\"pre\">'*/'</span></tt> (divide second\ninput by first).</dd>\n<dt>zero_div <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">str, optional</span></dt>\n<dd><p class=\"first\">Behaviour when a denominator input is zero. One of:</p>\n<dl class=\"last docutils\">\n<dt><tt class=\"docutils literal\">'warn'</tt> <em>(default)</em></dt>\n<dd>Propagates <tt class=\"docutils literal\">inf</tt> and emits a <tt class=\"docutils literal\">RuntimeWarning</tt> — numpy's\nstandard behaviour.</dd>\n<dt><tt class=\"docutils literal\">'raise'</tt></dt>\n<dd>Raises <tt class=\"docutils literal\">ZeroDivisionError</tt>.</dd>\n<dt><tt class=\"docutils literal\">'clamp'</tt></dt>\n<dd>Clamps the denominator magnitude to machine epsilon\n(<tt class=\"docutils literal\"><span class=\"pre\">numpy.finfo(float).eps</span></tt>), preserving sign, so the output\nstays large-but-finite rather than <tt class=\"docutils literal\">inf</tt>.</dd>\n</dl>\n</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>_ops <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">dict</span></dt>\n<dd>Maps operation characters to exponent values (<tt class=\"docutils literal\">+1</tt> or <tt class=\"docutils literal\"><span class=\"pre\">-1</span></tt>).</dd>\n<dt>_ops_array <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">numpy.ndarray</span></dt>\n<dd>Exponents (+1 for <tt class=\"docutils literal\">*</tt>, -1 for <tt class=\"docutils literal\">/</tt>) converted to an array.</dd>\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>Internal algebraic operator.</dd>\n</dl>\n</div>\n",
"params": {
"operations": {
"type": "string",
"default": "\"*/\"",
"description": "String of ``*`` and ``/`` characters indicating which inputs are multiplied (``*``) or divided (``/``). Inputs beyond the length of the string default to ``*``. Defaults to ``'*/'`` (divide second input by first)."
},
"zero_div": {
"type": "string",
"default": "\"warn\"",
"description": "Behaviour when a denominator input is zero. One of:"
}
},
"inputs": null,
"outputs": [
"out"
]
},
"Amplifier": {
"blockClass": "Amplifier",
"description": "Amplifies the input signal by multiplication with a constant gain term.",
"docstringHtml": "<p>Amplifies the input signal by multiplication with a constant gain term.</p>\n<p>Like this:</p>\n<div class=\"math\">\n\\begin{equation*}\ny(t) = \\mathrm{gain} \\cdot u(t)\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its operation (<cite>op_alg</cite>) will be called\nmultiple times per timestep, each time when <cite>Simulation._update(t)</cite> is\ncalled in the global simulation loop.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>The block is initialized like this:</p>\n<pre class=\"code python literal-block\">\n<span class=\"comment single\">#amplification by factor 5</span><span class=\"whitespace\">\n</span><span class=\"name\">A</span> <span class=\"operator\">=</span> <span class=\"name\">Amplifier</span><span class=\"punctuation\">(</span><span class=\"name\">gain</span><span class=\"operator\">=</span><span class=\"literal number integer\">5</span><span class=\"punctuation\">)</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>gain <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">float</span></dt>\n<dd>amplifier gain</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {
"gain": {
"type": "number",
"default": "1.0",
"description": "amplifier gain"
}
},
"inputs": null,
"outputs": null
},
"Function": {
"blockClass": "Function",
"description": "Arbitrary MIMO function block, defined by a function or `lambda` expression.",
"docstringHtml": "<p>Arbitrary MIMO function block, defined by a function or <cite>lambda</cite> expression.</p>\n<p>The function can have multiple arguments that are then provided\nby the input channels of the function block.</p>\n<p>Form multi input, the function has to specify multiple arguments\nand for multi output, the aoutputs have to be provided as a\ntuple or list.</p>\n<p>In the context of the global system, this block implements algebraic\ncomponents of the global system ODE/DAE.</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = \\mathrm{func}(\\vec{u})\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"note\">\n<h3>Note</h3>\n<p>This block is purely algebraic and its operation (<cite>op_alg</cite>) will be called\nmultiple times per timestep, each time when <cite>Simulation._update(t)</cite> is\ncalled in the global simulation loop.\nTherefore <cite>func</cite> must be purely algebraic and not introduce states,\ndelay, etc. For interfacing with external stateful APIs, use the\n<cite>Wrapper</cite> block.</p>\n</div>\n<div class=\"section\" id=\"note-1\">\n<h3>Note</h3>\n<p>If the outputs are provided as a single numpy array, they are\nconsidered a single output. For MIMO, output has to be tuple.</p>\n</div>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>consider the function:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">Function</span><span class=\"whitespace\">\n\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">f</span><span class=\"punctuation\">(</span><span class=\"name\">a</span><span class=\"punctuation\">,</span> <span class=\"name\">b</span><span class=\"punctuation\">,</span> <span class=\"name\">c</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">a</span><span class=\"operator\">**</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"name\">a</span><span class=\"operator\">*</span><span class=\"name\">b</span><span class=\"punctuation\">,</span> <span class=\"name\">b</span><span class=\"operator\">/</span><span class=\"name\">c</span><span class=\"whitespace\">\n\n</span><span class=\"name\">fn</span> <span class=\"operator\">=</span> <span class=\"name\">Function</span><span class=\"punctuation\">(</span><span class=\"name\">f</span><span class=\"punctuation\">)</span>\n</pre>\n<p>then, when the block is updated, the input channels of the block are\nassigned to the function arguments following this scheme:</p>\n<pre class=\"code literal-block\">\ninputs[0] -> a\ninputs[1] -> b\ninputs[2] -> c\n</pre>\n<p>and the function outputs are assigned to the\noutput channels of the block in the same way:</p>\n<pre class=\"code literal-block\">\na**2 -> outputs[0]\na*b -> outputs[1]\nb/c -> outputs[2]\n</pre>\n<p>Because the <cite>Function</cite> block only has a single argument, it can be\nused to decorate a function and make it a <cite>PathSim</cite> block. This might\nbe handy in some cases to keep definitions concise and localized\nin the code:</p>\n<pre class=\"code python literal-block\">\n<span class=\"keyword namespace\">from</span><span class=\"whitespace\"> </span><span class=\"name namespace\">pathsim.blocks</span><span class=\"whitespace\"> </span><span class=\"keyword namespace\">import</span> <span class=\"name\">Function</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#does the same as the definition above</span><span class=\"whitespace\">\n\n</span><span class=\"name decorator\">@Function</span><span class=\"whitespace\">\n</span><span class=\"keyword\">def</span><span class=\"whitespace\"> </span><span class=\"name function\">fn</span><span class=\"punctuation\">(</span><span class=\"name\">a</span><span class=\"punctuation\">,</span> <span class=\"name\">b</span><span class=\"punctuation\">,</span> <span class=\"name\">c</span><span class=\"punctuation\">):</span><span class=\"whitespace\">\n</span> <span class=\"keyword\">return</span> <span class=\"name\">a</span><span class=\"operator\">**</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"name\">a</span><span class=\"operator\">*</span><span class=\"name\">b</span><span class=\"punctuation\">,</span> <span class=\"name\">b</span><span class=\"operator\">/</span><span class=\"name\">c</span><span class=\"whitespace\">\n\n</span><span class=\"comment single\">#'fn' is now a PathSim block</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>func <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">callable</span></dt>\n<dd>MIMO function that defines algebraic block IO behaviour, signature <cite>func(*tuple)</cite></dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator that wraps <cite>func</cite></dd>\n</dl>\n</div>\n",
"params": {
"func": {
"type": "callable",
"default": null,
"description": "MIMO function that defines algebraic block IO behaviour, signature `func(*tuple)`"
}
},
"inputs": null,
"outputs": null
},
"Polynomial": {
"blockClass": "Polynomial",
"description": "Polynomial operator block.",
"docstringHtml": "<p>Polynomial operator block.</p>\n<p>Evaluates a polynomial in the input. The coefficients follow the\n<cite>numpy.polyval</cite> convention, with the highest order term first:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = c_0 \\vec{u}^n + c_1 \\vec{u}^{n-1} + \\dots + c_{n-1} \\vec{u} + c_n\n\\end{equation*}\n</div>\n<p>This block supports vector inputs (the polynomial is evaluated\nelement-wise).</p>\n<div class=\"section\" id=\"example\">\n<h3>Example</h3>\n<p>Quadratic <span class=\"math\">\\(y = 2 u^2 + 3 u + 1\\)</span>:</p>\n<pre class=\"code python literal-block\">\n<span class=\"name\">p</span> <span class=\"operator\">=</span> <span class=\"name\">Polynomial</span><span class=\"punctuation\">(</span><span class=\"name\">coeffs</span><span class=\"operator\">=</span><span class=\"punctuation\">[</span><span class=\"literal number integer\">2</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">3</span><span class=\"punctuation\">,</span> <span class=\"literal number integer\">1</span><span class=\"punctuation\">])</span>\n</pre>\n</div>\n<div class=\"section\" id=\"parameters\">\n<h3>Parameters</h3>\n<dl class=\"docutils\">\n<dt>coeffs <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">array_like</span></dt>\n<dd>polynomial coefficients in descending order of power,\nfollowing the <tt class=\"docutils literal\">numpy.polyval</tt> convention</dd>\n</dl>\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {
"coeffs": {
"type": "array",
"default": "[1.0, 0.0]",
"description": "polynomial coefficients in descending order of power, following the ``numpy.polyval`` convention"
}
},
"inputs": null,
"outputs": null
},
"Sin": {
"blockClass": "Sin",
"description": "Sine operator block.",
"docstringHtml": "<p>Sine operator block.</p>\n<p>This block supports vector inputs. This is the operation it does:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = \\sin(\\vec{u})\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {},
"inputs": null,
"outputs": null
},
"Cos": {
"blockClass": "Cos",
"description": "Cosine operator block.",
"docstringHtml": "<p>Cosine operator block.</p>\n<p>This block supports vector inputs. This is the operation it does:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = \\cos(\\vec{u})\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {},
"inputs": null,
"outputs": null
},
"Tan": {
"blockClass": "Tan",
"description": "Tangent operator block.",
"docstringHtml": "<p>Tangent operator block.</p>\n<p>This block supports vector inputs. This is the operation it does:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = \\tan(\\vec{u})\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {},
"inputs": null,
"outputs": null
},
"Tanh": {
"blockClass": "Tanh",
"description": "Hyperbolic tangent operator block.",
"docstringHtml": "<p>Hyperbolic tangent operator block.</p>\n<p>This block supports vector inputs. This is the operation it does:</p>\n<div class=\"math\">\n\\begin{equation*}\n\\vec{y} = \\tanh(\\vec{u})\n\\end{equation*}\n</div>\n<div class=\"section\" id=\"attributes\">\n<h3>Attributes</h3>\n<dl class=\"docutils\">\n<dt>op_alg <span class=\"classifier-delimiter\">:</span> <span class=\"classifier\">Operator</span></dt>\n<dd>internal algebraic operator</dd>\n</dl>\n</div>\n",
"params": {},
"inputs": null,
"outputs": null
},
"Abs": {
"blockClass": "Abs",