connectorRigidBodySpringDamperTest.py

You can view and download this file on Github: connectorRigidBodySpringDamperTest.py

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Test for RigidBodySpringDamper with springForceTorqueUserFunction;
  5#           the RigidBodySpringDamper can be used to model complicance effects in joints where
  6#           one axis undergoes large rotations, and the other rotations are small
  7#
  8# Author:   Johannes Gerstmayr
  9# Date:     2021-01-07
 10#
 11# 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.
 12#
 13#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 14
 15import sys
 16sys.path.append('../TestModels')            #for modelUnitTest as this example may be used also as a unit test
 17
 18import exudyn as exu
 19from exudyn.utilities import *
 20from exudyn.graphicsDataUtilities import *
 21import numpy as np
 22
 23useGraphics = True #without test
 24#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 25#you can erase the following lines and all exudynTestGlobals related operations if this is not intended to be used as TestModel:
 26try: #only if called from test suite
 27    from modelUnitTests import exudynTestGlobals #for globally storing test results
 28    useGraphics = exudynTestGlobals.useGraphics
 29except:
 30    class ExudynTestGlobals:
 31        pass
 32    exudynTestGlobals = ExudynTestGlobals()
 33#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 34
 35SC = exu.SystemContainer()
 36mbs = SC.AddSystem()
 37
 38oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0]))
 39nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0,0,0]))
 40
 41#example with rigid body at [0,0,0], 1kg under initial velocity
 42graphicsBody = GraphicsDataOrthoCubePoint(centerPoint=[0,0,0],size=[0.09,0.09,0.2], color=color4lightred)
 43nBody = mbs.AddNode(RigidRxyz(initialVelocities=[0,10,0, 2*pi*4,0,0]))
 44oBody = mbs.AddObject(RigidBody(physicsMass=1, physicsInertia=[1,1,1,0,0,0], nodeNumber=nBody,
 45                                visualization=VRigidBody(graphicsData=[graphicsBody])))
 46
 47mBody = mbs.AddMarker(MarkerNodeRigid(nodeNumber=nBody))
 48mGround = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround,
 49                                        localPosition = [0,0,0]))
 50
 51def UFforce(mbs, t, itemIndex, displacement, rotation, velocity, angularVelocity, stiffness, damping, rotJ0, rotJ1, offset):
 52    k = stiffness
 53    u = displacement
 54    v = velocity
 55    w = angularVelocity
 56    rot = rotation
 57    return [u[0]*k[0][0],u[1]*k[1][1]+v[1]*0.01*k[1][1],u[2]*k[2][2],
 58            rot[0]*k[0][0]+w[0]*0.001*k[0][0],rot[1]*k[0][0],rot[2]*k[0][0]]
 59
 60#markerNumbers and parameters taken from mini example
 61k=5000
 62mbs.AddObject(RigidBodySpringDamper(markerNumbers = [mGround, mBody],
 63                                    stiffness = np.diag([k,k,k, 0,0,0]),
 64                                    damping = np.diag([0,k*0.01,0, 0,0,0]),
 65                                    offset = [0,1,0, 0,0,0],
 66                                    springForceTorqueUserFunction = UFforce))
 67
 68mbs.Assemble()
 69
 70tEnd = 0.1
 71h=1e-3
 72if useGraphics:
 73    tEnd = 1 #parameters sucht that we can see some motion
 74    h=1e-5
 75
 76
 77simulationSettings = exu.SimulationSettings()
 78simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
 79simulationSettings.timeIntegration.endTime = tEnd
 80simulationSettings.solutionSettings.writeSolutionToFile = False
 81
 82simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1 #no numerical damping
 83
 84simulationSettings.displayStatistics = True
 85simulationSettings.timeIntegration.verboseMode = 1
 86
 87if useGraphics:
 88    exu.StartRenderer()              #start graphics visualization
 89    mbs.WaitForUserToContinue()    #wait for pressing SPACE bar to continue
 90
 91#start solver:
 92mbs.SolveDynamic(simulationSettings)
 93
 94if useGraphics:
 95    SC.WaitForRenderEngineStopFlag()#wait for pressing 'Q' to quit
 96    exu.StopRenderer()               #safely close rendering window!
 97
 98p0=mbs.GetObjectOutputBody(oBody, localPosition=[0.1,0.1,0.1],
 99                           variableType = exu.OutputVariableType.Position)
100result = p0[0]+p0[1]
101exu.Print('solution of connectorRigidBodySpringDamperTest=',result) #use x-coordinate
102
103exudynTestGlobals.testError = result - (0.18276224743714353) #2021-01-07:
104exudynTestGlobals.testResult = result