Skip to content

Commit 51a8052

Browse files
authored
clean up some tutorials (#94)
* clean up some tutorials * more cleanup
1 parent 8756b32 commit 51a8052

File tree

5 files changed

+13
-31
lines changed

5 files changed

+13
-31
lines changed

docs/src/examples/free_motion.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ eqs = [connect(world.frame_b, freeMotion.frame_a)
2424
body])
2525
ssys = structural_simplify(IRSystem(model))
2626
27-
prob = ODEProblem(ssys, [
28-
D.(freeMotion.r_rel_a) .=> randn();
29-
D.(D.(freeMotion.r_rel_a)) .=> randn();
30-
D.(freeMotion.phi) .=> randn();
31-
D.(D.(freeMotion.phi)) .=> randn();
32-
D.(body.w_a) .=> randn();
33-
collect(body.w_a .=> 0);
34-
collect(body.v_0 .=> 0);
35-
], (0, 10))
27+
prob = ODEProblem(ssys, [], (0, 10))
3628
3729
sol = solve(prob, Rodas4())
3830
plot(sol, idxs = body.r_0[2], title="Free falling body")

docs/src/examples/gyroscopic_effects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ D = Differential(t)
1919
world = Multibody.world
2020
2121
systems = @named begin
22-
spherical = Spherical(state=true, radius=0.02, color=[1,1,0,1])
22+
spherical = Spherical(state=true, radius=0.02, color=[1,1,0,1], quat=true)
2323
body1 = BodyCylinder(r = [0.25, 0, 0], diameter = 0.05)
2424
rot = FixedRotation(; n = [0,1,0], angle=deg2rad(45))
2525
revolute = Revolute(n = [1,0,0], radius=0.06, color=[1,0,0,1])
@@ -42,7 +42,7 @@ ssys = structural_simplify(IRSystem(model))
4242
4343
prob = ODEProblem(ssys, [model.world.g => 9.80665, model.revolute.w => 10], (0, 5))
4444
45-
sol = solve(prob, Rodas5P(), abstol=1e-6, reltol=1e-6)
45+
sol = solve(prob, Rodas5P(), abstol=1e-7, reltol=1e-7);
4646
@assert SciMLBase.successful_retcode(sol)
4747
using Test # hide
4848
@test sol(5, idxs=collect(model.body2.r_0[1:3])) ≈ [-0.0357364, -0.188245, 0.02076935] atol=1e-3 # hide

docs/src/examples/kinematic_loops.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ nothing # hide
9090
## Using cut joints
9191

9292
The mechanism below is another instance of a 4-bar linkage, this time with 6 revolute joints, 1 prismatic joint and 4 bodies. In order to simulate this mechanism, the user must
93-
1. Use the `iscut=true` keyword argument to one of the `Revolute` joints to indicate that the joint is a cut joint. A cut joint behaves similarly to a regular joint, but it introduces fewer constraints in order to avoid the otherwise over-constrained system resulting from closing the kinematic loop.
93+
1. Use the `iscut=true` keyword argument to one of the `Revolute` joints to indicate that the joint is a cut joint. A cut joint behaves similarly to a regular joint, but it introduces fewer constraints in order to avoid the otherwise over-constrained system resulting from closing the kinematic loop. While almost any joint can be chosen as the cut joint, it might be worthwhile experimenting with this choice in order to get an efficient representation. In this example, cutting `j5` produces an 8-dimensional state realization, while all other joints result in a 17-dimensional state.
9494
2. Increase the `state_priority` of the joint `j1` above the default joint priority 3. This encourages the model compiler to choose the joint coordinate of `j1` as state variable. The joint coordinate of `j1` is the only coordinate that uniquely determines the configuration of the mechanism. The choice of any other joint coordinate would lead to a singular representation in at least one configuration of the mechanism. The joint `j1` is the revolute joint located in the origin, see the animation below where this joint is made larger than the others.
9595

9696

@@ -103,11 +103,11 @@ systems = @named begin
103103
b1 = BodyShape(r = [0, 0.5, 0.1], radius=0.03)
104104
b2 = BodyShape(r = [0, 0.2, 0], radius=0.03)
105105
b3 = BodyShape(r = [-1, 0.3, 0.1], radius=0.03)
106-
rev = Revolute(n = [0, 1, 0], iscut=true)
106+
rev = Revolute(n = [0, 1, 0])
107107
rev1 = Revolute()
108108
j3 = Revolute(n = [1, 0, 0])
109109
j4 = Revolute(n = [0, 1, 0])
110-
j5 = Revolute(n = [0, 0, 1])
110+
j5 = Revolute(n = [0, 0, 1], iscut=true)
111111
b0 = FixedTranslation(r = [1.2, 0, 0], radius=0)
112112
end
113113
@@ -130,7 +130,7 @@ m = structural_simplify(IRSystem(fourbar2))
130130
131131
prob = ODEProblem(m, [], (0.0, 1.4399)) # The end time is chosen to make the animation below appear to loop forever
132132
133-
sol = solve(prob, Rodas4(autodiff=true))
133+
sol = solve(prob, FBDF(autodiff=true));
134134
@test SciMLBase.successful_retcode(sol)
135135
plot(sol, idxs=[j2.s]) # Plot the joint coordinate of the prismatic joint (green in the animation below)
136136
```

docs/src/examples/pendulum.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This results in a simplified model with the minimum required variables and equat
5555
We are now ready to create an `ODEProblem` and simulate it. We use the `Rodas4` solver from OrdinaryDiffEq.jl, and pass a dictionary for the initial conditions. We specify only initial condition for some variables, for those variables where no initial condition is specified, the default initial condition defined the model will be used.
5656
```@example pendulum
5757
D = Differential(t)
58-
defs = Dict(D(joint.phi) => 0, D(D(joint.phi)) => 0) # We may specify the initial condition here
58+
defs = Dict() # We may specify the initial condition here
5959
prob = ODEProblem(ssys, defs, (0, 3.35))
6060
6161
sol = solve(prob, Rodas4())
@@ -90,8 +90,7 @@ connections = [connect(world.frame_b, joint.frame_a)
9090
@named model = ODESystem(connections, t, systems = [world, joint, body, damper])
9191
ssys = structural_simplify(IRSystem(model))
9292
93-
prob = ODEProblem(ssys, [damper.phi_rel => 1, D(joint.phi) => 0, D(D(joint.phi)) => 0],
94-
(0, 10))
93+
prob = ODEProblem(ssys, [damper.phi_rel => 1], (0, 10))
9594
9695
sol = solve(prob, Rodas4())
9796
plot(sol, idxs = joint.phi, title="Damped pendulum")
@@ -123,7 +122,7 @@ connections = [connect(world.frame_b, joint.frame_a)
123122
@named model = ODESystem(connections, t, systems = [world, joint, body_0, damper, spring])
124123
ssys = structural_simplify(IRSystem(model))
125124
126-
prob = ODEProblem(ssys, [damper.s_rel => 1, D(D(joint.s)) => 0], (0, 10))
125+
prob = ODEProblem(ssys, [], (0, 10))
127126
128127
sol = solve(prob, Rodas4())
129128
Plots.plot(sol, idxs = joint.s, title="Mass-spring-damper system")
@@ -149,11 +148,7 @@ connections = [connect(world.frame_b, multibody_spring.frame_a)
149148
@named model = ODESystem(connections, t, systems = [world, multibody_spring, root_body])
150149
ssys = structural_simplify(IRSystem(model))
151150
152-
defs = Dict(collect(multibody_spring.r_rel_0 .=> [0, 1, 0])...,
153-
collect(root_body.r_0 .=> [0, 0, 0])...,
154-
collect(root_body.w_a .=> [0, 0, 0])...,
155-
collect(root_body.v_0 .=> [0, 0, 0])...,
156-
)
151+
defs = Dict()
157152
158153
prob = ODEProblem(ssys, defs, (0, 10))
159154
@@ -220,7 +215,7 @@ end
220215
model = complete(model)
221216
ssys = structural_simplify(IRSystem(model))
222217
223-
prob = ODEProblem(ssys, [model.shoulder_joint.phi => 0.0, model.elbow_joint.phi => 0.1], (0, 12))
218+
prob = ODEProblem(ssys, [model.shoulder_joint.phi => 0.0, model.elbow_joint.phi => 0.1], (0, 10))
224219
sol = solve(prob, Rodas4())
225220
plot(sol, layout=4)
226221
```

docs/src/examples/spring_mass_system.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ eqs = [
4646
4747
@named model = ODESystem(eqs, t, systems = [world; systems])
4848
ssys = structural_simplify(IRSystem(model))
49-
prob = ODEProblem(ssys,[
50-
D(p1.s) => 0,
51-
D(D(p1.s)) => 0,
52-
D(p2.s) => 0,
53-
D(D(p2.s)) => 0,
54-
], (0, 5))
49+
prob = ODEProblem(ssys,[], (0, 5))
5550
5651
sol = solve(prob, Rodas4())
5752
@assert SciMLBase.successful_retcode(sol)

0 commit comments

Comments
 (0)