Skip to content

SlewRateLimiter unexpected behaviour #390

Open
@JavierJJR

Description

@JavierJJR

Describe the bug 🐞

SlewRateLimiter arguments cannot be passed as parameters.

Expected behavior

SlewRateLimiter arguments can be passed as parameters or as numerical values, achieving the same result.

Minimal Reproducible Example 👇

The code below shows a toy example in which arguments are passed to the SlewRateLimiter as numerical values, which indeed works.

@mtkmodel sistemslew begin

	@components begin

		source = Step(start_time = 2, height = 1)
		limiter = SlewRateLimiter(y_start=0.0, rising = 1, falling = -0.5, Td = 0.001) 

	end

	@equations begin

		connect(source.output,limiter.input)

	end

end

@mtkbuild systemlim = sistemslew()

However, if arguments are passed as parameters, @mtkbuild fails:

@mtkmodel sistemslew begin
	
	@parameters begin

		limittest = 1

	end
	
	@components begin

		source = Step(start_time = 2, height = 1)
		limiter = SlewRateLimiter(y_start=0.0, rising = limittest, falling = -0.5, Td = 0.001) 

	end

	@equations begin

		connect(source.output,limiter.input)

	end

end

@mtkbuild systemlim = sistemslew()

Error & Stacktrace ⚠️

TypeError: non-boolean (SymbolicUtils.BasicSymbolic{Bool}) used in boolean context

Stack trace
Here is what happened, the most recent locations are first:

macro expansion
from 
nonlinear.jl:105
(::ModelingToolkitStandardLibrary.Blocks.var"#137#138")()
from 
ModelingToolkitStandardLibrary  abstractsystem.jl:2436
 
SlewRateLimiter(; name::Symbol, y_start::Float64, rising::Symbolics.Num, falling::Float64, Td::Float64)
from 
ModelingToolkitStandardLibrary  abstractsystem.jl:2436
 
macro expansion
from 
abstractsystem.jl:2268
__sistemslew__(; name::Symbol, limittest::ModelingToolkit.NoValue, source__start_time::Nothing, source__height::Nothing, limiter__y_start::Nothing, limiter__rising::Nothing, limiter__falling::Nothing, limiter__Td::Nothing)
from 
julia  model_parsing.jl:920
 
__sistemslew__
from 
model_parsing.jl:140
Model
from 
model_parsing.jl:25
macro expansion
from 
abstractsystem.jl:2268
from 
[This cell: line 1](http://localhost:1234/edit?id=9d589f3e-2987-11f0-1bbe-878a80eda722#0e8412f3-ab33-4831-9382-0eaa224a1074)
[@mtkbuild systemlim = sistemslew()](http://localhost:1234/edit?id=9d589f3e-2987-11f0-1bbe-878a80eda722#0e8412f3-ab33-4831-9382-0eaa224a1074)

Additional context

I wonder whether this is a bug or if there is something I am overlooking regarding the operation of this block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions