Skip to content

Commit 7dede74

Browse files
committed
new models for segmented simulation and force elements
1 parent e8fe97c commit 7dede74

File tree

9 files changed

+2620
-0
lines changed

9 files changed

+2620
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module BouncingSphere3DfreeMotion
2+
3+
using Modia3D
4+
using Modia3D.StaticArrays
5+
6+
BouncingSphere = Model3D(
7+
boxHeigth = 0.1,
8+
world = Object3D(feature=Scene(enableContactDetection=false)),
9+
ground = Object3D(parent=:world,
10+
translation=:[0.0,-boxHeigth/2,0.0],
11+
feature=Solid(shape=Box(lengthX=4.0, lengthY=:boxHeigth, lengthZ=0.7),
12+
visualMaterial=VisualMaterial(color="DarkGreen"),
13+
solidMaterial="Steel",
14+
collision=true)),
15+
sphere = Object3D(feature=Solid(shape=Sphere(diameter=0.2),
16+
visualMaterial=VisualMaterial(color="Blue"),
17+
solidMaterial="Steel",
18+
massProperties=MassPropertiesFromShapeAndMass(mass=0.001),
19+
collision=true)),
20+
free = FreeMotion2(obj1=:world, obj2=:sphere, r=Var(init=SVector{3,Float64}(0.0, 1.0, 0.0)))
21+
)
22+
23+
bouncingSphere = @instantiateModel(BouncingSphere, unitless=true, logCode=true)
24+
25+
simulate!(bouncingSphere, stopTime=0.2, dtmax=0.1, log=true, logStates=true)
26+
showInfo(bouncingSphere)
27+
28+
@usingModiaPlot
29+
plot(bouncingSphere, "free.r", figure=1)
30+
31+
simulate!(bouncingSphere, IDA(), nlinearMinForDAE=1, stopTime=2.2, dtmax=0.1, log=true, logStates=true) #, requiredFinalStates=requiredFinalStates)
32+
showInfo(bouncingSphere)
33+
34+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module BoxWorldForceSimulation
2+
3+
using Modia3D
4+
5+
function forceVec(; time::Float64, axis::Int64, maxForce::Float64)::Modia.SVector{3,Float64}
6+
if time < 1.0
7+
frc = 0.0
8+
elseif time < 2.0
9+
frc = maxForce*(time - 1.0)
10+
elseif time < 3.0
11+
frc = maxForce
12+
elseif time < 4.0
13+
frc = maxForce*(4.0 - time)
14+
else
15+
frc = 0.0
16+
end
17+
if axis == 1
18+
return Modia.SVector{3,Float64}(frc, 0.0, 0.0)
19+
elseif axis == 2
20+
return Modia.SVector{3,Float64}(0.0, frc, 0.0)
21+
else
22+
return Modia.SVector{3,Float64}(0.0, 0.0, frc)
23+
end
24+
end
25+
forceVector(; time, objectApply, objectCoord) = forceVec(; time=time, axis=1, maxForce=1.0)
26+
27+
BoxWorldForce = Model3D(
28+
Length = 0.1,
29+
Mass = 1.0,
30+
IMoment = 0.1,
31+
visualMaterial = VisualMaterial(color="IndianRed1", transparency=0.5),
32+
world = Object3D(feature=Scene(gravityField=NoGravityField(),
33+
nominalLength=:(2*Length))),
34+
worldFrame = Object3D(parent=:world,
35+
feature=Visual(shape=CoordinateSystem(length=:Length))),
36+
dirFrame = Object3D(parent=:world,
37+
rotation=[0.0, 0.0, 30.0/180*pi],
38+
feature=Visual(shape=CoordinateSystem(length=:(0.75*Length)))),
39+
box = Object3D(parent=:world, fixedToParent=false,
40+
feature=Solid(shape=Box(lengthX=:Length, lengthY=:Length, lengthZ=:Length),
41+
massProperties=MassProperties(; mass=:Mass, Ixx=:IMoment, Iyy=:IMoment, Izz=:IMoment),
42+
visualMaterial=:(visualMaterial))),
43+
force = WorldForce(;objectApply=:box,
44+
forceFunction=forceVector,
45+
objectCoord=:dirFrame)
46+
)
47+
48+
boxWorldForce = @instantiateModel(BoxWorldForce, unitless=true, logCode=false)
49+
50+
stopTime = 5.0
51+
dtmax = 0.1
52+
requiredFinalStates = [4.330091998452314, 2.4999797809222875, 0.0, 1.7320345346635413, 0.9999906048337232, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
53+
simulate!(boxWorldForce, stopTime=stopTime, dtmax=dtmax, log=true, requiredFinalStates=requiredFinalStates)
54+
55+
@usingModiaPlot
56+
plot(boxWorldForce, ["box.translation", "box.velocity", "force.forceVector"], figure=1)
57+
58+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module BoxWorldTorqueSimulation
2+
3+
using Modia3D
4+
5+
function torqueVec(; time::Float64, axis::Int64, maxTorque::Float64)::Modia.SVector{3,Float64}
6+
if time < 1.0
7+
trq = 0.0
8+
elseif time < 2.0
9+
trq = maxTorque*(time - 1.0)
10+
elseif time < 3.0
11+
trq = maxTorque
12+
elseif time < 4.0
13+
trq = maxTorque*(4.0 - time)
14+
else
15+
trq = 0.0
16+
end
17+
if axis == 1
18+
return Modia.SVector{3,Float64}(trq, 0.0, 0.0)
19+
elseif axis == 2
20+
return Modia.SVector{3,Float64}(0.0, trq, 0.0)
21+
else
22+
return Modia.SVector{3,Float64}(0.0, 0.0, trq)
23+
end
24+
end
25+
torqueVector(; time, objectApply, objectCoord) = torqueVec(; time=time, axis=2, maxTorque=1.0)
26+
27+
BoxWorldTorque = Model3D(
28+
Length = 0.1,
29+
Mass = 1.0,
30+
IMoment = 0.1,
31+
visualMaterial = VisualMaterial(color="IndianRed1", transparency=0.5),
32+
world = Object3D(feature=Scene(gravityField=NoGravityField(),
33+
nominalLength=:(2*Length))),
34+
worldFrame = Object3D(parent=:world,
35+
feature=Visual(shape=CoordinateSystem(length=:Length))),
36+
dirFrame = Object3D(parent=:world,
37+
rotation=[0.0, 0.0, 60.0/180*pi],
38+
feature=Visual(shape=CoordinateSystem(length=:(0.75*Length)))),
39+
box = Object3D(parent=:world, fixedToParent=false,
40+
feature=Solid(shape=Box(lengthX=:Length, lengthY=:Length, lengthZ=:Length),
41+
massProperties=MassProperties(; mass=:Mass, Ixx=:IMoment, Iyy=:IMoment, Izz=:IMoment),
42+
visualMaterial=:(visualMaterial))),
43+
torque = WorldTorque(objectApply=:box,
44+
torqueFunction=torqueVector,
45+
objectCoord=:dirFrame)
46+
)
47+
48+
boxWorldTorque = @instantiateModel(BoxWorldTorque, unitless=true, logCode=false)
49+
50+
stopTime = 5.0
51+
dtmax = 0.1
52+
requiredFinalStates = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -50.03469666280062, -0.13132172058876085, 0.015242310907410017, -17.320661301093185, 10.0, 0.0]
53+
simulate!(boxWorldTorque, stopTime=stopTime, dtmax=dtmax, log=true, requiredFinalStates=requiredFinalStates)
54+
55+
@usingModiaPlot
56+
plot(boxWorldTorque, ["box.rotation", "box.angularVelocity", "torque.torqueVector"], figure=1)
57+
58+
end

0 commit comments

Comments
 (0)