Skip to content

Commit 94034b2

Browse files
committed
Adds WrenchesCache
1 parent c86bc6e commit 94034b2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/RigidBodyDynamics.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export
2121
DynamicsResult,
2222
StateCache,
2323
DynamicsResultCache,
24-
SegmentedVectorCache
24+
SegmentedVectorCache,
25+
WrenchesCache
2526

2627
# specific joint types
2728
export

src/caches.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,28 @@ end
107107
@inline function makevalue(c::SegmentedVectorCache{K, KeyRange}, ::Type{T}) where {K, T, KeyRange}
108108
SegmentedVector{K, T, KeyRange}(Vector{T}(undef, c.length), c.ranges)
109109
end
110+
111+
"""
112+
$(TYPEDEF)
113+
114+
A container that manages the creation and storage of `BodyDict{Wrench{T}}`.
115+
Similar to [`StateCache`](@ref).
116+
"""
117+
struct WrenchesCache{M} <: AbstractTypeDict
118+
mechanism::Mechanism{M}
119+
keys::Vector{UInt}
120+
values::Vector # Can also be `Any`
121+
end
122+
123+
Base.show(io::IO, ::WrenchesCache{M}) where {M} = print(io, "WrenchesCache{$M}(…)")
124+
125+
WrenchesCache(mechanism::Mechanism{M}) where {M} = WrenchesCache{M}(mechanism, [], [])
126+
127+
@inline function valuetype(::Type{WrenchesCache{M}}, ::Type{T}) where {M,T}
128+
BodyDict{Wrench{T}}
129+
end
130+
131+
@inline function makevalue(c::WrenchesCache, ::Type{T}) where {T}
132+
rootframe = root_frame(c.mechanism)
133+
BodyDict{Wrench{T}}(b => zero(Wrench{T}, rootframe) for b in bodies(c.mechanism))
134+
end

0 commit comments

Comments
 (0)