Skip to content

Commit b566572

Browse files
authored
test analytical fourbar with UniversalSpherical (#111)
* test analytical fourbar with UniversalSpherical * rm using Plots
1 parent c94b264 commit b566572

File tree

6 files changed

+496
-364
lines changed

6 files changed

+496
-364
lines changed

docs/src/examples/kinematic_loops.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,43 @@ Multibody.render(fourbar2, sol; x=-2, y = 2, z = 3, filename = "fourbar2.gif") #
143143
nothing # hide
144144
```
145145

146-
![animation](fourbar2.gif)
146+
![animation](fourbar2.gif)
147+
148+
## Using a joint assembly
149+
This example models a mechanism similar to the previous one, but replaces several joints and bodies with the aggregate [`UniversalSpherical`](@ref) joint. This joint is a combination of a universal joint and a spherical joint, with a bar in-between. A benefit of using this joint assembly in a kinematic loop is that some nonlinear equations are solved analytically, and the solver will thus see fewer nonlinear equations. This can lead to a faster simulation.
150+
151+
```@example kinloop
152+
systems = @named begin
153+
j1 = Revolute(n = [1, 0, 0], w0 = 5.235987755983, state_priority=12.0, radius=0.1f0) # Increase state priority to ensure that this joint coordinate is chosen as state variable
154+
j2 = Prismatic(n = [1, 0, 0], s0 = -0.2)
155+
b1 = BodyShape(r = [0, 0.5, 0.1], radius=0.03)
156+
b2 = BodyShape(r = [0, 0.2, 0], radius=0.03)
157+
b3 = FixedTranslation(r = [1.2, 0, 0], radius=0)
158+
joint_us = UniversalSpherical(n1_a = [0, 1, 0], rRod_ia = [-1, 0.3, 0.1])
159+
end
160+
161+
connections = [connect(j2.frame_b, b2.frame_a)
162+
connect(j1.frame_b, b1.frame_a)
163+
connect(j1.frame_a, world.frame_b)
164+
connect(b1.frame_b, joint_us.frame_b)
165+
connect(joint_us.frame_a, b2.frame_b)
166+
connect(b3.frame_a, world.frame_b)
167+
connect(b3.frame_b, j2.frame_a)
168+
]
169+
170+
@named fourbar_analytic = ODESystem(connections, t, systems = [world; systems])
171+
fourbar_analytic = complete(fourbar_analytic)
172+
ssys = structural_simplify(IRSystem(fourbar_analytic))
173+
prob = ODEProblem(ssys, [], (0.0, 1.4399))
174+
sol2 = solve(prob, FBDF(autodiff=true)) # about 4x faster than the simulation above
175+
plot!(sol2, idxs=[j2.s]) # Plot the same coordinate as above
176+
```
177+
In practice, the two simulations are not exactly identical since we haven't modeled any mass attached to the rod in the joint assembly. We could add such mass to the rod by attaching to the `joint_us.frame_ia` connector.
178+
179+
```@example kinloop
180+
import GLMakie
181+
Multibody.render(fourbar_analytic, sol2; x=-2, y = 2, z = 3, filename = "fourbar_analytic.gif")
182+
nothing # hide
183+
```
184+
185+
![animation](fourbar_analytic.gif)

src/Multibody.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ include("interfaces.jl")
154154
export World, world, Mounting1D, Fixed, FixedTranslation, FixedRotation, Body, BodyShape, BodyCylinder, BodyBox, Rope
155155
include("components.jl")
156156

157-
export Revolute, Prismatic, Planar, Spherical, Universal, SphericalSpherical, UniversalSpherical,
157+
export Revolute, Prismatic, Planar, Spherical, Universal,
158158
GearConstraint, RollingWheelJoint, RollingWheel, FreeMotion, RevolutePlanarLoopConstraint
159159
include("joints.jl")
160160

161+
export SphericalSpherical, UniversalSpherical, JointUSR, JointRRR
162+
include("fancy_joints.jl")
163+
161164
export Spring, Damper, SpringDamperParallel, Torque, Force, WorldForce, WorldTorque
162165
include("forces.jl")
163166

0 commit comments

Comments
 (0)