Skip to content

Commit 9f7ff4c

Browse files
committed
add state priority option for rotation matrices
1 parent 3fcbc2f commit 9f7ff4c

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/Multibody.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ end
8282
8383
Emulates the `@variables` macro but does never creates array variables. Also never introuces the variable names into the calling scope.
8484
"""
85-
function at_variables_t(args...; default = nothing)
85+
function at_variables_t(args...; default = nothing, state_priority = nothing)
8686
xs = Symbolics.variables(args...; T = Symbolics.FnType)
8787
xs = map(x -> x(t), xs)
8888
if default !== nothing
8989
xs = Symbolics.setdefaultval.(xs, default)
9090
end
91+
if state_priority !== nothing
92+
xs = Symbolics.setmetadata.(xs, ModelingToolkit.VariableStatePriority, state_priority)
93+
end
9194
xs
9295
end
9396

src/frames.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
r_0, f, tau = collect.((r_0, f, tau))
1414
# R: Orientation object to rotate the world frame into the connector frame
1515

16-
R = NumRotationMatrix(; name, varw)
16+
R = NumRotationMatrix(; name, varw, state_priority=0)
1717

1818
ODESystem(Equation[], t, [r_0; f; tau], []; name,
1919
metadata = Dict(:orientation => R, :frame => true))

src/orientation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ The primary difference between `NumRotationMatrix` and `RotationMatrix` is that
3737
3838
- `varw`: If true, `w` is a variable, otherwise it is derived from the derivative of `R` as `w = get_w(R)`.
3939
"""
40-
function NumRotationMatrix(; R = collect(1.0I(3)), w = zeros(3), name, varw = false)
41-
R = at_variables_t(:R, 1:3, 1:3, default = R) #[description="Orientation rotation matrix ∈ SO(3)"]
40+
function NumRotationMatrix(; R = collect(1.0I(3)), w = zeros(3), name, varw = false, state_priority=nothing)
41+
R = at_variables_t(:R, 1:3, 1:3; default = R, state_priority) #[description="Orientation rotation matrix ∈ SO(3)"]
4242
# @variables w(t)[1:3]=w [description="angular velocity"]
4343
# R = collect(R)
4444
# R = ModelingToolkit.renamespace.(name, R) .|> Num

0 commit comments

Comments
 (0)