# No. 5, Pulleys with Tightening Mechanism (Brown 1868, p. 1).
#
# "Resembles 1, with the addition of a movable tightening pulley, B. When this pulley is pressed
# against the band to take up the slack, the belt transmits motion from one of the larger pulleys to
# the other; but when it is not, the belt is so slack as not to transmit motion."
#
# Layout from the plate (1 unit = 1 cm, top pulley r 9 = 54 px of the engraving): the driving pulley
# at the top, a smaller pulley below it a little to the right, and B, a small loose pulley on the end
# of a handle, pressing on the back of the left-hand (slack) side of the band from outside the loop.
#
# Fully physical: only the top pulley is motor-driven. The band is a closed chain of elastic leather
# links; it turns the lower pulley by friction alone, against a bearing brake (the load). The handle
# is a rod sliding in a guide, held against a stop by a spring: pressed in, B deflects the band 4.3
# units and lengthens its path by 0.91 units, which is 0.40 of stretch (4 N of tension) plus 0.51 of
# slack taken up; withdrawn (the operator's hand at 4 s, or the `withdrawn` variant from the start),
# the band is 0.51 units longer than the open path round the two pulleys and hangs slack.
number: 5
slug: pulleys-with-tightening-mechanism
name: Pulleys with Tightening Mechanism
brown: "Resembles 1, with the addition of a movable tightening pulley, B. When this pulley is pressed against the band to take up the slack, the belt transmits motion from one of the larger pulleys to the other; but when it is not, the belt is so slack as not to transmit motion."
units: cm
sim: {timestep: 0.0001, integrator: implicitfast, iterations: 50, duration_s: 12}   # 0.2 ms diverges with links this stiff
bodies:
  - {id: p_top, shape: pulley, radius: 9, width: 4, pos: [0, 0, 62], mass: 2.0, spokes: 4, hub: 2.4}
  - {id: p_bot, shape: pulley, radius: 6.25, width: 4, pos: [2.3, 0, 8.8], mass: 1.0, spokes: 4, hub: 1.8}
  # B's handle: a rod from B's axle out to the grip at the lower left, sliding along its own length.
  - id: handle
    shape: lever
    pos: [-6, 0, 31.5]
    mass: 0.4
    rods:
      - {from: [-6, -0.2, 31.5], to: [-13.4, -0.2, 28.3], radius: 0.55}
      - {from: [-13.4, -0.2, 28.3], to: [-17.6, -0.2, 26.5], radius: 0.75}
  # B itself turns on its axle in the end of the handle, so the band can run over it.
  - {id: p_B, shape: pulley, radius: 4.3, width: 4, pos: [-6, 0, 31.5], mass: 0.3, spokes: 0, hub: 1.3, mount: handle, color: "#e3d7bd"}
joints:
  - {id: j_top, type: hinge, body: p_top, axis: [0, 1, 0], damping: 0.002}
  - {id: j_bot, type: hinge, body: p_bot, axis: [0, 1, 0], damping: 0.01, frictionloss: 0.05}   # the load: a bearing brake (0.05 N·m)
  # The handle slides along its own length (0.918, 0, 0.397). 0 = pressed in, on the stop as drawn;
  # -6 = withdrawn, on the back stop, B clear of the band. The spring (N/m) holds it on a stop.
  - {id: j_handle, type: slide, body: handle, axis: [0.918, 0, 0.397], range: [-6, 0], stiffness: 300, springref: 2, damping: 150}   # damped: moved over about half a second, as by hand
  - {id: j_B, type: hinge, body: p_B, axis: [0, 1, 0], damping: 0.0005}
belts:
  - id: belt
    around: [p_top, p_B, p_bot]   # counter-clockwise: over the top, down the left side past B, round the bottom
    outside: [p_B]                # B presses on the back of the band
    links: 100
    segments: 10
    thickness: 0.4
    width: 3.2
    density: 950
    stiffness: 100000     # N/m per link
    damping: 2
    pretension: 4         # N with B pressed in: 100 links × 4/100000 m = 0.40 units of stretch
    friction: 0.6         # leather on iron
contact: {solref: [0.004, 1], solimp: [0.9, 0.95, 0.001], margin: 0}
# Turning this way the band is drawn up the right-hand side, so the left-hand side, where B is, is the
# slack side, as in the plate.
driver: {joint: j_top, kind: velocity, rpm: -30, kv: 2, max_torque: 5}
# The operator: B pressed in at the start, withdrawn at 4 s, pressed in again at 8 s.
hand:
  - {t: 4, springref: {j_handle: -8}}
  - {t: 8, springref: {j_handle: 2}}
variants:
  - id: pressed
    note: "B pressed against the band: the slack is taken up and the band drives the lower pulley"
    springref: {j_handle: 2}
  - id: withdrawn
    note: "B withdrawn from the start: the band hangs slack and the lower pulley stands still"
    springref: {j_handle: -8}
    hand: []
variant: pressed
checks:
  # B pressed in: open band, same direction; rims 9.2 and 6.45 at the belt's centreline:
  # 9.2/6.45 = 1.426, less creep.
  - {type: ratio, out: j_bot, in: j_top, expect: 1.426, tol: 0.05, settle_s: 1.5, window_s: 1}
  - {type: position, joint: j_handle, min: -0.05, max: 0.05, settle_s: 1, window_s: 1.5}   # B on its stop, pressed in
  - {type: belt_on, belt: belt, max_radial_dev: 1.5, max_lateral: 0.6, duration_s: 2.5}
  - {type: penetration, max: 0.002, settle_s: 1}
  # B withdrawn (the band hangs slack, the lower pulley stops) is checked on the `withdrawn` variant in
  # tests/test_movements.py; the render shows the full in / withdrawn at 4 s / in again at 8 s cycle.
camera: {target: [-2.5, 0, 35], position: [52, -168, 50], fov: 30}
display:
  output: j_bot
  labels: {j_top: Upper pulley (driver), j_bot: Lower pulley, j_B: Tightening pulley B}
  expect: {default: 1.426, pressed: 1.426, withdrawn: 0}
  lever: {joint: j_handle, label: Tightening pulley B, states: {Pressed in: 2, Withdrawn: -8}}
