multiMbsTest.py
You can view and download this file on Github: multiMbsTest.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: test with several mbs
5#
6# Author: Johannes Gerstmayr
7# Date: 2021-03-22
8#
9# 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.
10#
11#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
13import exudyn as exu
14from exudyn.itemInterface import *
15from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
16import exudyn.graphics as graphics #only import if it does not conflict
17
18import numpy as np
19
20
21def CreateSystem(mbs, pOff, color0):
22 #%%++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #physical parameters
24 p0=np.array(pOff)
25 g = [0,-9.81,0] #gravity
26 bodyDim=[1,0.1,0.1] #body dimensions
27 pMid0 = np.array([bodyDim[0]*0.5,0,0]) + p0 #center of mass, body0
28
29 #first link:
30 #inertia with helper function
31 iCube0 = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1])
32 #print(iCube)
33
34 #graphics for body
35 graphicsBody0 = graphics.RigidLink(p0=[-0.5*bodyDim[0],0,0],p1=[0.5*bodyDim[0],0,0],
36 axis0=[0,0,1], axis1=[0,0,0*1], radius=[0.05,0.05],
37 thickness = 0.1, width = [0.12,0.12], color=color0)
38
39 b0 = mbs.CreateRigidBody(referencePosition = pMid0,
40 inertia = iCube0,
41 gravity = g,
42 graphicsDataList = [graphicsBody0])
43
44 #ground body and marker
45 oGround = mbs.CreateGround()
46 mbs.CreateRevoluteJoint(bodyNumbers=[oGround, b0],
47 position=p0, axis=[0,0,1],
48 axisRadius=0.01, axisLength=0.1)
49 mbs.Assemble()
50
51def Simulate(SC, mbs):
52 #%%++++++++++++++++++++++++++++++++++++++++++++++++++++++
53 #assemble system and solve
54
55 simulationSettings = exu.SimulationSettings() #takes currently set values or default values
56
57 tEnd = 2 #simulation time
58 h = 1e-3 #step size
59 simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
60 simulationSettings.timeIntegration.endTime = tEnd
61 simulationSettings.timeIntegration.verboseMode = 1
62 simulationSettings.timeIntegration.simulateInRealtime = True
63
64 SC.visualizationSettings.general.autoFitScene = False
65 SC.visualizationSettings.window.renderWindowSize=[1600,1200]
66 SC.visualizationSettings.openGL.multiSampling = 4
67
68 # exu.StartRenderer()
69 # if 'renderState' in exu.sys: #reload old view
70 # SC.SetRenderState(exu.sys['renderState'])
71
72 mbs.WaitForUserToContinue() #stop before simulating
73
74 mbs.SolveDynamic(simulationSettings = simulationSettings,
75 solverType=exu.DynamicSolverType.TrapezoidalIndex2)
76
77 # SC.WaitForRenderEngineStopFlag() #stop before closing
78 # exu.StopRenderer() #safely close rendering window!
79
80
81
82SC2 = exu.SystemContainer()
83SC = exu.SystemContainer()
84mbs = SC.AddSystem()
85mbs2 = SC2.AddSystem()
86
87CreateSystem(mbs, [0,0,0], graphics.color.red)
88CreateSystem(mbs, [1.2,0,0], graphics.color.blue)
89CreateSystem(mbs2, [0,0,0], graphics.color.red)
90CreateSystem(mbs2, [0.6,-1.2,0], graphics.color.green)
91
92SC.AttachToRenderEngine()
93exu.StartRenderer()
94if 'renderState' in exu.sys: #reload old view
95 SC.SetRenderState(exu.sys['renderState'])
96
97Simulate(SC, mbs)
98# mbs.WaitForUserToContinue()
99#SC.DetachFromRenderEngine()
100SC.WaitForRenderEngineStopFlag() #stop before closing
101exu.StopRenderer() #safely close rendering window!
102
103SC2.AttachToRenderEngine()
104exu.StartRenderer()
105if 'renderState' in exu.sys: #reload old view
106 SC2.SetRenderState(exu.sys['renderState'])
107Simulate(SC2, mbs2)
108
109SC2.WaitForRenderEngineStopFlag() #stop before closing
110exu.StopRenderer() #safely close rendering window!
111
112if False:
113
114 mbs.PlotSensor([sens1],[1])