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
16
17import numpy as np
18
19testIsActive = exu.sys.get('testIsActive', False)
20
21SC = exu.SystemContainer()
22mbs = SC.AddSystem()
23
24r = 0.2
25oDisc = mbs.CreateRigidBody(inertia = InertiaCylinder(density=5000, length=0.02, outerRadius=r, axis=0),
26                          referencePosition = [1,0,r],
27                          initialAngularVelocity = [-3*2*pi,10,0],
28                          initialVelocity = [0,r*3*2*pi,0],
29                          gravity = [0,0,-9.81],
30                          graphicsDataList = [exu.graphics.Cylinder(pAxis = [-0.01,0,0], vAxis = [0.02,0,0], radius = r*0.99, nTiles=32,
31                                                                    color=exu.graphics.color.blue),
32                                              exu.graphics.Basis(length=2*r)])
33oGround = mbs.CreateGround(graphicsDataList=[exu.graphics.CheckerBoard(size=8)])
34
35mbs.CreateRollingDisc(bodyNumbers=[oGround, oDisc], 
36                      axisPosition=[0,0,0], axisVector=[1,0,0], #on local wheel frame
37                      planePosition = [0,0,0], planeNormal = [0,0,1],  #in ground frame
38                      discRadius = r, 
39                      discWidth=0.01, color=exu.graphics.color.steelblue)
40
41mbs.Assemble()
42
43simulationSettings = exu.SimulationSettings() #takes currently set values or default values
44
45
46stepSize=0.002
47tEnd = 1
48
49simulationSettings.timeIntegration.numberOfSteps = int(tEnd/stepSize)
50simulationSettings.timeIntegration.endTime = tEnd
51simulationSettings.solution.file.write = (not testIsActive)
52simulationSettings.timeIntegration.verboseMode = 1
53simulationSettings.timeIntegration.newton.useModifiedNewton = True
54
55SC.visualizationSettings.nodes.show = True
56SC.visualizationSettings.nodes.drawNodesAsPoint  = False
57SC.visualizationSettings.nodes.showBasis = True
58SC.visualizationSettings.nodes.basisSize = 0.015
59SC.visualizationSettings.view0.camera.perspective = 1
60SC.visualizationSettings.openGL.light0.shadow=0.3
61SC.visualizationSettings.openGL.multiSampling=4
62
63if not testIsActive:
64    SC.renderer.Start()
65    SC.renderer.DoIdleTasks()
66
67mbs.SolveDynamic(simulationSettings)
68
69p0=mbs.GetObjectOutputBody(oDisc, exu.OutputVariableType.Position)
70
71u = np.linalg.norm(p0)
72exu.Print('solution of createRollingDisc=',u) 
73
74exu.sys['testResult'] = u
75
76
77if not testIsActive:
78    SC.renderer.DoIdleTasks()
79    SC.renderer.Stop() #safely close rendering window!
80
81# mbs.SolutionViewer()