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
 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(itemNumbers=[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.realtime.active = True
 63    
 64    SC.visualizationSettings.general.autoFitScene = False
 65    SC.visualizationSettings.view0.window.renderWindowSize=[1600,1200]
 66    SC.visualizationSettings.openGL.multiSampling = 4
 67    
 68    # SC.renderer.Start()
 69    # SC.renderer.RestoreSavedState() #reload old view
 70    
 71    SC.renderer.DoIdleTasks() #stop before simulating
 72    
 73    mbs.SolveDynamic(simulationSettings = simulationSettings,
 74                     solverType=exu.DynamicSolverType.TrapezoidalIndex2)
 75    
 76    # SC.renderer.DoIdleTasks() #stop before closing
 77    # SC.renderer.Stop() #safely close rendering window!
 78    
 79
 80
 81SC2 = exu.SystemContainer()
 82SC = exu.SystemContainer()
 83mbs = SC.AddSystem()
 84mbs2 = SC2.AddSystem()
 85
 86CreateSystem(mbs, [0,0,0], graphics.color.red)
 87CreateSystem(mbs, [1.2,0,0], graphics.color.blue)
 88CreateSystem(mbs2, [0,0,0], graphics.color.red)
 89CreateSystem(mbs2, [0.6,-1.2,0], graphics.color.green)
 90
 91SC.renderer.Attach()
 92SC.renderer.Start()
 93SC.renderer.RestoreSavedState() #reload old view
 94    
 95Simulate(SC, mbs)
 96# SC.renderer.DoIdleTasks()
 97#SC.renderer.Detach()
 98SC.renderer.DoIdleTasks() #stop before closing
 99SC.renderer.Stop() #safely close rendering window!
100
101SC2.renderer.Attach()
102SC.renderer.Start()
103SC2.renderer.RestoreSavedState() #reload old view
104Simulate(SC2, mbs2)
105
106SC2.renderer.DoIdleTasks() #stop before closing
107SC.renderer.Stop() #safely close rendering window!
108
109if False:
110    
111    mbs.PlotSensor([sens1],[1])