Skip to content

Commit 3fcbc2f

Browse files
committed
add cutjoint options in chain, and broken test
1 parent 8a181b8 commit 3fcbc2f

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/components.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,8 @@ Representing a body with 3 translational and 3 rotational degrees-of-freedom.
234234
phid0 = zeros(3),
235235
r_0 = 0,
236236
v_0 = 0,
237-
radius = 0.05,
238-
v_0 = 0,
239237
w_a = 0,
238+
radius = 0.05,
240239
air_resistance = 0.0,
241240
color = [1,0,0,1],
242241
quat=false,)
@@ -416,7 +415,7 @@ There are three different methods of adding damping to the rope:
416415
- Damping in flexing of the rope, modeled as viscous friction in the joints between the links, controlled by the parameter `d_joint`.
417416
- Air resistance to the rope moving through the air, controlled by the parameter `air_resistance`. This damping is quadratic in the velocity (``f_d ~ -||v||v``) of each link relative to the world frame.
418417
"""
419-
function Rope(; name, l = 1, dir = [0,-1, 0], n = 10, m = 1, c = 0, d=0, air_resistance=0, d_joint = 0, color = [255, 219, 120, 255]./255, radius = 0.05f0, kwargs...)
418+
function Rope(; name, l = 1, dir = [0,-1, 0], n = 10, m = 1, c = 0, d=0, air_resistance=0, d_joint = 0, cutspherical = false, cutprismatic=false, color = [255, 219, 120, 255]./255, radius = 0.05f0, kwargs...)
420419

421420
@assert n >= 1
422421
systems = @named begin
@@ -428,8 +427,13 @@ function Rope(; name, l = 1, dir = [0,-1, 0], n = 10, m = 1, c = 0, d=0, air_res
428427
li = l / n # Segment length
429428
mi = m / n # Segment mass
430429

431-
# joints = [Spherical(name=Symbol("joint_$i"), isroot=!(iscut && i == 1), iscut = iscut && i == 1, state=true, d = d_joint) for i = 1:n+1]
432-
joints = [Spherical(; name=Symbol("joint_$i"), isroot=true, state=true, d = d_joint, radius=0, color) for i = 1:n+1]
430+
joints = [Spherical(name=Symbol("joint_$i"),
431+
# isroot=!(cutspherical && i == 1),
432+
isroot=true,
433+
iscut = cutspherical && i == 1,
434+
# state=!(cutspherical && i == 1),
435+
state=true,
436+
d = d_joint) for i = 1:n+1]
433437

434438
eqs = [
435439
connect(frame_a, joints[1].frame_a)
@@ -443,7 +447,7 @@ function Rope(; name, l = 1, dir = [0,-1, 0], n = 10, m = 1, c = 0, d=0, air_res
443447
springs = [Translational.Spring(c = ci, s_rel0=li, name=Symbol("link_$i")) for i = 1:n]
444448
dampers = [Translational.Damper(d = di, name=Symbol("damping_$i")) for i = 1:n]
445449
masses = [Body(; m = mi, name=Symbol("mass_$i"), isroot=false, r_cm = li/2*dir, air_resistance, color=0.9*color) for i = 1:n]
446-
links = [Prismatic(; n = dir, s0 = li, name=Symbol("flexibility_$i"), axisflange=true, color, radius) for i = 1:n]
450+
links = [Prismatic(; n = dir, s0 = li, name=Symbol("flexibility_$i"), axisflange=true, color, radius, iscut = cutprismatic && i == 1) for i = 1:n]
447451
for i = 1:n
448452
push!(eqs, connect(links[i].support, springs[i].flange_a, dampers[i].flange_a))
449453
push!(eqs, connect(links[i].axis, springs[i].flange_b, dampers[i].flange_b))

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,31 @@ tt = 0:0.1:10
10601060
@test Matrix(sol(tt, idxs = [collect(body.r_0[2:3]);])) Matrix(sol(tt, idxs = [collect(body2.r_0[2:3]);]))
10611061

10621062

1063+
@test_skip begin # Produces state with rotation matrix
1064+
number_of_links = 3
1065+
chain_length = 2
1066+
x_dist = 1.5 # Distance between the two mounting points
1067+
systems = @named begin
1068+
chain = Rope(l = chain_length, m = 5, n=number_of_links, c=1, d_joint=0.2, dir=[1, 0, 0], color=[0.5, 0.5, 0.5, 1], radius=0.05, cutprismatic=false, cutspherical=true)
1069+
fixed = FixedTranslation(; r=[x_dist, 0, 0], radius=0.02, color=[0.1,0.1,0.1,1]) # Second mounting point
1070+
end
1071+
1072+
connections = [connect(world.frame_b, fixed.frame_a, chain.frame_a)
1073+
connect(chain.frame_b, fixed.frame_b)]
1074+
1075+
@named mounted_chain = ODESystem(connections, t, systems = [systems; world])
1076+
1077+
ssys = structural_simplify(IRSystem(mounted_chain))
1078+
prob = ODEProblem(ssys, [
1079+
collect(chain.link_3.body.w_a) .=> [0,0,0];
1080+
collect(chain.link_3.frame_b.r_0) .=> [x_dist,0,0];
1081+
], (0, 4))
1082+
sol = solve(prob, Rodas4(autodiff=false))
1083+
@test SciMLBase.successful_retcode(sol)
1084+
1085+
# Multibody.render(mounted_chain, sol, x=3, filename = "mounted_chain.gif") # May take long time for n>=10
1086+
end
1087+
10631088
# ==============================================================================
10641089
## Simple motion with quaternions=============================================================
10651090
# ==============================================================================

0 commit comments

Comments
 (0)