Skip to content

Commit 826fb7e

Browse files
Fix start index of collision dectection zero crossing function
1 parent 47f1be9 commit 826fb7e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Composition/dynamics.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct MultibodyData{FloatType}
9393
jointObjects::Vector{Object3D} # References to Object3Ds that have a joint
9494
jointStartIndex::Vector{Int} # Start index of joint in qdd
9595
jointNdof::Vector{Int} # Number-of-degrees-of-freedom of joint
96-
zStartIndex::Int # eventHandler.z[zStartIndex] is first index of crossing function
96+
zStartIndex::Int # eventHandler.z[zStartIndex] is first index of crossing functions for contact detection
9797
# (or zero, if nableContactDetection=false)
9898
nz::Int # Number of used zero crossing functions
9999
residuals::Vector{FloatType} # Residuals - length(residuals) = nqdd
@@ -141,6 +141,7 @@ function setModiaJointVariables!(id::Int, _leq_mode, instantiatedModel::ModiaLan
141141
if scene.options.enableContactDetection
142142
nz = 2
143143
zStartIndex = ModiaLang.addZeroCrossings(instantiatedModel, nz)
144+
scene.zStartIndex = zStartIndex
144145
else
145146
nz = 0
146147
zStartIndex = 0

src/Composition/scene.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ mutable struct Scene
514514
noCPairs::Vector{Vector{Int64}} # Indices of frames (with respect to collSuperObjs) that can't collide in general (e.g. objects are connected via joints)
515515
noCPairsHelp::Dict{Modia3D.AbstractJoint,Vector{Int64}}
516516
allowedToMove::Vector{Union{Bool,Nothing}}
517-
AABB::Vector{Vector{Basics.BoundingBox}} # Bounding boxes of elements that can collide
517+
AABB::Vector{Vector{Basics.BoundingBox}} # Bounding boxes of elements that can collide
518+
zStartIndex::Int # start index of collision zero crossing functions
518519
#forceElements::Vector{Int64}
519520
exportAnimation::Bool # animation file export is enabled
520521
animation::Vector{animationStep} # animation data of visible Object3Ds
@@ -557,10 +558,10 @@ mutable struct Scene
557558
Dict{Modia3D.AbstractJoint,Vector{Int64}}(),
558559
Vector{Union{Bool}}[],
559560
Vector{Vector{Basics.BoundingBox}}[],
561+
1,
560562
exportAnimation,
561563
Vector{animationStep}[],
562564
0,
563-
564565
Revolute[],
565566
Prismatic[],
566567
FreeMotion[])

src/contactDetection/ContactDetectionMPR/handler.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ function selectContactPairs!(sim, scene::Composition.Scene, ch::Composition.Cont
7979
# z[1] ... zero crossing function from contact to no contact
8080
# max. distance (= min. penetration) of active contact pairs
8181
if isempty(ch.contactDict)
82-
@inbounds simh.z[1] = -42.0
82+
@inbounds simh.z[scene.zStartIndex] = -42.0
8383
else
8484
(pair, key) = findmax(ch.contactDict)
85-
@inbounds simh.z[1] = pair.distanceWithHysteresis
85+
@inbounds simh.z[scene.zStartIndex] = pair.distanceWithHysteresis
8686
end
8787
# z[2] ... zero crossing function from no contact to contact
8888
# min. distance of inactive contact pairs
89-
@inbounds simh.z[2] = ch.noContactMinVal
89+
@inbounds simh.z[1+scene.zStartIndex] = ch.noContactMinVal
9090
end
9191
ch.distanceComputed = true
9292
return nothing

0 commit comments

Comments
 (0)