simple4linkPendulumBing.py
You can view and download this file on Github: simple4linkPendulumBing.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: 4-link pendulum
5#
6# Author: Bing AI with some help by Johannes Gerstmayr; note that doublePendulum2D.py did not exist prior to this model
7# Date: 2023-04-15
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
17SC = exu.SystemContainer()
18mbs = SC.AddSystem()
19
20# create nodes:
21n0=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[0,0,0], initialVelocities=[0,0,0]))
22n1=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[1,0,0], initialVelocities=[0,0,0]))
23n2=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[2,0,0], initialVelocities=[0,0,0]))
24n3=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[3,0,0], initialVelocities=[0,0,0]))
25
26# create bodies:
27b0=mbs.AddObject(RigidBody2D(physicsMass=1, physicsInertia=1,nodeNumber=n0,
28 visualization=VRigidBody2D(graphicsData=[graphics.Lines([[-0.5,0,0],[0.5,0,0]])])))
29b1=mbs.AddObject(RigidBody2D(physicsMass=1, physicsInertia=1,nodeNumber=n1,
30 visualization=VRigidBody2D(graphicsData=[graphics.Lines([[-0.5,0,0],[0.5,0,0]])])))
31b2=mbs.AddObject(RigidBody2D(physicsMass=1, physicsInertia=1,nodeNumber=n2,
32 visualization=VRigidBody2D(graphicsData=[graphics.Lines([[-0.5,0,0],[0.5,0,0]])])))
33b3=mbs.AddObject(RigidBody2D(physicsMass=1, physicsInertia=1,nodeNumber=n3,
34 visualization=VRigidBody2D(graphicsData=[graphics.Lines([[-0.5,0,0],[0.5,0,0]])])))
35
36# add markers and loads:
37oGround = mbs.AddObject(ObjectGround())
38mGround=mbs.AddMarker(MarkerBodyPosition(bodyNumber=oGround, localPosition=[-0.5, 0., 0.]))
39m00 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b0, localPosition=[-0.5, 0., 0.]))
40m01 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b0, localPosition=[ 0.5, 0., 0.]))
41m10 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b1, localPosition=[-0.5, 0., 0.]))
42m12 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b1, localPosition=[ 0.5, 0., 0.]))
43m21 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b2, localPosition=[-0.5, 0., 0.]))
44m23 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b2, localPosition=[ 0.5, 0., 0.]))
45m32 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=b3, localPosition=[-0.5, 0., 0.]))
46
47# add joints:
48jg0 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[mGround,m00]))
49j01 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[m01,m10]))
50j12 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[m12,m21]))
51j23 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[m23,m32]))
52
53# add loads:
54
55mLoad0=mbs.AddMarker(MarkerNodePosition(nodeNumber=n0))
56mLoad1=mbs.AddMarker(MarkerNodePosition(nodeNumber=n1))
57mLoad2=mbs.AddMarker(MarkerNodePosition(nodeNumber=n2))
58mLoad3=mbs.AddMarker(MarkerNodePosition(nodeNumber=n3))
59
60mbs.AddLoad(Force(markerNumber=mLoad0, loadVector=[0,-9.81*1,0]))
61mbs.AddLoad(Force(markerNumber=mLoad1, loadVector=[0,-9.81*1,0]))
62mbs.AddLoad(Force(markerNumber=mLoad2, loadVector=[0,-9.81*1,0]))
63mbs.AddLoad(Force(markerNumber=mLoad3, loadVector=[0,-9.81*1,0]))
64
65# add time integration scheme:
66mbs.Assemble()
67simulationSettings = exu.SimulationSettings()
68simulationSettings.timeIntegration.numberOfSteps = 10000
69simulationSettings.timeIntegration.endTime = 10
70simulationSettings.solutionSettings.writeSolutionToFile = True
71simulationSettings.solutionSettings.solutionWritePeriod = 0.01
72
73exu.StartRenderer()
74mbs.WaitForUserToContinue()
75mbs.SolveDynamic(simulationSettings)
76exu.StopRenderer()