-
-
Notifications
You must be signed in to change notification settings - Fork 232
Description
Hi!
If I want to port a satellite simulator to MTK, I will need to have some variables that has custom types. For example, for the attitude, I might want to use quaternions that has a specific algebra for multiplication and propagation given an angular velocity. I know I can model all the algebra inside MTK, but it will not be optimal since we have packages that implement the quaternion algebra already.
I tried with this MWE:
using ModelingToolkit
using OrdinaryDiffEq
using ReferenceFrameRotations
import Base: zero
zero(::Type{Quaternion{T}}) where T = Quaternion{T}(0, 0, 0, 0)
@variables t x(t)
D = Differential(t)
@named quat_model = ODESystem(D(x) ~ Quaternion{Float64}(0, 0, 0, 0))
prob = ODEProblem(quat_model, [x => Quaternion(1.0, 0.0, 0.0, 0.0)], (0.0, 10.0))
sol = solve(prob, Tsit5())
However, this returns the following error:
ERROR: LoadError: setindex! not defined for Quaternion{Float64}
I just cannot set the method setindex!
for Quaternion
because it is immutable.
Is there any plan to support variables with custom types?
Note: The Quaternion
of Quaternions.jl works because it is <: Number
whereas Quaternion
of ReferenceFrameRotations.jl is <:AbstractVector
. For some specificities involving how the attitude is propagated, it is better to treat a quaternion as a 4x1 vector.