@@ -293,7 +293,6 @@ function __propagate_opspace_force!(cache::CacheBundle, mc::CMC{<:JointSubspace}
293293 nothing
294294end
295295
296-
297296_configuration (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = get_q (cache, c. coord_data. joint)
298297_velocity (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = get_q̇ (cache, c. coord_data. joint)
299298_acceleration (cache:: CacheBundle , c:: CMC{<:JointSubspace} ) = zero (get_q̇ (cache, c. coord_data. joint))
@@ -490,28 +489,16 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:QuaternionAttitude})
490489end
491490
492491function __propagate_opspace_force! (cache:: CacheBundle , cmc:: CMC{<:QuaternionAttitude} )
493- # c = cmc.coord_data
494- # fID = c.frameID
495-
496- # T⁰ᵃ = get_transform(cache, fID)
497- # R⁰ᵃ = rotor(T⁰ᵃ)
498- # ω⁰ᵃ = get_angular_vel(cache, fID)
499- # Ṙ⁰ᵃ = quaternion_derivative(R⁰ᵃ, ω⁰ᵃ)
500-
501- # Rᵗ⁰ = inv(c.target_rotation)
502-
503- # Ṙᵗᵃ = rotate(Rᵗ⁰, Ṙ⁰ᵃ, Val{false}()) # Dont normalize as this is a velocity
504-
505- # ż = bivector(Ṙᵗᵃ)
506-
507- # nothing
492+ c = cmc. coord_data
493+ rotor_wf = rotor (get_transform (cache, c. frameID))
494+ rotor_tw = inv (c. target_rotation)
495+ E_wf = Transforms. quaternion_derivative_propagation (rotor_wf)
496+ E_tw = Transforms. quatmul_matrix (rotor_tw)
497+ E = E_tw * E_wf
498+ f_view = f_cache_view (cache, cmc)
508499
509-
510- # c = cmc.coord_data
511- # R⁰ᵃ = rotor(T⁰ᵃ)
512- # τ = cross(configuration(cache, cmc), f)
513- # get_frame_torques(cache)[fID] .+= τ
514- # nothing
500+ τ = E' * SVector (0.0 , f_view[1 ], f_view[2 ], f_view[3 ])
501+ get_frame_torques (cache)[c. frameID] += τ
515502end
516503
517504_configuration (cache:: CacheBundle , cmc:: CMC{<:QuaternionAttitude} ) = SVector {length(cmc), eltype(cache)} (z_cache_view (cache, cmc))
@@ -690,14 +677,23 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:RotatedCoord})
690677end
691678
692679function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:RotatedCoord} )
680+ # Sort out inputs
693681 c = mc. coord_data
694682 f_view = f_cache_view (cache, mc)
683+ @assert length (f_view) == 3
684+ f = f_view[SVector (1 , 2 , 3 )] # Get the force applied to the coord as an SVector
695685 f_ret = f_cache_view (cache, cache[c. world_frame_coord])
686+ R = rotor (get_transform (cache, c. frameID))
687+ z:: SVector = _configuration (cache, c. world_frame_coord)
688+
689+ # Apply force R * f
690+ f_ret .+ = R * f
691+ # Apply torque R * cross(z, f)
692+ τ = cross (R* f, z)
693+ get_frame_torques (cache)[c. frameID] += τ
696694 nothing
697695end
698696
699-
700-
701697_configuration (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = SVector {length(cmc)} (z_cache_view (cache, cmc))
702698_velocity (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = SVector {length(cmc)} (ż_cache_view (cache, cmc))
703699_jacobian (cache:: CacheBundle , cmc:: CMC{<:RotatedCoord} ) = J_cache_view (cache, cmc)
@@ -747,8 +743,8 @@ function __jacobian!(cache::CacheBundle, cmc::CMC{<:UnrotatedCoord})
747743 J = J_cache_view (cache, cmc)
748744 fill! (J, zero (eltype (J))) # TODO do this once rather than every time
749745 J_ret = _vms_jacobian_result_view (cache, J, c. frameID)
750- # return RSz * -J_ωb + R⁻¹ *J_z
751- # mul!(J, RSz, -J_ωb, R⁻¹ , J_z)
746+ # return RSz * -J_ωb + R*J_z
747+ # mul!(J, RSz, -J_ωb, R, J_z)
752748 @assert length (c) == 3
753749 for i in axes (J_ret, 1 ), j in axes (J_ret, 2 )
754750 J_ij = zero (eltype (J_ret))
@@ -784,9 +780,20 @@ function __acceleration!(cache::CacheBundle, cmc::CMC{<:UnrotatedCoord})
784780end
785781
786782function __propagate_opspace_force! (cache:: CacheBundle , mc:: CMC{<:UnrotatedCoord} )
783+ # Sort out inputs
787784 c = mc. coord_data
788785 f_view = f_cache_view (cache, mc)
786+ @assert length (f_view) == 3
787+ f = f_view[SVector (1 , 2 , 3 )] # Get the force applied to the coord as an SVector
789788 f_ret = f_cache_view (cache, cache[c. link_frame_coord])
789+ R = rotor (get_transform (cache, c. frameID))
790+ z:: SVector = _configuration (cache, c. link_frame_coord)
791+
792+ # Apply force inv(R) * f
793+ f_ret .+ = inv (R) * f
794+ # Apply torque z × (inv(R) * f)
795+ τ = cross (R* z, f)
796+ get_frame_torques (cache)[c. frameID] += τ
790797 nothing
791798end
792799
0 commit comments