Skip to content

Commit 0442f7e

Browse files
committed
pass along quaternion variables
1 parent 2a8b085 commit 0442f7e

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/components.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ This component has a single frame, `frame_a`. To represent bodies with more than
411411
if quat
412412
@named frame_a = Frame(varw=false)
413413
Ra = ori(frame_a, false)
414-
qeeqs = nonunit_quaternion_equations(Ra, w_a)
414+
qeeqs, qvars, qpars = nonunit_quaternion_equations(Ra, w_a)
415+
vars = [vars; qvars]
416+
pars = [pars; qpars]
417+
qeeqs
415418
else
416419
@named frame_a = Frame(varw=false)
417420
Ra = ori(frame_a, false)

src/joints.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ Joint with 3 constraints that define that the origin of `frame_a` and the origin
225225

226226
if state
227227
if quat
228-
append!(eqs, nonunit_quaternion_equations(Rrel, w_rel))
228+
qeeqs, qvars, qpars = nonunit_quaternion_equations(Rrel, w_rel)
229+
vars = [vars; qvars]
230+
pars = [pars; qpars]
231+
eqs = [eqs; qeeqs]
232+
# append!(eqs, nonunit_quaternion_equations(Rrel, w_rel))
229233
# append!(eqs, collect(w_rel) .~ angularVelocity2(Rrel))
230234
else
231235
@variables begin
@@ -542,7 +546,11 @@ The relative position vector `r_rel_a` from the origin of `frame_a` to the origi
542546
end
543547

544548
if quat
545-
append!(eqs, nonunit_quaternion_equations(Rrel, w_rel_b))
549+
qeeqs, qvars, qpars = nonunit_quaternion_equations(Rrel, w_rel_b)
550+
vars = [vars; qvars]
551+
pars = [pars; qpars]
552+
eqs = [eqs; qeeqs]
553+
# append!(eqs, nonunit_quaternion_equations(Rrel, w_rel_b))
546554
else
547555
morevars = @variables begin
548556
(phi(t)[1:3] = phi), [state_priority = state_priority, description = "3 angles to rotate frame_a into frame_b"]

src/orientation.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,20 @@ function get_frame(sol, frame, t)
436436
end
437437

438438
function nonunit_quaternion_equations(R, w)
439-
@variables Q(t)[1:4], [state_priority=-1, description="Unit quaternion with [w,i,j,k]"] # normalized
440-
@variables (t)[1:4]=[1,0,0,0], [state_priority=1000, description="Non-unit quaternion with [w,i,j,k]"] # Non-normalized
441-
@variables Q̂d(t)[1:4], [state_priority=1000]
442-
# NOTE:
443-
@variables n(t) c(t)
444-
@parameters k = 0.1
445-
= collect(Q̂)
446-
Q̂d = collect(Q̂d)
447-
Q = collect(Q)
439+
vars = @variables begin
440+
Q(t)[1:4], [state_priority=-1, description="Unit quaternion with [w,i,j,k]"] # normalized
441+
(t)[1:4]=[1,0,0,0], [state_priority=1000, description="Non-unit quaternion with [w,i,j,k]"] # Non-normalized
442+
Q̂d(t)[1:4], [state_priority=1000]
443+
# NOTE:
444+
n(t)
445+
c(t)
446+
end
447+
pars = @parameters begin
448+
k = 0.1
449+
end
450+
# Q̂ = collect(Q̂)
451+
# Q̂d = collect(Q̂d)
452+
# Q = collect(Q)
448453
# w is used in Ω, and Ω determines D(Q̂)
449454
# This corresponds to modelica's
450455
# frame_a.R = from_Q(Q, angularVelocity2(Q, der(Q)));
@@ -454,7 +459,7 @@ function nonunit_quaternion_equations(R, w)
454459

455460
# QR = from_Q(Q, angular_velocity2(Q, D.(Q)))
456461
QR = from_Q(Q̂ ./ sqrt(n), w)
457-
[
462+
eqs = [
458463
n ~'
459464
c ~ k * (1 - n)
460465
D.(Q̂) .~ Q̂d
@@ -463,6 +468,7 @@ function nonunit_quaternion_equations(R, w)
463468
R ~ from_Q(Q, w)
464469
# R.w .~ angularVelocity2(Q̂, Q̂d)
465470
]
471+
eqs, vars, pars
466472
end
467473

468474
# function angularVelocity2(Q, der_Q)

0 commit comments

Comments
 (0)