|
| 1 | +module RattlebackSimulation |
| 2 | + |
| 3 | +using Modia3D |
| 4 | + |
| 5 | +mass = 0.014660765716752368 |
| 6 | +centerOfMass = [0.0, 0.0, 0.0] |
| 7 | +inertiaTensor = [5.864306286700948e-7 0.0 0.0; 0.0 7.623598172711232e-6 0.0; 0.0 0.0 7.623598172711232e-6] |
| 8 | +gam = -5 # inertia tensor orientation angle [deg] about vertical axis; sign defines preferred rotation direction |
| 9 | +rotMatrix = [cosd(gam) -sind(gam) 0.0; sind(gam) cosd(gam) 0.0; 0.0 0.0 1.0] |
| 10 | +inertiaTensor = rotMatrix * inertiaTensor * rotMatrix' |
| 11 | +massProps = MassProperties(; mass=mass, centerOfMass=centerOfMass, |
| 12 | + Ixx=inertiaTensor[1,1], Iyy=inertiaTensor[2,2], Izz=inertiaTensor[3,3], |
| 13 | + Ixy=inertiaTensor[1,2], Iyz=inertiaTensor[2,3], Ixz=inertiaTensor[3,1]) |
| 14 | + |
| 15 | +Rattleback = Model( |
| 16 | + world = Object3D(feature=Scene(gravityField=UniformGravityField(g=9.81, n=[0, 0, -1]), |
| 17 | + nominalLength=0.1, |
| 18 | + enableContactDetection=true)), |
| 19 | + worldFrame = Object3D(parent=:world, feature=Visual(shape=CoordinateSystem(length=0.05))), |
| 20 | + ground = Object3D(parent=:world, |
| 21 | + translation=:[0.0, 0.0, -0.005], |
| 22 | + feature=Solid(shape=Box(lengthX=0.2, lengthY=0.2, lengthZ=0.01), |
| 23 | + visualMaterial=VisualMaterial(color="Grey90", transparency=0.5), |
| 24 | + solidMaterial="DryWood", |
| 25 | + collision=true)), |
| 26 | + ellipsoid = Object3D(feature=Solid(massProperties=massProps, |
| 27 | + shape=Ellipsoid(lengthX=0.1, lengthY=0.02, lengthZ=0.02), |
| 28 | + visualMaterial=VisualMaterial(color="Blue"), |
| 29 | + solidMaterial="DryWood", |
| 30 | + collision=true)), |
| 31 | + joint = FreeMotion(obj1=:world, obj2=:ellipsoid, r=Var(init=[0.0, 0.0, 0.01]), w=Var(init=[0.0, 0.1, 5.0])) |
| 32 | +) |
| 33 | + |
| 34 | +rattleback = @instantiateModel(buildModia3D(Rattleback), unitless=true) |
| 35 | + |
| 36 | +stopTime = 6.0 |
| 37 | +tolerance = 1e-8 |
| 38 | +requiredFinalStates = [0.0006643219607533129, -0.0003421523453737833, 0.00999995717824536, 0.0004810494172644089, 0.00013865075493256469, -3.842333721570369e-8, 0.08135690941922864, -0.26163303787420544, -1.2651039117459748, -0.05518153954821725, -0.6191105987556029, -2.2091732972104654] |
| 39 | +simulate!(rattleback, stopTime=stopTime, tolerance=tolerance, log=false, requiredFinalStates=requiredFinalStates) |
| 40 | + |
| 41 | +@usingModiaPlot |
| 42 | +plot(rattleback, ["joint.r" "joint.rot"; "joint.v" "joint.w"], figure=1) |
| 43 | + |
| 44 | +end |
0 commit comments