Skip to content

Commit ba53c32

Browse files
committed
- Simulation speed improved, if contact of FileMesh objects and/or robot path planning
- Timer included in Scene (scene.timer), so that it is more easily accessible - contactPairMaterials.json updated to get less warning messages for runtests - YouBotPingPong.jl atol slightly enlarged
1 parent 21fcaa5 commit ba53c32

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

palettes/contactPairMaterials.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
"slidingFrictionCoefficient": 0.0,
3636
"rotationalResistanceCoefficient": 0.0
3737
},
38+
"BilliardTable,BilliardCue": {
39+
"responseType": "ElasticResponse",
40+
"coefficientOfRestitution": 0.0,
41+
"slidingFrictionCoefficient": 0.8,
42+
"rotationalResistanceCoefficient": 0.01
43+
},
44+
"BilliardCue,BilliardCue": {
45+
"responseType": "ElasticResponse",
46+
"coefficientOfRestitution": 0.98,
47+
"slidingFrictionCoefficient": 0.0,
48+
"rotationalResistanceCoefficient": 0.0
49+
},
3850
"Observer,Steel": {
3951
"responseType": "ObserverResponse",
4052
"printAlarm": true

src/Composition/dynamics.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ end
8282

8383

8484

85-
function initAnalysis2!(world)
85+
function initAnalysis2!(world, timer)
8686
# use Scene(..) of world object
8787
if typeof(world.feature) <: Modia3D.Composition.Scene
8888
scene = world.feature
8989
else
9090
error("Internal error of Modia3D: typeof(world.feature) = ", typeof(world.feature), ", but must be Modia3D.Composition.Scene")
9191
end
9292
scene.analysis = Modia3D.DynamicAnalysis
93+
scene.timer = timer
9394

9495
Modia3D.Composition.chooseAndBuildUpTree(world, scene)
9596

@@ -114,14 +115,16 @@ function instantiateModel3D!(partiallyInstantiatedModel::Modia.SimulationModel{F
114115
end
115116
mbsBuild::MultibodyBuild{F,TimeType} = partiallyInstantiatedModel.buildDict[modelPath]
116117
(world, revoluteObjects, prismaticObjects, freeMotionObjects, hiddenJointObjects, forceElements) = checkMultibodySystemAndGetWorldAndJointsAndForceElements(modelDict, modelPath, F)
117-
118+
119+
# Set timer in scene (so that timer is easily available in Modia3D functions)
120+
118121
# Initialize force elements
119122
for force in forceElements
120123
initializeForceElement(force)
121124
end
122125

123126
# Construct MultibodyData
124-
scene = initAnalysis2!(world)
127+
scene = initAnalysis2!(world,partiallyInstantiatedModel.timer)
125128
scene.forceElements = forceElements
126129
if scene.options.enableContactDetection && scene.collide
127130
nz = 2
@@ -372,7 +375,7 @@ function computeGeneralizedForces!(mbs::MultibodyData{F,TimeType}, qdd_hidden::V
372375
terminateForceElement(force)
373376
end
374377
if exportAnimation
375-
Modia3D.exportAnimation(scene)
378+
TimerOutputs.@timeit instantiatedModel.timer "Modia3D_4b exportAnimation" Modia3D.exportAnimation(scene)
376379
end
377380
if visualize
378381
#println("... time = $time: visualization is closed")

src/Composition/scene.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ mutable struct Scene{F <: Modia3D.VarFloatType} <: Modia3D.AbstractScene
434434
exportAnimation::Bool # animation file export is enabled
435435
animation::Vector{animationStep} # animation data of visible Object3Ds
436436
outputCounter::Int64 # animation/visualization output step counter
437-
437+
timer::TimerOutputs.TimerOutput # Timer
438+
438439
function Scene{F}(;gravityField = UniformGravityField(),
439440
useOptimizedStructure = true,
440441
enableContactDetection = true,

src/PathPlanning/referencePathInternal.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ end
3232

3333
ReferencePath(; names, position, v_max, a_max) = ReferencePath(names, position=position, v_max=v_max, a_max=a_max)
3434

35-
getRefPathPosition(referencePath, index) = referencePath.position[index]
36-
getRefPathPosition(; referencePath, index) = referencePath.position[index]
35+
getRefPathPosition(referencePath::ReferencePath, index)::Float64 = referencePath.position[index]
36+
getRefPathPosition(; referencePath::ReferencePath, index)::Float64 = referencePath.position[index]
3737

38-
getRefPathInitPosition(referencePath, index) = referencePath.initPos[index]
39-
getRefPathInitPosition(; referencePath, index) = referencePath.initPos[index]
38+
getRefPathInitPosition(referencePath::ReferencePath, index)::Float64 = referencePath.initPos[index]
39+
getRefPathInitPosition(; referencePath::ReferencePath, index)::Float64 = referencePath.initPos[index]
4040

4141

4242
## -------------------- utility functions ------------------------

src/PathPlanning/referencePathUser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
calculateRobotMovement(; referencePath, instantiatedModel) = calculateRobotMovement(referencePath, instantiatedModel)
4141

4242

43-
function calculateRobotMovement(referencePath, instantiatedModel)
43+
function calculateRobotMovement(referencePath, instantiatedModel)::ReferencePath
4444
referencePath.instantiatedModel = instantiatedModel
4545
if Modia.isEvent(instantiatedModel)
4646
if Modia.getTime(instantiatedModel) < referencePath.nextEventTime

src/Shapes/boundingBoxes.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,21 @@ end
247247

248248
# [Gino v.d. Bergen, p. 131]
249249
@inline function supportPoint_abs_FileMesh(shape::FileMesh, e_abs::SVector{3,T}) where {T}
250-
e_absVec = Vector{SVector{3,Float64}}(undef, 1)
251-
e_absVec[1] = e_abs
252-
(max_value, position) = findmax(broadcast(dot, shape.objPoints, e_absVec))
253-
return SVector{3,T}(shape.objPoints[position])
250+
#e_absVec = Vector{SVector{3,Float64}}(undef, 1)
251+
#e_absVec[1] = e_abs
252+
#(max_value, position) = findmax(broadcast(dot, shape.objPoints, e_absVec))
253+
#return SVector{3,T}(shape.objPoints[position])
254+
iMax::Int = 1
255+
dotMax::T = typemin(T)
256+
objPoints = shape.objPoints
257+
for i in 2:length(shape.objPoints)
258+
doti = dot(objPoints[i],e_abs)
259+
if doti > dotMax
260+
iMax = i
261+
dotMax = doti
262+
end
263+
end
264+
return objPoints[iMax]
254265
end
255266

256267

test/Robot/YouBotPingPong.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ YouBot = Model(
403403
]
404404
)
405405

406+
animationFile = nothing # "YouBotPingPong.json"
407+
406408
Setup = Model3D(
407409
gravField = UniformGravityField(g=9.81, n=[0,0,-1]),
408-
world = Object3D(feature=Scene(gravityField = :gravField, visualizeFrames=false, defaultFrameLength=0.1, enableContactDetection=true, elasticContactReductionFactor=1e-4, animationFile="YouBotPingPong.json")),
410+
world = Object3D(feature=Scene(gravityField = :gravField, visualizeFrames=false, defaultFrameLength=0.1, enableContactDetection=true, elasticContactReductionFactor=1e-4, animationFile=animationFile)),
409411

410412
# worldFrame = Object3D(parent=:world, feature=Visual(shape=CoordinateSystem(length = 0.5))),
411413

@@ -488,6 +490,6 @@ stopTime = 5.0
488490
testTime = 2.6
489491
tolerance = 1e-6
490492
requiredFinalStates = [-1.1074556140316614e-6, -1.5708081309224846e-6, 0.004318767918916739, -0.0549812598198102, 0.018341522563563008, -0.23292171811699988, -2.5341253706630947e-5, 9.563659404612395e-6, 9.861885194446625e-8, -3.757389500092675e-8, -0.008203268519548534, 0.08427992925773496, -0.19863732806446607, -0.08581303210589916, 0.00033018352089870753, -1.107374319291623e-6, -1.5708894244394602e-6, 0.004318767892034848, -0.05498125979294491, 0.018341522525621993, -0.23292171807905454, -2.534127375344645e-5, 9.563679456627568e-6, 9.861972648175242e-8, -3.757476953751818e-8, -0.008202647095242736, 0.08427972378938253, -0.1986375139486019, -0.0858131018343996, 0.00033018656336086143, -1.1076332038804084e-6, -1.570630545802361e-6, 0.00431876794815167, -0.05498125984904925, 0.01834152268185664, -0.2329217182353066, -2.5341236324870474e-5, 9.563642013267081e-6, 9.862522850475129e-8, -3.7580271495454505e-8, -0.00820462603190175, 0.08428015268900449, -0.1986367484856495, -0.08581297166285347, 0.0003302057050821647, -0.03107629005920148, -0.11131736138141905, 0.029896045936138697, 0.0018082551499392894, -0.018396779235415803, 3.1826341520734124e-6, 6.1275964621094055, -0.10267792277688194, -3.1963406592895636, -0.7350913822598424, -0.11253294292231224, -0.06489318279480064, -0.021320234786303613, -0.04304478478736012, 0.029894390269836604, 4.499196003772979e-12, 3.98359080421212e-12, -2.0225449533754707e-6, 2.688971437372173, 1.0539016808167536, 5.598938367809748, 6.824630606488717e-11, -9.551796829092543e-11, -1.2846294770681155e-10, 0.03278182072933573, 0.08627491647113615, 0.02989410442603615, -9.134345911291685e-16, -6.016262742751276e-16, -1.1465087059050158e-6, 2.9389929706895837, -0.6690095278820727, 1.2906797902967708, 2.8803597502216844e-14, -8.898905061806922e-15, -6.453264767699427e-15]
491-
simulate!(youbot, stopTime=testTime, tolerance=tolerance, requiredFinalStates_atol=0.001, log=true, logStates=false, requiredFinalStates=requiredFinalStates)
493+
simulate!(youbot, stopTime=testTime, tolerance=tolerance, requiredFinalStates_atol=0.02, log=true, logStates=false, requiredFinalStates=requiredFinalStates)
492494

493495
end

0 commit comments

Comments
 (0)