# No. 20, Different Arrangements of Pulleys (Brown 1868, plate 19-22, figure 20).
#
# "19, 20, 21 and 22. Are different arrangements of pulleys. The following rule applies to these
# pulleys:—In a system of pulleys where each pulley is embraced by a cord attached at one end to a
# fixed point and at the other to the center of the movable pulley, the effect of the whole will be =
# the number 2, multiplied by itself as many times as there are movable pulleys in the system."
#
# The reeving, counted off the plate (1 unit = 1 cm; the plate is about 40 cm wide here). Three
# sheaves hang in a cascade from a ceiling, and THREE separate ropes:
#
#   * ROPE 1 is led over the top sheave A, which is fixed on a hook in the ceiling. Its left end is
#     hooked to the eye on the middle block B, and its right end is tied to the RIGHT-hand eye on
#     the weight. So A is a dead sheave: it only turns the rope down.
#   * ROPE 2 is led over B. Its left end is hooked to the eye on the bottom block C, its right end
#     to the MIDDLE eye on the weight. B turns and rides up and down on its rope.
#   * ROPE 3 is led over C. Its left end is the hauling part, which runs down and to the left, off
#     the plate, to the hand; its right end is tied to the LEFT-HAND eye on the weight. C is the
#     block the hand works on.
#
# The plate draws each cord's fall on the far side of the sheave it embraces and its end at the
# block's centre, which no taut rope can do — a fall landing on a sheave's centre would have to run
# through the sheave. What is kept is what the plate really shows: each cord reaches a block at the
# hook it hangs by, and the falls leave the sheaves tangent to them. So B and C carry a rigid hook
# arm out to the eye, standing 2.5 cm above the rim the next rope rides on, and the falls come off
# the rims plumb, exactly as the plate draws them.
#
# Brown's rule is for the other arrangement (one end of every cord fixed); this one puts an end of
# every cord on the weight itself, and the advantage is the sum of the doublings, 1 + 2 + 4 = 7.
# Tension balance (leaving the blocks' own weights aside): the hand pulls T. C hangs from one part of
# rope 2 and is pulled down by both parts of rope 3, so rope 2 carries 2T. B hangs from one part of
# rope 1 and is pulled down by both parts of rope 2, so rope 1 carries 4T. The weight hangs on one end
# of each rope: 7T. So the weight rises at a seventh of the hand's haul, and Brown's "power" is a
# seventh of the weight.
#
# Nothing is driven but the hand: a slide joint in a guide along rope 3's hauling part, hauled at a
# constant 6 cm/s — the one actuator. Everything else is contact and friction: each rope is a chain
# of round hemp links lying on the rims, its eyes pinned to the bodies it is tied to, and each
# sheave is free on its own pin inside its block. Nothing couples the hand to the weight except the
# three ropes.
number: 20
slug: different-arrangements-of-pulleys
name: Different Arrangements of Pulleys (second)
plate: [19, 20, 21, 22]
brown: "19, 20, 21 and 22. Are different arrangements of pulleys. The following rule applies to these pulleys:—In a system of pulleys where each pulley is embraced by a cord attached at one end to a fixed point and at the other to the center of the movable pulley, the effect of the whole will be = the number 2, multiplied by itself as many times as there are movable pulleys in the system."
units: cm
sim: {timestep: 0.0001, integrator: implicitfast, iterations: 60, duration_s: 2.4}
bodies:
  # The ceiling and the hook A is hung on.
  - id: ceiling
    shape: part
    fixed: true
    pos: [0, 0, 0]
    density: 700
    color: "#c6b99c"
    pieces:
      - {kind: poly, points: [[8.0, 87.4], [44.0, 87.4], [44.0, 89.6], [8.0, 89.6]], y: [-1.0, 1.0], collide: 0}
      - {kind: rod, from: [26, 0, 87.4], to: [26, 0, 82.4], radius: 0.32, collide: 0, color: "#8f8a80"}   # A's strap
      - {kind: rod, from: [25.1, -2.0, 82.0], to: [27.0, -2.0, 82.0], radius: 0.28, collide: 0, color: "#8f8a80"} # its hook, in front of the rope
  # A: the top sheave, hung in the ceiling's hook. Rope 1 only runs over it, so it turns but does
  # not move: a dead sheave, as the plate draws it.
  - {id: sheave_a, shape: pulley, radius: 7, width: 3.0, pos: [26, 0, 74], mass: 0.9, spokes: 0, hub: 1.5, flange: 0.5, color: "#e6dcc6"}
  # B: the middle block. The sheave turns on its own pin inside the block, and the block's guide is
  # the vertical, as the plate draws the falls plumb. Its hook arm stands out to the left and above,
  # clear of the rim rope 2 rides on, and carries rope 1's end at the eye.
  - id: block_b
    shape: part
    pos: [22, 0, 52]
    mass: 1.0
    color: "#b8ac92"
    pieces:
      - {kind: rod, from: [22, 0, 55.5], to: [18.5, 0, 61.5], radius: 0.35, collide: 0}          # the hook arm
      - {kind: disc, center: [18.5, 61.5], radius: 1.2, inner: 0.55, y: [-0.7, 0.7], collide: 0}  # its eye
      - {kind: rod, from: [20.6, -2.2, 52], to: [20.6, 2.2, 52], radius: 0.5, collide: 0}         # the pin
  - {id: sheave_b, shape: pulley, mount: block_b, radius: 7, width: 3.0, pos: [22, 0, 52], mass: 0.8, spokes: 0, hub: 1.5, flange: 0.5, color: "#e6dcc6"}
  # C: the bottom block, the hand's block, on the same plan as B, its hook arm carrying rope 2's end.
  - id: block_c
    shape: part
    pos: [18, 0, 30]
    mass: 1.0
    color: "#b8ac92"
    pieces:
      - {kind: rod, from: [18, 0, 33.5], to: [14.5, 0, 39.5], radius: 0.35, collide: 0}            # the hook arm
      - {kind: disc, center: [14.5, 39.5], radius: 1.2, inner: 0.55, y: [-0.7, 0.7], collide: 0}    # its eye
      - {kind: rod, from: [16.6, -2.2, 30], to: [16.6, 2.2, 30], radius: 0.5, collide: 0}         # the pin
  - {id: sheave_c, shape: pulley, mount: block_c, radius: 7, width: 3.0, pos: [18, 0, 30], mass: 0.8, spokes: 0, hub: 1.5, flange: 0.5, color: "#e6dcc6"}
  # The weight: the squared block Brown hangs, with an eye on its back for each of the three cords.
  # It hangs plumb on a vertical guide, for it can only rise.
  - id: load
    shape: part
    pos: [30, 0, 16.5]
    mass: 20
    color: "#9c8460"
    pieces:
      - {kind: poly, points: [[23.0, 12.0], [37.0, 12.0], [37.0, 21.0], [23.0, 21.0]], y: [-4.0, 4.0], collide: 0}
      - {kind: poly, points: [[26.6, 21.0], [27.4, 21.0], [27.4, 21.4], [26.6, 21.4]], y: [4.0, 4.15], collide: 0, color: "#7d6845"}
      - {kind: poly, points: [[30.6, 21.0], [31.4, 21.0], [31.4, 21.4], [30.6, 21.4]], y: [4.0, 4.15], collide: 0, color: "#7d6845"}
      - {kind: poly, points: [[34.6, 21.0], [35.4, 21.0], [35.4, 21.4], [34.6, 21.4]], y: [4.0, 4.15], collide: 0, color: "#7d6845"}
      - {kind: disc, center: [25.5, 21.6], radius: 0.9, inner: 0.4, y: [-0.5, 0.5], collide: 1}    # rope 3's eye
      - {kind: disc, center: [29.5, 21.6], radius: 0.9, inner: 0.4, y: [-0.5, 0.5], collide: 1}    # rope 2's eye
      - {kind: disc, center: [33.5, 21.6], radius: 0.9, inner: 0.4, y: [-0.5, 0.5], collide: 1}    # rope 1's eye
  # The hand, hauling rope 3's free end plumb down from C's left side. The plate draws the loose end
  # hanging off at a slant; a slanted haul would shorten as C sinks and spoil the count of parts, so
  # the hand hauls it plumb (starting high enough that it stays above the floor for the whole run).
  - id: hand
    shape: grip
    pos: [10.5, 0, 22]
    mass: 0.9
    color: "#c9bda2"
    rods:
      - {from: [10.5, 0, 23.5], to: [10.5, 0, 20.5], radius: 1.9}     # the fist closed on the rope
      - {from: [10.5, 0, 20.5], to: [10.5, 0, 18.6], radius: 1.5}     # the cuff
      - {from: [10.5, 0, 18.6], to: [10.5, 0, 15.0], radius: 1.2}      # the forearm
joints:
  - {id: j_a, type: hinge, body: sheave_a, axis: [0, 1, 0], damping: 0.01}  # A's axle in the ceiling hook
  - {id: j_b, type: slide, body: block_b, axis: [0, 0, 1], range: [-14, 4]}   # the rope alone holds B up
  - {id: j_sheave_b, type: hinge, body: sheave_b, axis: [0, 1, 0], damping: 0.005}  # B's sheave on its own pin
  - {id: j_c, type: slide, body: block_c, axis: [0, 0, 1], range: [-12, 6]}
  - {id: j_sheave_c, type: hinge, body: sheave_c, axis: [0, 1, 0], damping: 0.005}
  - {id: j_load, type: slide, body: load, axis: [0, 0, 1], range: [-6, 6]}
  - {id: j_hand, type: slide, body: hand, axis: [0, 0, -1], range: [-1, 30]}  # plumb down the hauling part
cords:
  # Rope 1: from B's eye, over the fixed sheave A, down to the right-hand eye on the weight. Its two
  # falls leave the rim plumb, 26 ± 7.5, so B's hook arm reaches out to x = 18.5 to meet the left one.
  - id: rope1
    from: {body: block_b, at: [18.5, 0, 61.5]}
    over: [sheave_a]
    to: {body: load, at: [33.5, 0, 21.6]}
    links: 52
    thickness: 1.0
    density: 1400           # hemp
    stiffness: 400000       # N/m per link: a rope is nearly inextensible
    pretension: 125         # N, what it carries in a steady lift: 4T + 2 W_C + W_B
    damping: 3000          # N s/m per link: hemp's own internal friction, so a rope does not ring
    friction: 0.5           # hemp on a wooden sheave
  # Rope 2: from C's eye, over B, down to the middle eye on the weight. Its falls leave B plumb at
  # 22 ± 7.5, so C's hook arm reaches out to x = 14.5 to meet the left one.
  - id: rope2
    from: {body: block_c, at: [14.5, 0, 39.5]}
    over: [sheave_b]
    to: {body: load, at: [29.5, 0, 21.6]}
    links: 38
    thickness: 1.0
    density: 1400
    stiffness: 400000
    pretension: 54          # N, 2T + W_C
    damping: 3000          # N s/m per link: hemp's own internal friction, so a rope does not ring
    friction: 0.5
  # Rope 3: the hand's rope, over C and down to the left-hand eye on the weight. Its falls leave C
  # plumb at 18 ± 7.5; the hauling part runs on down to the left, where the hand is.
  - id: rope3
    from: {body: hand, at: [10.5, 0, 22]}
    over: [sheave_c]
    to: {body: load, at: [25.5, 0, 21.6]}
    links: 28
    thickness: 1.0
    density: 1400
    stiffness: 150000       # N/m per link: its links are short (1.4 cm), so softer keeps sqrt(k/m)*dt under 1; 18 N stretches it 3 mm
    pretension: 18          # N, T
    damping: 3000          # N s/m per link: hemp's own internal friction, so a rope does not ring
    friction: 0.5
# The ropes lie on the sheaves under the whole weight, so their contact has to be stiff: the links
# press into the rims, which the hand's haul then works against.
contact: {solref: [0.0005, 1], solimp: [0.98, 0.999, 0.0001], margin: 0}
driver: {joint: j_hand, kind: velocity, speed: 6, kv: 60000, max_torque: 400}
checks:
  # Brown's count for this arrangement: an end of every cord is on the weight, so it hangs in 1 + 2 + 4
  # = 7 parts of the hand's pull and rises at a seventh of the haul. The lengths say the same: rope 1
  # makes B sink as fast as the weight rises; rope 2 then makes C sink three times as fast; and the
  # hand's rope, plumb, pays out 2 x 3 + 1 = 7 times the weight's rise.
  - {type: ratio, out: j_load, in: j_hand, expect: 0.142857, tol: 0.006, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_b, in: j_hand, expect: -0.142857, tol: 0.006, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_c, in: j_hand, expect: -0.428571, tol: 0.015, settle_s: 1.2, window_s: 1.0}
  # Each sheave rolls at the speed its strands pass it, over (R + rope radius) = 0.075 m, in rad per
  # metre of hand. A: B's strand falls at v/7 and the weight's rises at v/7, so 1/(7 x 0.075) = 1.905.
  # B: relative to its pin, C's strand falls at 2v/7 and the weight's rises at 2v/7, so 3.810.
  # C: relative to its pin, the weight's strand rises at 4v/7, so 7.619.
  - {type: ratio, out: j_a, in: j_hand, expect: -1.905, tol: 0.1, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_sheave_b, in: j_hand, expect: -3.810, tol: 0.2, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_sheave_c, in: j_hand, expect: -7.619, tol: 0.4, settle_s: 1.2, window_s: 1.0}
  # Brown's "power", by tension balance with the blocks' own weights (B and C 1.8 kg each). C:
  # T2 = 2T + W_C. B: T1 = 2 T2 + W_B. Weight: T1 + T2 + T = 196.2 N, so T = (196.2 - 3 W_C - W_B)/7
  # = 17.9 N. The hand's own 0.9 kg pulls 8.8 N of that down its plumb guide, so the driver pulls 9.1 N.
  - {type: force, expect: 9.1, tol: 1.5, settle_s: 1.2, window_s: 1.0}
  # And the weight is seen to rise, at 6/7 cm/s.
  - {type: position, joint: j_load, min: 0.2, max: 3.0, settle_s: 1.2, window_s: 1.0}
  - {type: penetration, max: 0.0005, settle_s: 1.2}
camera: {target: [22, 0, 30], position: [40, -225, 38], fov: 32}   # the plate's view, ceiling to weight
display:
  tiers:
    - {id: full, label: Full, ms: 2.3262}
    - {id: fine, label: Fine, links: [31, 23, 17], timestep: 0.0008, integrator: discrete, ms: 0.6491}
    - {id: light, label: Lightest, links: [31, 23, 17], timestep: 0.0016, integrator: discrete, armature: 1.0e-7, ms: 0.5244}
    - {id: friction, label: Friction model, timestep: 0.002, integrator: discrete, model: capstan, ms: 0.0472}
  output: j_load
  labels: {j_hand: Hand hauling rope 3 (driver), j_load: Weight on the three cords, j_b: Middle block B, j_c: Bottom block C}
  expect: {default: 0.142857}