doublePendulum2D.py
You can view and download this file on Github: doublePendulum2D.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Simple double pendulum
5#
6# Author: Johannes Gerstmayr (with "help" of Bing AI)
7# Date: 2023-05-01
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
13
14import exudyn as exu
15from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
16import exudyn.graphics as graphics #only import if it does not conflict
17from math import sin, cos, pi
18
19SC = exu.SystemContainer()
20mbs = SC.AddSystem()
21
22# create nodes:
23n0=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[0,0,0], initialVelocities=[0,0,0]))
24n1=mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[1,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]])])))
31
32# add markers and loads:
33oGround = mbs.AddObject(ObjectGround())
34mGround=mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=[-0.5, 0., 0.]))
35m00 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b0, localPosition=[-0.5, 0., 0.]))
36m01 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b0, localPosition=[ 0.5, 0., 0.]))
37m10 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b1, localPosition=[-0.5, 0., 0.]))
38#m12 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b1, localPosition=[ 0.5, 0., 0.]))
39
40# add joints:
41jg0 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[mGround,m00]))
42j01 = mbs.AddObject(RevoluteJoint2D(markerNumbers=[m01,m10]))
43
44# add loads:
45
46mLoad0=mbs.AddMarker(MarkerNodePosition(nodeNumber=n0))
47mLoad1=mbs.AddMarker(MarkerNodePosition(nodeNumber=n1))
48
49mbs.AddLoad(Force(markerNumber=mLoad0, loadVector=[0,-9.81,0]))
50mbs.AddLoad(Force(markerNumber=mLoad1, loadVector=[0,-9.81,0]))
51
52
53# add time integration scheme:
54mbs.Assemble()
55simulationSettings = exu.SimulationSettings()
56simulationSettings.timeIntegration.numberOfSteps = 10000
57simulationSettings.timeIntegration.endTime = 10
58
59#remove this if you want to simulate fast:
60simulationSettings.timeIntegration.simulateInRealtime = True #otherwise, nothing is visible
61
62simulationSettings.solutionSettings.writeSolutionToFile = True
63simulationSettings.solutionSettings.solutionWritePeriod = 0.01
64
65simulationSettings.timeIntegration.verboseMode = 1
66# simulationSettings.displayStatistics = True
67# simulationSettings.displayComputationTime = True
68
69#simulate:
70exu.StartRenderer()
71mbs.WaitForUserToContinue()
72mbs.SolveDynamic(simulationSettings)
73exu.StopRenderer()