# No. 19, Different Arrangements of Pulleys (Brown 1868, plate 19-22, figure 19).
#
# "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 plate, read strand by strand (1 unit = 1 cm). A large sheave A hangs on a hook from the
# ceiling. Two smaller sheaves, B and then C, hang stepwise down to the left. The weight carries three
# small sheaves, w3, w2 and w1, on its top. There are THREE ropes, and each is made fast at the pin of
# one sheave, goes down under a sheave on the weight, comes back up over that same sheave and down to
# the pin of the next:
#
#   * rope 1: from A's pin (fixed), down under w3, up over A, down to B's pin;
#   * rope 2: from B's pin, down under w2, up over B, down to C's pin;
#   * rope 3: from C's pin, down under w1, up over C, down to the hand.
#
# Kinematics. Let the weight rise at u. Rope 1's two strands to w3 shorten 2u, so B drops 2u. Rope 2
# then has three strands at B (two to w2, one to C), so C drops 3 x 2u + 2u = 8u. Rope 3 likewise
# has three strands at C, so the hand pays out 3 x 8u + 2u = 26u. The weight rises at 1/26 of the
# hand's haul.
#
# Forces, as a check. The hand pulls T. C hangs from rope 2's end and carries three parts of rope 3,
# so rope 2 carries 3T + W_C. B hangs from rope 1's end and carries three parts of rope 2, so rope 1
# carries 3 T2 + W_B. The weight hangs in two parts of each rope: 2(T1 + T2 + T) = 26T + 8 W_C + 2 W_B.
#
# Brown's rule is for a different reeving, so this one is not 2^n. Building it out is what gives 26.
#
# Two liberties, both stated here. First, the plate draws each rope's end at a sheave's pin, but a
# taut rope leaving a pin would have to run out through its own sheave's rim. Instead each block (and
# A's strap) carries a strap in front of its sheave with an eye just outside the rim, on the pin's
# vertical. Second, the plate's loose end hangs off at a slant; a slanted haul would shorten as C
# sinks and spoil the count, so the hand hauls plumb. Every other strand is plumb, as the plate draws
# it: each sheave on the weight is half the diameter (to the rope's centre) of the sheave above it.
#
# Nothing is driven but the hand: a slide in a plumb guide on rope 3's hauling part, at 6 cm/s. The
# weight's guide carries a dashpot, which stills its bounce on the ropes' stretch.
# Every rope is a chain of round hemp links lying on the rims, its eyes pinned to the bodies it is
# tied to. Nothing couples the hand to the weight except the three ropes.
number: 19
slug: different-arrangements-of-pulleys
name: Different Arrangements of Pulleys (first)
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, A's hook and strap, and the strap's eye under A, where rope 1 is made fast.
  - id: ceiling
    shape: part
    fixed: true
    pos: [0, 0, 100]
    density: 700
    color: "#c6b99c"
    pieces:
      - {kind: poly, points: [[-30.0, 100.0], [16.0, 100.0], [16.0, 102.4], [-30.0, 102.4]], y: [-1.2, 1.2], collide: 0}
      - {kind: rod, from: [0, 0, 100], to: [0, 0, 97.4], radius: 0.4, collide: 0, color: "#8f8a80"}        # the hook
      - {kind: rod, from: [0, -2.6, 97.4], to: [0, -2.6, 74.9], radius: 0.45, collide: 0, color: "#8f8a80"} # the strap, in front of A
      - {kind: rod, from: [0, 0, 97.4], to: [0, -2.6, 97.4], radius: 0.4, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [0, -2.6, 74.9], to: [0, 0, 74.9], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0, 74.9], radius: 0.9, inner: 0.4, y: [-0.4, 0.4], collide: 0, color: "#8f8a80"}   # rope 1's eye
      - {kind: rod, from: [0, -2.6, 86], to: [0, 2.2, 86], radius: 0.5, collide: 0, color: "#8f8a80"}      # A's pin
  # A: the fixed sheave on the hook.
  - {id: sheave_a, shape: pulley, radius: 9.6, width: 3.0, pos: [0, 0, 86], mass: 1.0, spokes: 0, hub: 1.8, flange: 0.5, color: "#e6dcc6"}
  # B: the middle block, its strap in front of the sheave with an eye above the rim (rope 1's end) and
  # one below it (rope 2's end), both on the pin's vertical.
  - id: block_b
    shape: part
    pos: [-10, 0, 62]
    mass: 0.6
    color: "#b8ac92"
    pieces:
      - {kind: rod, from: [-10, -2.4, 71.1], to: [-10, -2.4, 52.9], radius: 0.4, collide: 0}
      - {kind: rod, from: [-10, -2.4, 71.1], to: [-10, 0, 71.1], radius: 0.35, collide: 0}
      - {kind: rod, from: [-10, -2.4, 52.9], to: [-10, 0, 52.9], radius: 0.35, collide: 0}
      - {kind: disc, center: [-10, 71.1], radius: 0.9, inner: 0.4, y: [-0.4, 0.4], collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [-10, 52.9], radius: 0.9, inner: 0.4, y: [-0.4, 0.4], collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-10, -2.4, 62], to: [-10, 2.0, 62], radius: 0.45, collide: 0}           # the pin
  - {id: sheave_b, shape: pulley, mount: block_b, radius: 7.6, width: 3.0, pos: [-10, 0, 62], mass: 0.6, spokes: 0, hub: 1.5, flange: 0.5, color: "#e6dcc6"}
  # C: the lowest block, on the same plan: rope 2's end above, rope 3's end below.
  - id: block_c
    shape: part
    pos: [-18, 0, 40]
    mass: 0.4
    color: "#b8ac92"
    pieces:
      - {kind: rod, from: [-18, -2.4, 47.1], to: [-18, -2.4, 32.9], radius: 0.35, collide: 0}
      - {kind: rod, from: [-18, -2.4, 47.1], to: [-18, 0, 47.1], radius: 0.3, collide: 0}
      - {kind: rod, from: [-18, -2.4, 32.9], to: [-18, 0, 32.9], radius: 0.3, collide: 0}
      - {kind: disc, center: [-18, 47.1], radius: 0.8, inner: 0.35, y: [-0.4, 0.4], collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [-18, 32.9], radius: 0.8, inner: 0.35, y: [-0.4, 0.4], collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-18, -2.4, 40], to: [-18, 2.0, 40], radius: 0.4, collide: 0}           # the pin
  - {id: sheave_c, shape: pulley, mount: block_c, radius: 5.6, width: 3.0, pos: [-18, 0, 40], mass: 0.4, spokes: 0, hub: 1.2, flange: 0.5, color: "#e6dcc6"}
  # The weight, with its three small sheaves standing on lugs on its top, as the plate draws them.
  - id: load
    shape: part
    pos: [-4, 0, 11]
    mass: 50
    color: "#9c8460"
    pieces:
      - {kind: poly, points: [[-20.0, 6.0], [12.0, 6.0], [12.0, 16.0], [-20.0, 16.0]], y: [-5.0, 5.0], collide: 0}
      - {kind: rod, from: [5, -2.2, 16], to: [5, -2.2, 24], radius: 0.45, collide: 0, color: "#8f8a80"}     # w3's lug
      - {kind: rod, from: [-6, -2.2, 16], to: [-6, -2.2, 24], radius: 0.45, collide: 0, color: "#8f8a80"}   # w2's lug
      - {kind: rod, from: [-15, -2.2, 16], to: [-15, -2.2, 24], radius: 0.45, collide: 0, color: "#8f8a80"} # w1's lug
  - {id: w3, shape: pulley, mount: load, radius: 4.6, width: 2.4, pos: [5, 0, 24], mass: 0.3, spokes: 0, hub: 1.0, flange: 0.4, color: "#e6dcc6"}
  - {id: w2, shape: pulley, mount: load, radius: 3.6, width: 2.4, pos: [-6, 0, 24], mass: 0.3, spokes: 0, hub: 0.9, flange: 0.4, color: "#e6dcc6"}
  - {id: w1, shape: pulley, mount: load, radius: 2.6, width: 2.4, pos: [-15, 0, 24], mass: 0.3, spokes: 0, hub: 0.8, flange: 0.4, color: "#e6dcc6"}
  # The hand, hauling rope 3 plumb down from C's left side.
  - id: hand
    shape: grip
    pos: [-24, 0, 30]
    mass: 0.4
    color: "#c9bda2"
    rods:
      - {from: [-24, 0, 31.5], to: [-24, 0, 28.5], radius: 1.7}     # the fist closed on the rope
      - {from: [-24, 0, 28.5], to: [-24, 0, 26.8], radius: 1.35}    # the cuff
      - {from: [-24, 0, 26.8], to: [-24, 0, 23.0], radius: 1.1}     # the forearm
joints:
  - {id: j_a, type: hinge, body: sheave_a, axis: [0, 1, 0], damping: 0.01}           # A on its pin
  - {id: j_b, type: slide, body: block_b, axis: [0, 0, 1], range: [-8, 4]}          # the ropes alone hold B up
  - {id: j_sheave_b, type: hinge, body: sheave_b, axis: [0, 1, 0], damping: 0.005}
  - {id: j_c, type: slide, body: block_c, axis: [0, 0, 1], range: [-10, 4]}
  - {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: [-2, 6], damping: 2000}   # its guide: a dashpot that stills the 50 kg weight bouncing on 400 cm of stretchy rope (4.6 N at its 2.3 mm/s, 0.18 N at the hand)
  - {id: j_w3, type: hinge, body: w3, axis: [0, 1, 0], damping: 0.005}
  - {id: j_w2, type: hinge, body: w2, axis: [0, 1, 0], damping: 0.005}
  - {id: j_w1, type: hinge, body: w1, axis: [0, 1, 0], damping: 0.005}
  - {id: j_hand, type: slide, body: hand, axis: [0, 0, -1], range: [-1, 30]}        # plumb down the hauling part
cords:
  # Every rope goes down the left of its weight sheave, under it, up its right, over its upper sheave
  # from right to left and down: counter-clockwise in x-z at both, so both are `under`.
  # Rope 1: A's eye, under w3, over A, to B's upper eye. T1 = 3 T2 + W_B = 178 N in a steady lift.
  - id: rope1
    from: {body: ceiling, at: [0, 0, 74.9]}
    to: {body: block_b, at: [-10, 0, 71.1]}
    over: [w3, sheave_a]
    under: [w3, sheave_a]
    links: 88
    thickness: 0.8
    density: 1400          # hemp
    stiffness: 200000      # N/m per link (2 cm links): keeps sqrt(k/m) dt near 1.2
    pretension: 178        # N, what it carries in a steady lift
    damping: 400           # N s/m per link: hemp's own internal friction (much more makes the sheaves chatter)
    friction: 0.5          # hemp on a wooden sheave
  # Rope 2: B's lower eye, under w2, over B, to C's upper eye. T2 = 3T + W_C = 55.5 N.
  - id: rope2
    from: {body: block_b, at: [-10, 0, 52.9]}
    to: {body: block_c, at: [-18, 0, 47.1]}
    over: [w2, sheave_b]
    under: [w2, sheave_b]
    links: 75
    thickness: 0.8
    density: 1400
    stiffness: 150000      # 1.6 cm links
    pretension: 55.5
    damping: 400
    friction: 0.5
  # Rope 3: C's lower eye, under w1, over C, to the hand. T = 15.9 N.
  - id: rope3
    from: {body: block_c, at: [-18, 0, 32.9]}
    to: {body: hand, at: [-24, 0, 30]}
    over: [w1, sheave_c]
    under: [w1, sheave_c]
    links: 53
    thickness: 0.8
    density: 1400
    stiffness: 100000      # 1.2 cm links
    pretension: 15.9
    damping: 400
    friction: 0.5
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:
  # The count of parts: the weight rises at 1/26 of the haul, B sinks at 2/26 and C at 8/26.
  - {type: ratio, out: j_load, in: j_hand, expect: 0.03846, tol: 0.003, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_b, in: j_hand, expect: -0.07692, tol: 0.004, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_c, in: j_hand, expect: -0.30769, tol: 0.012, settle_s: 1.2, window_s: 1.0}
  # Each sheave rolls at the speed its strands pass it, over its radius to the rope's centre, in rad
  # per metre of haul. In each pair the rope's tied end and the weight's sheave close on each other at
  # a rate c: rope 1 at 1/26 (A fixed, weight rising), rope 2 at 3/26 (B sinking 2/26), rope 3 at
  # 9/26 (C sinking 8/26). So the upper sheave sees the rope run at 2c and the weight's sheave at c:
  # A 2/26/0.10 = 0.769, w3 1/26/0.05 = 0.769; B 6/26/0.08 = 2.885, w2 3/26/0.04 = 2.885;
  # C 18/26/0.06 = 11.54, w1 9/26/0.03 = 11.54.
  - {type: ratio, out: j_a, in: j_hand, expect: -0.769, tol: 0.06, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_w3, in: j_hand, expect: -0.769, tol: 0.06, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_sheave_b, in: j_hand, expect: -2.885, tol: 0.18, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_w2, in: j_hand, expect: -2.885, tol: 0.18, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_sheave_c, in: j_hand, expect: -11.54, tol: 0.6, settle_s: 1.2, window_s: 1.0}
  - {type: ratio, out: j_w1, in: j_hand, expect: -11.54, tol: 0.6, settle_s: 1.2, window_s: 1.0}
  # Brown's "power": T = (W - 8 W_C - 2 W_B)/26 with the weight and its sheaves 50.9 kg, C 0.8 kg and
  # B 1.2 kg, so (499.3 - 62.8 - 23.5)/26 = 15.9 N. Add 0.18 N for the weight's guide and take away
  # the hand's own 0.4 kg (3.9 N): the driver pulls 12.1 N.
  - {type: force, expect: 12.1, tol: 1.0, settle_s: 1.2, window_s: 1.0}
  # And the weight is seen to rise, at 6/26 = 0.23 cm/s.
  - {type: position, joint: j_load, min: 0.05, max: 2.0, settle_s: 1.2, window_s: 1.0}
  - {type: penetration, max: 0.0005, settle_s: 1.2}
camera: {target: [-6, 0, 42], position: [6, -260, 50], fov: 30}   # the plate's view: ceiling to weight
display:
  tiers:
    - {id: full, label: Full, ms: 6.0323}
    - {id: friction, label: Friction model, timestep: 0.002, integrator: discrete, model: capstan, ms: 0.0550}
  output: j_load
  labels: {j_hand: Hand hauling rope 3 (driver), j_load: Weight, j_b: Block B, j_c: Block C, j_a: Fixed sheave A}
  expect: {default: 0.03846}
