rigidBodyTutorial.py
You can view and download this file on Github: rigidBodyTutorial.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: 3D rigid body example with joints
5#
6# Author: Johannes Gerstmayr
7# Date: 2020-03-14
8# Modified: 2023-04-18
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 * #includes itemInterface, graphicsDataUtilities and rigidBodyUtilities
16import numpy as np
17
18SC = exu.SystemContainer()
19mbs = SC.AddSystem()
20
21
22g = [0,-9.81,0] #gravity
23bodyDim = [1,0.1,0.1] #body dimensions
24p0 = [0,0,0] #origin of pendulum
25pMid0 = [bodyDim[0]*0.5,0,0] #center of mass, body0
26
27#inertia for cubic body with dimensions in sideLengths
28iCube = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1])
29print(iCube)
30
31#graphics for body
32graphicsBody = GraphicsDataRigidLink(p0=[-0.5*bodyDim[0],0,0],p1=[0.5*bodyDim[0],0,0],
33 axis1=[0,0,1], radius=[0.01,0.01],
34 thickness = 0.01, width = [0.02,0.02], color=color4lightred)
35
36[n0,b0]=AddRigidBody(mainSys = mbs,
37 inertia = iCube,
38 nodeType = str(exu.NodeType.RotationEulerParameters),
39 position = pMid0,
40 rotationMatrix = np.diag([1,1,1]),
41 angularVelocity = [0,0,0],
42 gravity = g, #will automatically add a load on body
43 graphicsDataList = [graphicsBody])
44
45#ground body and marker
46oGround = mbs.AddObject(ObjectGround())
47markerGround = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=[0,0,0]))
48
49#markers are needed to link joints and bodies; also needed for loads
50#markers for rigid body:
51markerBody0J0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b0, localPosition=[-0.5*bodyDim[0],0,0]))
52
53#revolute joint (free z-axis)
54mbs.AddObject(GenericJoint(markerNumbers=[markerGround, markerBody0J0],
55 constrainedAxes=[1,1,1,1,1,0],
56 visualization=VObjectJointGeneric(axesRadius=0.01, axesLength=0.1)))
57
58mbs.Assemble()
59#mbs.systemData.Info()
60
61simulationSettings = exu.SimulationSettings() #takes currently set values or default values
62
63tEnd = 4
64stepSize = 1e-4 #could be larger, but then we do not see the simulation ...
65
66simulationSettings.timeIntegration.numberOfSteps = int(tEnd/stepSize)
67simulationSettings.timeIntegration.endTime = tEnd
68simulationSettings.timeIntegration.verboseMode = 1 #to see some output
69
70#start graphics
71exu.StartRenderer()
72mbs.WaitForUserToContinue() #wait until user presses space
73
74#start generalized alpha solver
75mbs.SolveDynamic(simulationSettings = simulationSettings)
76
77SC.WaitForRenderEngineStopFlag()
78exu.StopRenderer() #safely close rendering window!