6262
6363@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:CoordDifference} ) = nothing
6464
65+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:CoordDifference} )
66+ f_view = f_cache_view (cache, mc)
67+ f_cache_view (cache, cache[mc. coord_data. parent]) .+ = f_view
68+ f_cache_view (cache, cache[mc. coord_data. child]) .- = f_view
69+ nothing
70+ end
71+
6572function _configuration (cache:: CacheBundle , c:: CMC{<:CoordDifference} )
6673 z_p = _configuration (cache, c. coord_data. parent)
6774 z_c = _configuration (cache, c. coord_data. child)
106113
107114@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:CoordSum} ) = nothing
108115
116+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:CoordSum} )
117+ f_view = f_cache_view (cache, mc)
118+ f_cache_view (cache, cache[mc. coord_data. c1]) .+ = f_view
119+ f_cache_view (cache, cache[mc. coord_data. c2]) .+ = f_view
120+ nothing
121+ end
122+
123+
109124function _configuration (cache:: CacheBundle , c:: CMC{<:CoordSum} )
110125 z_1 = _configuration (cache, c. coord_data. c1)
111126 z_2 = _configuration (cache, c. coord_data. c2)
@@ -131,15 +146,16 @@ end
131146# CoordStack
132147# ###################################################################################################
133148
134- @inline __configuration! (cache:: CacheBundle , c:: CMC{<:CoordStack} ) = nothing
135- @inline __velocity! (cache:: CacheBundle , c:: CMC{<:CoordStack} ) = nothing
136- function __jacobian! (cache:: CacheBundle , c:: CMC{<:CoordStack} )
137- J_ret = J_cache_view (cache, c)
149+ @inline __configuration! (cache:: CacheBundle , mc:: CMC{<:CoordStack} ) = nothing
150+ @inline __velocity! (cache:: CacheBundle , mc:: CMC{<:CoordStack} ) = nothing
151+ function __jacobian! (cache:: CacheBundle , mc:: CMC{<:CoordStack} )
152+ c = mc. coord_data
153+ J_ret = J_cache_view (cache, mc)
138154 fill! (J_ret, zero (eltype (J_ret)))
139- J_ret_1 = _vms_jacobian_result_view (cache, J_ret, c. coord_data . c1)
140- J_ret_2 = _vms_jacobian_result_view (cache, J_ret, c. coord_data . c2)
141- J1 = _jacobian (cache, c. coord_data . c1)
142- J2 = _jacobian (cache, c. coord_data . c2)
155+ J_ret_1 = _vms_jacobian_result_view (cache, J_ret, c. c1)
156+ J_ret_2 = _vms_jacobian_result_view (cache, J_ret, c. c2)
157+ J1 = _jacobian (cache, c. c1)
158+ J2 = _jacobian (cache, c. c2)
143159 # Instead, do it manually
144160 Nc1 = size (J1, 1 )
145161 J_ret_1[1 : Nc1, :] .= J1
@@ -148,6 +164,19 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:CoordStack})
148164end
149165@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:CoordStack} ) = nothing
150166
167+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:CoordStack} )
168+ f_view = f_cache_view (cache, mc)
169+ f2 = f_cache_view (cache, cache[mc. coord_data. c2])
170+ f1 = f_cache_view (cache, cache[mc. coord_data. c1])
171+ for i in 1 : length (f1)
172+ f1[i] += f_view[i]
173+ end
174+ for i in 1 : length (f2)
175+ f2[i] += f_view[i+ length (f1)]
176+ end
177+ nothing
178+ end
179+
151180function _configuration (cache:: CacheBundle , c:: CMC{<:CoordStack} )
152181 z1 = _configuration (cache, c. coord_data. c1)
153182 z2 = _configuration (cache, c. coord_data. c2)
179208@inline __jacobian! (cache:: CacheBundle , c:: CMC{<:CoordSlice} ) = nothing
180209@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:CoordSlice} ) = nothing
181210
211+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:CoordSlice} )
212+ f_applied = f_cache_view (cache, mc)
213+ f_ret = f_cache_view (cache, mc. coord_data. coord)
214+ for (i, idx) in enumerate (mc. coord_data. idxs)
215+ f_ret[idx] += f_applied[i]
216+ end
217+ nothing
218+ end
219+
182220function _configuration (cache:: CacheBundle , c:: CMC{<:CoordSlice} )
183221 _configuration (cache, c. coord_data. coord)[c. coord_data. idxs]
184222end
@@ -206,6 +244,7 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:ConstCoord})
206244 nothing
207245end
208246@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:ConstCoord} ) = nothing
247+ @inline __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:ConstCoord} ) = nothing
209248
210249_configuration (cache:: CacheBundle , c:: CMC{<:ConstCoord{Nc, Tc}} ) where {Tc, Nc} = SVector {Nc, eltype(cache)} (c. coord_data. val)
211250_velocity (cache:: CacheBundle , c:: CMC{<:ConstCoord{Nc, Tc}} ) where {Tc, Nc} = zero (SVector{Nc, eltype (cache)})
@@ -224,6 +263,7 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:ReferenceCoord})
224263 nothing
225264end
226265@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:ReferenceCoord} ) = nothing
266+ @inline __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:ReferenceCoord} ) = nothing
227267
228268_configuration ( cache:: CacheBundle , c:: CMC{<:ReferenceCoord{Nc, Tc}} ) where {Tc, Nc} = SVector {Nc, eltype(cache)} (c. coord_data. val[])
229269_velocity ( cache:: CacheBundle , c:: CMC{<:ReferenceCoord{Nc, Tc}} ) where {Tc, Nc} = SVector {Nc, eltype(cache)} (c. coord_data. vel[])
@@ -246,6 +286,13 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:JointSubspace})
246286 nothing
247287end
248288@inline __acceleration! (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = nothing
289+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:JointSubspace} )
290+ f_view = f_cache_view (cache, mc)
291+ @assert length (f_view) == 1
292+ _apply_joint_force_to_frames! (cache, mc. coord_data. joint, f_view[1 ])
293+ nothing
294+ end
295+
249296
250297_configuration (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = get_q (cache, c. coord_data. joint)
251298_velocity (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = get_q̇ (cache, c. coord_data. joint)
@@ -364,7 +411,10 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:FrameOrigin})
364411 nothing
365412end
366413__acceleration! (cache:: CacheBundle , c:: CMC{<:FrameOrigin} ) = nothing
367- __propagate_opspace_force! (cache:: CacheBundle , c:: CMC{<:FrameOrigin} ) = get_frame_forces (cache)[c. coord_data. frameID] += f_cache_view (cache, c)
414+ function __propagate_opspace_force! (cache:: CacheBundle , c:: CMC{<:FrameOrigin} )
415+ get_frame_forces (cache)[c. coord_data. frameID] += f_cache_view (cache, c)
416+ nothing
417+ end
368418
369419_configuration (cache:: CacheBundle , c:: CMC{<:FrameOrigin} ) = origin (get_transform (cache, c. coord_data. frameID))
370420_velocity (cache:: CacheBundle , c:: CMC{<:FrameOrigin} ) = get_linear_vel (cache, c. coord_data. frameID)
@@ -439,7 +489,7 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:QuaternionAttitude})
439489 α_cache_view (cache, cmc) .= bivector (ddrotor_tf)
440490end
441491
442- # function __propagate_opspace_force!(cache::CacheBundle, cmc::CMC{<:QuaternionAttitude}, f )
492+ function __propagate_opspace_force! (cache:: CacheBundle , cmc:: CMC{<:QuaternionAttitude} )
443493# c = cmc.coord_data
444494# fID = c.frameID
445495
462512# τ = cross(configuration(cache, cmc), f)
463513# get_frame_torques(cache)[fID] .+= τ
464514# nothing
465- # end
515+ end
466516
467517_configuration (cache:: CacheBundle , cmc:: CMC{<:QuaternionAttitude} ) = SVector {length(cmc), eltype(cache)} (z_cache_view (cache, cmc))
468518_velocity (cache:: CacheBundle , cmc:: CMC{<:QuaternionAttitude} ) = SVector {length(cmc), eltype(cache)} (ż_cache_view (cache, cmc))
@@ -484,11 +534,6 @@ function __jacobian!(cache::CacheBundle, c::CMC{<:FrameAngularVelocity})
484534end
485535__acceleration! (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = nothing
486536
487- # _configuration(cache::MechanismCacheBundle, c::CMC{<:FrameAngularVelocity}) = rotor(transform(cache, c.coord_data.frameID))
488- _velocity (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = get_angular_vel (cache, c. coord_data. frameID)
489- _jacobian (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = J_cache_view (cache, c)
490- _acceleration (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = _get_angular_acc (cache, c. coord_data. frameID)
491-
492537function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:FrameAngularVelocity} )
493538 c = mc. coord_data
494539 f_view = f_cache_view (cache, mc)
@@ -499,6 +544,10 @@ function __propagate_opspace_force!(cache::CacheBundle, mc::CMC{<:FrameAngularVe
499544 nothing
500545end
501546
547+ # _configuration(cache::MechanismCacheBundle, c::CMC{<:FrameAngularVelocity}) = rotor(transform(cache, c.coord_data.frameID))
548+ _velocity (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = get_angular_vel (cache, c. coord_data. frameID)
549+ _jacobian (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = J_cache_view (cache, c)
550+ _acceleration (cache:: CacheBundle , c:: CMC{<:FrameAngularVelocity} ) = _get_angular_acc (cache, c. coord_data. frameID)
502551
503552# ###################################################################################################
504553# CoordNorm
@@ -546,6 +595,20 @@ function __acceleration!(cache::CacheBundle, c::CMC{<:CoordNorm})
546595 α_cache_view (cache, c) .= αᵢ
547596end
548597
598+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:CoordNorm} )
599+ c = mc. coord_data
600+ f_view = f_cache_view (cache, mc)
601+ @assert length (f_view) == 1
602+ f_ret = f_cache_view (cache, cache[c. coord])
603+ zₐ = _configuration (cache, c. coord)
604+ zᵢ = _configuration (cache, mc)
605+ for i in 1 : length (f_ret)
606+ f_ret[i] += f_view[1 ] * zₐ[i] / zᵢ[1 ]
607+ end
608+ nothing
609+ end
610+
611+
549612_configuration (cache:: CacheBundle , c:: CMC{<:CoordNorm} ) = SVector (z_cache_view (cache, c)[1 ])
550613_velocity (cache:: CacheBundle , c:: CMC{<:CoordNorm} ) = SVector (ż_cache_view (cache, c)[1 ])
551614_jacobian (cache:: CacheBundle , c:: CMC{<:CoordNorm} ) = J_cache_view (cache, c)
@@ -626,6 +689,15 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:RotatedCoord})
626689 nothing
627690end
628691
692+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:RotatedCoord} )
693+ c = mc. coord_data
694+ f_view = f_cache_view (cache, mc)
695+ f_ret = f_cache_view (cache, cache[c. world_frame_coord])
696+ nothing
697+ end
698+
699+
700+
629701_configuration (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = SVector {length(cmc)} (z_cache_view (cache, cmc))
630702_velocity (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = SVector {length(cmc)} (ż_cache_view (cache, cmc))
631703_jacobian (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = J_cache_view (cache, cmc)
@@ -711,6 +783,13 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:UnrotatedCoord})
711783 nothing
712784end
713785
786+ function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:UnrotatedCoord} )
787+ c = mc. coord_data
788+ f_view = f_cache_view (cache, mc)
789+ f_ret = f_cache_view (cache, cache[c. link_frame_coord])
790+ nothing
791+ end
792+
714793_configuration (cache:: CacheBundle , cmc:: CMC{<:UnrotatedCoord} ) = SVector {length(cmc)} (z_cache_view (cache, cmc))
715794_velocity (cache:: CacheBundle , cmc:: CMC{<:UnrotatedCoord} ) = SVector {length(cmc)} (ż_cache_view (cache, cmc))
716795_jacobian (cache:: MechanismCacheBundle , cmc:: CMC{<:UnrotatedCoord} ) = J_cache_view (cache, cmc)
0 commit comments