createRollingDiscTest.py

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

 1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2# This is an EXUDYN example
 3#
 4# Details:  Test model for CreateRollingDisc; simple model of a wheel
 5#
 6# Author:   Johannes Gerstmayr
 7# Date:     2025-03-05
 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.utilities import * #includes itemInterface and rigidBodyUtilities
15import exudyn.graphics as graphics #only import if it does not conflict
16
17import numpy as np
18
19useGraphics = True #without test
20#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21#you can erase the following lines and all exudynTestGlobals related operations if this is not intended to be used as TestModel:
22try: #only if called from test suite
23    from modelUnitTests import exudynTestGlobals #for globally storing test results
24    useGraphics = exudynTestGlobals.useGraphics
25except:
26    class ExudynTestGlobals:
27        pass
28    exudynTestGlobals = ExudynTestGlobals()
29#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
31SC = exu.SystemContainer()
32mbs = SC.AddSystem()
33
34r = 0.2
35oDisc = mbs.CreateRigidBody(inertia = InertiaCylinder(density=5000, length=0.02, outerRadius=r, axis=0),
36                          referencePosition = [1,0,r],
37                          initialAngularVelocity = [-3*2*pi,10,0],
38                          initialVelocity = [0,r*3*2*pi,0],
39                          gravity = [0,0,-9.81],
40                          graphicsDataList = [exu.graphics.Cylinder(pAxis = [-0.01,0,0], vAxis = [0.02,0,0], radius = r*0.99, nTiles=64,
41                                                                    color=exu.graphics.color.blue),
42                                              exu.graphics.Basis(length=2*r)])
43oGround = mbs.CreateGround(graphicsDataList=[exu.graphics.CheckerBoard(size=8)])
44
45mbs.CreateRollingDisc(bodyNumbers=[oGround, oDisc],
46                      axisPosition=[0,0,0], axisVector=[1,0,0], #on local wheel frame
47                      planePosition = [0,0,0], planeNormal = [0,0,1],  #in ground frame
48                      discRadius = r,
49                      discWidth=0.01, color=exu.graphics.color.steelblue)
50
51mbs.Assemble()
52
53simulationSettings = exu.SimulationSettings() #takes currently set values or default values
54
55
56stepSize=0.002
57tEnd = 1
58
59simulationSettings.timeIntegration.numberOfSteps = int(tEnd/stepSize)
60simulationSettings.timeIntegration.endTime = tEnd
61simulationSettings.solutionSettings.writeSolutionToFile = useGraphics
62simulationSettings.timeIntegration.verboseMode = 1
63simulationSettings.timeIntegration.newton.useModifiedNewton = True
64
65SC.visualizationSettings.nodes.show = True
66SC.visualizationSettings.nodes.drawNodesAsPoint  = False
67SC.visualizationSettings.nodes.showBasis = True
68SC.visualizationSettings.nodes.basisSize = 0.015
69SC.visualizationSettings.openGL.perspective = 2
70SC.visualizationSettings.openGL.shadow=0.3
71SC.visualizationSettings.openGL.multiSampling=4
72
73if useGraphics:
74    SC.renderer.Start()
75    SC.renderer.DoIdleTasks()
76
77mbs.SolveDynamic(simulationSettings)
78
79p0=mbs.GetObjectOutputBody(oDisc, exu.OutputVariableType.Position)
80
81u = np.linalg.norm(p0)
82exu.Print('solution of createRollingDisc=',u)
83
84exudynTestGlobals.testError = u - (0)
85exudynTestGlobals.testResult = u
86
87
88if useGraphics:
89    SC.renderer.DoIdleTasks()
90    SC.renderer.Stop() #safely close rendering window!
91
92# mbs.SolutionViewer()