Skip to content

Commit 3b6bd76

Browse files
committed
add parameters to spring and damper
1 parent 75e4f60 commit 3b6bd76

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

docs/src/examples/swing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ W(args...; kwargs...) = Multibody.world
2424
@components begin
2525
frame_a = Frame()
2626
frame_b = Frame()
27-
joint1 = Spherical(isroot=true, state=true, d=0.001)
27+
joint1 = Spherical(isroot=true, state=true, d=0.001, color=[0.7, 0.7, 0.7, 0.7])
2828
rope = BodyShape(r=[0.0,-1,0], m=0.05, radius=0.01)
29-
spring = Spring(c = inv(0.04/60), m=0.01)
30-
damper = Damper(d = 50.0)
29+
spring = Spring(c = inv(0.04/60), m=0.01, radius=0.06)
30+
damper = Damper(d = 50.0, radius=0.05, length_fraction=0.1)
3131
end
3232
@equations begin
3333
connect(frame_a, joint1.frame_a)

ext/Render.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,14 @@ function render!(scene, ::typeof(Damper), sys, sol, t)
473473
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
474474
r_0b = get_fun(sol, collect(sys.frame_b.r_0))
475475
color = get_color(sys, sol, :gray)
476+
radius = sol(sol.t[1], idxs=sys.radius) |> Float32
477+
length_fraction = sol(sol.t[1], idxs=sys.length_fraction) |> Float32
476478
thing = @lift begin
477479
r1 = Point3f(r_0a($t))
478480
r2 = Point3f(r_0b($t))
479481
origin = r1
480482
d = r2 - r1
481-
extremity = d / norm(d) * 0.2f0 + r1
482-
radius = 0.1f0
483+
extremity = d / norm(d) * length_fraction + r1
483484
Makie.GeometryBasics.Cylinder(origin, extremity, Float32(radius))
484485
end
485486
mesh!(scene, thing; color)

src/forces.jl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,22 @@ additional equations to handle the mass are removed.
290290
- `kwargs`: are passed to `LineForceWithMass`
291291
292292
# Rendering
293-
- `num_windings = 6`
294-
- `color = [0,0,1,1]`
295-
- `radius = 0.1`
296-
- `N = 200`
293+
- `num_windings = 6`: Number of windings of the coil when rendered
294+
- `color = [0,0,1,1]`: Color of the spring when rendered
295+
- `radius = 0.1`: Radius of spring when rendered
296+
- `N = 200`: Number of points in mesh when rendered. Rendering time can be reduced somewhat by reducing this number.
297297
298298
See also [`SpringDamperParallel`](@ref)
299299
"""
300300
@component function Spring(; c, name, m = 0, lengthfraction = 0.5, s_unstretched = 0, num_windings=6, color=[0,0,1,1], radius=0.1, N=200, kwargs...)
301301
@named ptf = PartialTwoFrames()
302302
@unpack frame_a, frame_b = ptf
303303
pars = @parameters begin
304-
# c=c, [description = "spring constant", bounds = (0, Inf)]
305-
# s_unstretched=s_unstretched, [
306-
# description = "unstretched length of spring",
307-
# bounds = (0, Inf),
308-
# ] # Bug in MTK where parameters only passed to sub components are ignored
304+
c=c, [description = "spring constant", bounds = (0, Inf)]
305+
s_unstretched=s_unstretched, [
306+
description = "unstretched length of spring",
307+
bounds = (0, Inf),
308+
]
309309
num_windings = num_windings, [description = "Number of windings of the coil when rendered"]
310310
color[1:4] = color
311311
radius = radius, [description = "Radius of spring when rendered"]
@@ -375,16 +375,26 @@ and `D(s)` is the time derivative of `s`.
375375
# Arguments:
376376
- `d`: Damping coefficient
377377
378+
# Rendering
379+
- `radius = 0.1`: Radius of damper when rendered
380+
- `length_fraction = 0.2`: Fraction of the length of the damper that is rendered
381+
- `color = [0.5, 0.5, 0.5, 1]`: Color of the damper when rendered
382+
378383
See also [`SpringDamperParallel`](@ref)
379384
"""
380-
@component function Damper(; d, name, kwargs...)
385+
@component function Damper(; d, name, radius = 0.1, length_fraction = 0.2, color = [0.5, 0.5, 0.5, 1],kwargs...)
381386
@named plf = PartialLineForce(; kwargs...)
382387
@unpack s, f = plf
383-
@parameters d=d [description = "damping constant", bounds = (0, Inf)]
388+
pars = @parameters begin
389+
d=d, [description = "damping constant", bounds = (0, Inf)]
390+
radius = radius, [description = "Radius of damper when rendered"]
391+
length_fraction = length_fraction, [description = "Fraction of the length of the damper that is rendered"]
392+
color[1:4] = color
393+
end
384394
eqs = [
385395
f ~ d * D(s),
386396
]
387-
extend(ODESystem(eqs, t; name), plf)
397+
extend(ODESystem(eqs, t, [s, f], pars; name), plf)
388398
end
389399

390400
"""

0 commit comments

Comments
 (0)