-
-
Notifications
You must be signed in to change notification settings - Fork 217
@mtkmodel
errors when module qualifier is used to create component
#2289
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Comments
This was referenced Oct 23, 2023
This is still a problem on the latest release of MTK, the following system works fine, but if I use using Multibody
using ModelingToolkit
using JuliaSimCompiler
using OrdinaryDiffEq
using ModelingToolkitStandardLibrary.Blocks
import ModelingToolkitStandardLibrary.Mechanical.Rotational
@parameters t
D = Differential(t)
# Workarounds for @mtkmodel bugs and limitations
RTorque = Rotational.Torque
BSine = Blocks.Sine
W(args...; kwargs...) = Multibody.world
@mtkmodel ActuatedJoint begin
@components begin
world = W()
torque = RTorque()
joint = Revolute(useAxisFlange=true) # The axis flange provides an interface to the 1D torque input from ModelingToolkitStandardLibrary.Mechanical.Rotational
torque_signal = BSine(frequency=1/5)
body = BodyShape(; m = 1, r_cm = [0.4, 0, 0])
end
@equations begin
connect(world.frame_b, joint.frame_a)
connect(joint.frame_b, body.frame_a)
connect(torque_signal.output, torque.tau)
connect(torque.flange, joint.axis)
end
end
@named model = ActuatedJoint()
ssys = structural_simplify(IRSystem(model))
prob = ODEProblem(ssys, [D(D(joint.phi)) => 0], (0, 10))
sol = solve(prob, Rodas4()) julia> @mtkmodel ActuatedJoint begin
@components begin
torque = Rotational.Torque()
joint = Revolute(useAxisFlange=true) # The axis flange provides an interface to the 1D torque input from ModelingToolkitStandardLibrary.Mechanical.Rotational
torque_signal = Blocks.Sine(frequency=1/5)
body = BodyShape(; m = 1, r_cm = [0.4, 0, 0])
end
@equations begin
connect(world.frame_b, joint.frame_a)
connect(joint.frame_b, body.frame_a)
connect(torque_signal.output, torque.tau)
connect(torque.flange, joint.axis)
end
end
ERROR: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
convert(::Type{T}, ::T) where T
@ Base Base.jl:84
Symbol(::Any...)
@ Base strings/basic.jl:229
Stacktrace:
[1] setindex!(A::Vector{Symbol}, x::Expr, i1::Int64)
@ Base ./array.jl:1021
[2] _unsafe_copyto!(dest::Vector{Symbol}, doffs::Int64, src::Vector{Any}, soffs::Int64, n::Int64)
@ Base ./array.jl:299
[3] unsafe_copyto!
@ ./array.jl:353 [inlined]
[4] _copyto_impl!(dest::Array, doffs::Integer, src::Array, soffs::Integer, n::Integer)
@ Base ./array.jl:376 [inlined]
[5] copyto!
@ ./array.jl:363 [inlined]
[6] copyto!
@ ./array.jl:385 [inlined]
[7] copyto_axcheck!(dest::Any, src::Any)
@ Base ./abstractarray.jl:1174 [inlined]
[8] Vector{Symbol}(x::Vector{Any})
@ Base ./array.jl:673
[9] convert
@ Base ./array.jl:665 [inlined]
[10] push!(a::Vector{Vector{Symbol}}, item::Vector{Any})
@ Base ./array.jl:1118
[11] parse_components!(exprs::Vector{Any}, cs::Vector{Symbol}, dict::Dict{Symbol, Any}, body::Expr, kwargs::Vector{Any})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/66mEN/src/systems/model_parsing.jl:297
[12] parse_model!(exprs::Vector{…}, comps::Vector{…}, ext::Base.RefValue{…}, eqs::Vector{…}, icon::Base.RefValue{…}, vs::Vector{…}, ps::Vector{…}, sps::Vector{…}, dict::Dict{…}, mod::Module, arg::Expr, kwargs::Vector{…})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/66mEN/src/systems/model_parsing.jl:250
[13] _model_macro(mod::Module, name::Symbol, expr::Expr, isconnector::Bool)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/66mEN/src/systems/model_parsing.jl:49
[14] var"@mtkmodel"(__source__::LineNumberNode, __module__::Module, name::Symbol, body::Any)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/66mEN/src/systems/model_parsing.jl:31
[15] eval
@ ./boot.jl:385 [inlined]
[16] eval
@ ./Base.jl:88 [inlined]
[17] repleval(m::Module, code::Expr, ::String)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/VSCodeServer/src/repl.jl:229
[18] (::VSCodeServer.var"#110#112"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/VSCodeServer/src/repl.jl:192
[19] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging ./logging.jl:515
[20] with_logger
@ ./logging.jl:627 [inlined]
[21] (::VSCodeServer.var"#109#111"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/VSCodeServer/src/repl.jl:193
[22] #invokelatest#2
@ Base ./essentials.jl:887 [inlined]
[23] invokelatest(::Any)
@ Base ./essentials.jl:884
[24] (::VSCodeServer.var"#62#63")()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/VSCodeServer/src/eval.jl:34
Some type information was truncated. Use `show(err)` to see complete types. |
Ah, I noticed that no release has been made since this fix was merged |
No Sign up for free
to join this conversation on GitHub.
Already have an account?
No Sign in to comment
The following is fine
but with the namespace
Blocks
qualifying the access toConstant
, the macro errorsThe text was updated successfully, but these errors were encountered: