Wrapper¶
- class pathsim.blocks.wrapper.Wrapper(func=None, T=1, tau=0)[source]¶
Bases:
BlockWrapper block for discrete implementation and external code integration.
The Wrapper class is designed to call the internal func at fixed intervals using an internal Schedule event. This makes it particularly useful for wrapping external code or implementing discrete-time systems.
Essentially this block does the same as Function with the difference that its not evaluated continuously but periodically at discrete times.
Example
There are two ways to setup the Wrapper, first and standard way is to define a function to be wrapped and pass it to the block initializer:
from pathsim.blocks import Wrapper #function to be wrapped def func(a, b, c): return a * (b + c) wrp = Wrapper(func, T=0.1)
Another option is to use the dec classmethod, which might be more convenient in some situations:
from pathsim.blocks import Wrapper @Wrapper.dec(T=0.1) def wrp(a, b, c): return a * (b + c)
This way the internal function of the block wrp will be evaluated with a period of T=0.1 and its outputs updated accordingly.
- Parameters:
- update(t)[source]¶
Update system equation for fixed point loop.
Note
No direct passthrough, the Wrapper block doesnt implement the update method. The behavior is defined by the func arg.
- Parameters:
t (float) – evaluation time
- property T¶
Get the sampling period of the block
- Returns:
T – sampling period for the Schedule event
- Return type: