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