rigidBodyTutorial.py
You can view and download this file on Github: rigidBodyTutorial.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Single 3D rigid body example with generic joint
5#
6# Author: Johannes Gerstmayr
7# Date: 2020-03-14
8# Modified: 2024-06-04 (updated to CreateRigidBody)
9#
10# Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details.
11#
12#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
14import exudyn as exu
15from exudyn.utilities import ObjectGround, InertiaCuboid, AddRigidBody, MarkerBodyRigid, GenericJoint, \
16 VObjectJointGeneric, SensorBody
17#to be sure to have all items and functions imported, just do:
18#from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
19import exudyn.graphics as graphics #only import if it does not conflict
20import numpy as np
21
22SC = exu.SystemContainer()
23mbs = SC.AddSystem()
24
25
26g = [0,-9.81,0] #gravity
27bodyDim = [1,0.1,0.1] #body dimensions
28p0 = [0,0,0] #origin of pendulum
29pMid0 = [bodyDim[0]*0.5,0,0] #center of mass, body0
30
31#inertia for cubic body with dimensions in sideLengths
32iCube = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1])
33print(iCube)
34
35#graphics for body
36graphicsBody = graphics.RigidLink(p0=[-0.5*bodyDim[0],0,0],p1=[0.5*bodyDim[0],0,0],
37 axis1=[0,0,1], radius=[0.01,0.01],
38 thickness = 0.01, width = [0.02,0.02], color=graphics.color.lightred)
39
40#create rigid body with gravity load with one create function, which creates node, object, marker and load!
41b0=mbs.CreateRigidBody(inertia = iCube,
42 referencePosition = pMid0,
43 gravity = g,
44 graphicsDataList = [graphicsBody])
45
46#ground body and marker
47oGround = mbs.CreateGround()
48markerGround = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=[0,0,0]))
49
50#markers are needed to link joints and bodies; also needed for loads
51#markers for rigid body:
52markerBody0J0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b0, localPosition=[-0.5*bodyDim[0],0,0]))
53
54#revolute joint (free z-axis)
55mbs.AddObject(GenericJoint(markerNumbers=[markerGround, markerBody0J0],
56 constrainedAxes=[1,1,1,1,1,0],
57 visualization=VObjectJointGeneric(axesRadius=0.01, axesLength=0.1)))
58
59mbs.Assemble()
60#mbs.systemData.Info()
61
62simulationSettings = exu.SimulationSettings() #takes currently set values or default values
63
64tEnd = 4
65stepSize = 1e-4 #could be larger, but then we do not see the simulation ...
66
67simulationSettings.timeIntegration.numberOfSteps = int(tEnd/stepSize)
68simulationSettings.timeIntegration.endTime = tEnd
69simulationSettings.timeIntegration.verboseMode = 1 #to see some output
70
71#start graphics
72exu.StartRenderer()
73mbs.WaitForUserToContinue() #wait until user presses space
74
75#start generalized alpha solver
76mbs.SolveDynamic(simulationSettings = simulationSettings)
77
78SC.WaitForRenderEngineStopFlag()
79exu.StopRenderer() #safely close rendering window!