Skip to content

Commit 78c40cc

Browse files
committed
Add get minimal velocity function
1 parent 7881fe5 commit 78c40cc

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/joints/rotational.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,12 @@ end
256256
q = stateb.qc / joint.qoffset
257257
return nullspacemat(joint) * rotation_vector(q)
258258
end
259+
@inline function minimalVelocities(joint::Rotational, body1::Body, body2::Body)
260+
statea = body1.state
261+
stateb = body2.state
262+
return nullspacemat(joint) * (vrotate(stateb.ωc,statea.qc\stateb.qc) - statea.ωc) # in body1's frame
263+
end
264+
@inline function minimalVelocities(joint::Rotational, body1::Origin, body2::Body)
265+
stateb = body2.state
266+
return nullspacemat(joint) * vrotate(stateb.ωc,stateb.qc) # in body1's frame
267+
end

src/joints/translational.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,12 @@ end
255255
stateb = body2.state
256256
return nullspacemat(joint) * g(joint, stateb.xc, stateb.qc)
257257
end
258+
@inline function minimalVelocities(joint::Translational, body1::Body, body2::Body)
259+
statea = body1.state
260+
stateb = body2.state
261+
return nullspacemat(joint) * (stateb.vc - statea.vc)
262+
end
263+
@inline function minimalVelocities(joint::Translational, body1::Origin, body2::Body)
264+
stateb = body2.state
265+
return nullspacemat(joint) * stateb.vc
266+
end

src/main_components/equalityconstraint.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ end
118118
return :(svcat($(vec...)))
119119
end
120120

121+
@generated function minimalVelocities(mechanism, eqc::EqualityConstraint{T,N,Nc}) where {T,N,Nc}
122+
vec = [:(minimalVelocities(eqc.constraints[$i], getbody(mechanism, eqc.parentid), getbody(mechanism, eqc.childids[$i]))) for i = 1:Nc]
123+
return :(svcat($(vec...)))
124+
end
125+
121126
@inline function GtλTof!(mechanism, body::Body, eqc::EqualityConstraint)
122127
isactive(eqc) && (body.state.d -= zerodimstaticadjoint(∂g∂ʳpos(mechanism, eqc, body.id)) * eqc.λsol[2])
123128
return

0 commit comments

Comments
 (0)