|
1 |
| -# Pendulum---The "Hello World of multi-body dynamics" |
| 1 | +# Pendulum--The "Hello World of multi-body dynamics" |
2 | 2 | This beginners tutorial will model a pendulum pivoted around the origin in the world frame. The world frame is a constant that lives inside the Multibody module, all multibody models are "grounded" in the same world. To start, we load the required packages
|
3 | 3 | ```@example pendulum
|
4 | 4 | using ModelingToolkit
|
@@ -72,12 +72,38 @@ connections = [connect(world.frame_b, joint.frame_a)
|
72 | 72 | @named model = ODESystem(connections, t, systems = [world, joint, body, damper])
|
73 | 73 | ssys = structural_simplify(model, allow_parameter = false)
|
74 | 74 |
|
75 |
| -
|
76 | 75 | prob = ODEProblem(ssys, [damper.phi_rel => 1, D(joint.phi) => 0, D(D(joint.phi)) => 0],
|
77 | 76 | (0, 30))
|
78 | 77 |
|
| 78 | +sol = solve(prob, Rodas4()) |
| 79 | +plot(sol, idxs = joint.phi) |
| 80 | +``` |
| 81 | +This time we see that the pendulum loses energy and eventually comes to rest at the stable equilibrium point ``\pi / 2``. |
| 82 | + |
| 83 | +## A linear pendulum? |
| 84 | +When we think of a pendulum, we typically think of a rotary pendulum that is rotating around a pivot point like in the examples above. |
| 85 | +A mass suspended in a spring can be though of as a linear pendulum (often referred to as a harmonic oscillator rather than a pendulum), and we show here how we can construct a model of such a device. |
| 86 | + |
| 87 | +```@example pendulum |
| 88 | +import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as T |
| 89 | +
|
| 90 | +@named damper = T.Damper(0.5) |
| 91 | +@named spring = T.Spring(1) |
| 92 | +@named joint = Prismatic(n = [0, 1, 0], isroot = true, useAxisFlange = true) |
| 93 | +
|
| 94 | +connections = [connect(world.frame_b, joint.frame_a) |
| 95 | + connect(damper.flange_b, spring.flange_b, joint.axis) |
| 96 | + connect(joint.support, damper.flange_a, spring.flange_a) |
| 97 | + connect(body.frame_a, joint.frame_b)] |
| 98 | +
|
| 99 | +@named model = ODESystem(connections, t, systems = [world, joint, body, damper, spring]) |
| 100 | +ssys = structural_simplify(model, allow_parameter = false) |
| 101 | +
|
| 102 | +prob = ODEProblem(ssys, [damper.s_rel => 1, D(joint.s) => 0, D(D(joint.s)) => 0], |
| 103 | + (0, 30)) |
79 | 104 |
|
80 | 105 | sol = solve(prob, Rodas4())
|
81 |
| -plot(sol, idxs = collect(joint.phi)) |
| 106 | +plot(sol, idxs = joint.s) |
82 | 107 | ```
|
83 |
| -This time we see that the pendulum loses energy and eventually comes to rest at the stable equilibrium point ``\pi / 2``. |
| 108 | + |
| 109 | +As is hopefully evident from the little code snippet above, this linear pendulum model has a lot in common with the rotary pendulum. In this example, we connected both the spring and a damper to the same axis flange in the joint. This time, the components came from the `TranslationalModelica` submodule of ModelingToolkitStandardLibrary rather than the `Rotational` submodule. Also here do we pass `useAxisFlange` when we create the joint to make sure that it is equipped with the flanges `support` and `axis` needed to connect the translational components. |
0 commit comments