Skip to content

Commit a5a4016

Browse files
committed
remove some default initial conditions
1 parent d69666a commit a5a4016

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

docs/src/examples/wheel.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ prob = ODEProblem(ssys, [
264264
], (0.0, 15.0))
265265
sol = solve(prob, Rodas5Pr())
266266
render(model, sol, show_axis=false, x=0, y=0, z=4, traces=[model.slipBasedWheelJoint.frame_a], filename="slipwheel.gif")
267+
nothing # hide
267268
```
268269

269270
![slipwheel animation](slipwheel.gif)
@@ -275,8 +276,8 @@ A more elaborate example with 4 wheels.
275276
@mtkmodel TwoTrackWithDifferentialGear begin
276277
@components begin
277278
body = Pl.Body(m = 100, I = 1, gy = 0)
278-
body1 = Pl.Body(m = 300, I = 0.1, r = [1, 1], v = [0, 0], phi = 0, w = 0, gy = 0)
279-
body2 = Pl.Body(m = 100, I = 1, gy = 0)
279+
body1 = Pl.Body(m = 300, I = 0.1, r = [1, 1], v = [0, 0], phi = 0, w = 0, gy = 0,)
280+
body2 = Pl.Body(m = 100, I = 1, gy = 0,)
280281
wheelJoint1 = Pl.SlipBasedWheelJoint(
281282
radius = 0.25,
282283
r = [0, 1],
@@ -383,4 +384,8 @@ prob = ODEProblem(ssys, defs, (0.0, 5.0))
383384
sol = solve(prob, Rodas5P(autodiff=false))
384385
@test SciMLBase.successful_retcode(sol)
385386
Multibody.render(model, sol, show_axis=false, x=0, y=0, z=5, filename="twotrack.gif")
386-
```
387+
nothing # hide
388+
```
389+
390+
![twotrack animation](twotrack.gif)
391+
```

src/PlanarMechanics/components.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Body component with mass and inertia
5858
# Connectors:
5959
- `frame`: 2-dim. Coordinate system
6060
"""
61-
@component function Body(; name, m, I, r = zeros(2), v=nothing, phi = 0, w=nothing, gy = -9.807, radius=0.1, render=true, color=Multibody.purple, state_priority=2)
61+
@component function Body(; name, m, I, r = zeros(2), v=nothing, phi = nothing, w=nothing, gy = -9.807, radius=0.1, render=true, color=Multibody.purple, state_priority=2)
6262
@named frame_a = Frame()
6363
pars = @parameters begin
6464
m = m, [description = "Mass of the body"]

src/PlanarMechanics/joints.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
2424
"""
2525
@component function Revolute(;
2626
name,
27-
axisflange = false, render = true, radius = 0.1, color = [1.0, 0.0, 0.0, 1.0], phi=0, w=0,
27+
axisflange = false, render = true, radius = 0.1, color = [1.0, 0.0, 0.0, 1.0], phi=nothing, w=nothing,
2828
iscut = false,
2929
state_priority = 10)
3030
@named partial_frames = PartialTwoFrames()
@@ -112,8 +112,8 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
112112
@component function Prismatic(;
113113
name,
114114
r = [0,0],
115-
s = 0,
116-
v = 0,
115+
s = nothing,
116+
v = nothing,
117117
axisflange = false,
118118
render = true,
119119
radius = 0.1,

test/test_PlanarMechanics.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ import ModelingToolkitStandardLibrary.Mechanical.Rotational
466466
revolute = Pl.Revolute(phi = 0, w = 0)
467467
fixed = Pl.Fixed()
468468
engineTorque = Rotational.ConstantTorque(tau_constant = 2)
469-
body = Pl.Body(m = 10, I = 1, gy=0)
469+
body = Pl.Body(m = 10, I = 1, gy=0, phi=0, w=0)
470470
inertia = Rotational.Inertia(J = 1, phi = 0, w = 0)
471471
constant = Blocks.Constant(k = 0)
472472
end
@@ -672,13 +672,15 @@ import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as Transl
672672

673673
guesses = ModelingToolkit.missing_variable_defaults(model)
674674
ps = parameters(model)
675-
initsys = generate_initializesystem(ssys)
676-
u0 = merge(Dict(guesses), ModelingToolkit.defaults(model))
677-
initprob = NonlinearLeastSquaresProblem(initsys, u0, [ps; t => 0.0])
675+
fulldefs = defaults(model)
676+
defs = Dict(filter(p->!ModelingToolkit.isparameter(p[1]), collect(ModelingToolkit.defaults(model))))
677+
u0 = merge(Dict(guesses), defs)
678+
initsys = generate_initializesystem(ssys; guesses=u0)
679+
initprob = NonlinearLeastSquaresProblem(initsys, u0, [[p => fulldefs[p] for p in ps]; t => 0.0])
678680
u0sol = solve(initprob)
679681

680682

681-
prob = ODEProblem(ssys, unknowns(ssys) .=> u0sol[unknowns(ssys)], (0.0, 5.0))
683+
prob = ODEProblem(ssys, unknowns(ssys) .=> u0sol[unknowns(ssys)]*0.7, (0.0, 5.0))
682684
sol = solve(prob, Rodas5P(), initializealg = ShampineCollocationInit())
683685
@test SciMLBase.successful_retcode(sol)
684686
end

0 commit comments

Comments
 (0)