Skip to content

handle units for analysis points #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Blocks/analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function Base.hash(ap::AnalysisPoint, seed::UInt)
h3 ⊻ (0xd29cdc51aa6562d4 % UInt)
end

function ModelingToolkit.get_unit(ap::AnalysisPoint)
ModelingToolkit.unitless
end

function ap_var(sys)
if hasproperty(sys, :u)
# collect to turn symbolic arrays into arrays of symbols
Expand Down
24 changes: 24 additions & 0 deletions test/Blocks/test_analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,27 @@ L = CS.ss(matrices...) |> sminreal
matrices, _ = linearize(sys_outer, [:inner_plant_input], [:inner_plant_output])
G = CS.ss(matrices...) |> sminreal
@test tf(G) ≈ tf(CS.feedback(Ps, Cs))

## unit test
@mtkmodel SingleIntegrator begin
@parameters begin
to_mps = 1, [unit = u"m/s"]
end
@variables begin
(x(t) = 0), [unit = u"m", description = "Position"]
control(t), [unit = u"m/s", description = "Control Velocity"]
end
@components begin
uIn = RealInput()
c1 = Blocks.Constant(k = 1)
end
@equations begin
control ~ (uIn.u) * to_mps
D(x) ~ control
connect(c1.output, :test_point, uIn)
end
end
@mtkbuild single_integrator = SingleIntegrator()
prob = ODEProblem(single_integrator, [], (0, 10))
sol = solve(prob, Tsit5())
@test sol(10)[] ≈ 10
Loading