|
| 1 | +module BouncingSphereContactResultsSimulation |
| 2 | + |
| 3 | +using Modia3D |
| 4 | + |
| 5 | +BouncingSphere = Model3D( |
| 6 | + boxHeigth = 0.1, |
| 7 | + groundMaterial = VisualMaterial(color="DarkGreen", transparency=0.5), |
| 8 | + gravField = UniformGravityField(g=9.81, n=[0, -1, 0]), |
| 9 | + world = Object3D(feature=Scene(gravityField=:gravField, |
| 10 | + visualizeFrames=false, |
| 11 | + defaultFrameLength=0.2, |
| 12 | + enableContactDetection=true, |
| 13 | + visualizeContactPoints=true)), |
| 14 | + worldFrame = Object3D(parent=:world, feature=Visual(shape=CoordinateSystem(length=0.5))), |
| 15 | + ground = Object3D(parent=:world, |
| 16 | + translation=:[0.0, -boxHeigth/2, 0.0], |
| 17 | + feature=Solid(shape=Box(lengthX=2.0, lengthY=:boxHeigth, lengthZ=0.5), |
| 18 | + visualMaterial=:groundMaterial, |
| 19 | + solidMaterial="Steel", |
| 20 | + collision=true)), |
| 21 | + sphere = Object3D(parent=:world, fixedToParent=false, |
| 22 | + translation=[-0.5, 0.3, 0.0], |
| 23 | + velocity=[1.0, 0.0, 0.0], |
| 24 | + feature=Solid(shape=Sphere(diameter=0.2), |
| 25 | + visualMaterial=VisualMaterial(color="Blue"), |
| 26 | + solidMaterial="Steel", |
| 27 | + massProperties=MassPropertiesFromShapeAndMass(mass=10000.0), |
| 28 | + collision=true)), |
| 29 | + result = ContactResult(object1=:sphere, object2=:ground, objectCoordinateRef=:ground) |
| 30 | +) |
| 31 | + |
| 32 | +bouncingSphere = @instantiateModel(BouncingSphere, unitless=true, log=false, logStateSelection=false, logCode=false, FloatType=Float64) |
| 33 | + |
| 34 | +stopTime = 1.5 |
| 35 | +dtmax = 0.05 |
| 36 | +tolerance = 1e-8 |
| 37 | +requiredFinalStates = [0.6190964322303429, 0.09989803187140613, 0.0, 0.7018335184646917, -0.00011551585213889106, 0.0, 0.0, 0.0, -9.171436344350457, 0.0, 0.0, -7.0240720401621495] |
| 38 | +simulate!(bouncingSphere, stopTime=stopTime, tolerance=tolerance, dtmax=dtmax, log=true, logStates=false, logEvents=true, |
| 39 | + requiredFinalStates_atol=1e-6, requiredFinalStates=requiredFinalStates) |
| 40 | + |
| 41 | +@usingModiaPlot |
| 42 | +plot(bouncingSphere, ["result.penetration", "result.penetrationVelocity", "result.tangentialVelocity", "result.angularVelocity", "result.normalForce", "result.tangentialForce", "result.torque"], figure=1) |
| 43 | +plot(bouncingSphere, ["result.positionVector", "result.normalVector", "result.forceVector", "result.torqueVector"], figure=2) |
| 44 | + |
| 45 | +end |
0 commit comments