Skip to content

Commit

Permalink
fix: fix Blocks components
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Feb 22, 2024
1 parent b73ef27 commit 0645554
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Blocks/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys

x = collect(x)
x_scaled = collect(x_scaled)
bb = collect(bb)

sts = [x; x_scaled; y; u]

Expand Down
26 changes: 15 additions & 11 deletions src/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ function Base.show(io::IO, m::MIME"text/plain", p::Parameter)
end

get_sample_time(memory::Parameter) = memory.ref
Symbolics.@register_symbolic get_sample_time(memory)
Symbolics.@register_symbolic get_sample_time(memory::Parameter)

Base.convert(::Type{T}, x::Parameter{T}) where {T <: Real} = x.ref
function Base.convert(::Type{<:Parameter{T}}, x::Number) where {T <: Real}
Expand Down Expand Up @@ -603,8 +603,9 @@ end
function get_sampled_data(t, buffer)
get_sampled_data(t, buffer.data, buffer.ref, buffer.circular_buffer)
end
Symbolics.@register_symbolic get_sampled_data(t, buffer)
Symbolics.@register_symbolic get_sampled_data(t, buffer, dt, circular_buffer) false
Symbolics.@register_symbolic Parameter(data::Vector, ref, circular_buffer::Bool)
Symbolics.@register_symbolic get_sampled_data(t, buffer::Parameter)
Symbolics.@register_symbolic get_sampled_data(t, buffer::Vector, dt, circular_buffer) false

function Symbolics.derivative(::typeof(get_sampled_data), args::NTuple{2, Any}, ::Val{1})
t = @inbounds args[1]
Expand Down Expand Up @@ -655,21 +656,23 @@ data input component.
buffer,
sample_time,
circular_buffer = true)
T = eltype(buffer)
pars = @parameters begin
buffer = buffer #::Vector{Real}
sample_time = sample_time #::Real
circular_buffer = circular_buffer #::Bool
buffer::Vector{T} = buffer #::Vector{Real}
sample_time::T = sample_time #::Real
circular_buffer::Bool = circular_buffer #::Bool

Check warning on line 663 in src/Blocks/sources.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/sources.jl#L661-L663

Added lines #L661 - L663 were not covered by tests
end
@parameters p::Parameter{T} = Parameter(buffer, sample_time, circular_buffer)
vars = []
systems = @named begin
output = RealOutput()
end
eqs = [
output.u ~ get_sampled_data(t, buffer, sample_time, circular_buffer)
output.u ~ get_sampled_data(t, p)
]
return ODESystem(eqs, t, vars, pars; name, systems,
return ODESystem(eqs, t, vars, [pars; p]; name, systems,
defaults = [
output.u => get_sampled_data(0.0, buffer, sample_time, circular_buffer)
output.u => get_sampled_data(0.0, p)
])
end

Expand All @@ -684,9 +687,10 @@ data input component.
# Connectors:
- `output`
"""
@component function SampledData(::Val{SampledDataType.struct_based}; name, buffer)
@component function SampledData(

Check warning on line 690 in src/Blocks/sources.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/sources.jl#L690

Added line #L690 was not covered by tests
::Val{SampledDataType.struct_based}; name, buffer::Parameter)
pars = @parameters begin
buffer = buffer #::Parameter
buffer::typeof(buffer) = buffer #::Parameter

Check warning on line 693 in src/Blocks/sources.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/sources.jl#L693

Added line #L693 was not covered by tests
end
vars = []
systems = @named begin
Expand Down

0 comments on commit 0645554

Please sign in to comment.