pySimBlocks.blocks.operators.rate_limiter

class pySimBlocks.blocks.operators.rate_limiter.RateLimiter(name: str, rising_slope: ArrayLike = inf, falling_slope: ArrayLike = -inf, initial_output: TypeAliasForwardRef('ArrayLike') | None = None, sample_time: float | None = None)[source]

Bases: Block

Discrete-time rate limiter block.

Limits the rate of change of the output signal by constraining the maximum allowed increase and decrease per time step:

delta = u[k] - y[k-1]

y[k] = y[k-1] + clip(delta, falling_slope * dt, rising_slope * dt)

Bounds are applied component-wise and resolved on the first call. Once the input shape is resolved it must remain constant.

rising_raw

Raw rising-slope array before broadcasting.

falling_raw

Raw falling-slope array before broadcasting.

rising_slope

Broadcasted rising slope matched to the input shape, or None before the first resolution.

falling_slope

Broadcasted falling slope matched to the input shape, or None before the first resolution.

direct_feedthrough = True

True if outputs depend directly on inputs.

initialize(t0: float) None[source]

Resolve slopes from the initial input and set the initial state.

Parameters:

t0 – Initial simulation time in seconds.

Raises:
  • RuntimeError – If input 'in' is None at initialization.

  • ValueError – If input is not 2D or slopes have incompatible shapes.

output_update(t: float, dt: float) None[source]

Apply the rate limit and write the result to the output port.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:
  • RuntimeError – If input 'in' is None or the block is not initialized.

  • ValueError – If input is not 2D or its shape changed after initialization.

state_update(t: float, dt: float) None[source]

Store the current output as the previous value for the next step.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.