# No. 6, Pulleys with Vibrating Lever (Brown 1868, p. 1).
#
# "By giving a vibratory motion to the lever secured to the semi-circular segment, the belt attached
# to the said segment imparts a reciprocating rotary motion to the two pulleys below."
#
# Layout from the plate (1 unit = 1 cm; segment rim r 9 = 113 px of the engraving): a straight lever
# with knob ends, rocking on a hub at the centre of the half wheel (the segment) that hangs below it;
# two equal pulleys below, side by side. The band is fastened to the segment at both ends: from the
# left end of the segment it runs down the left of its rim, crosses to the right-hand pulley, passes
# under both pulleys, and crosses back up from the left-hand pulley to the right of the segment's rim
# and its right end. Rocking the lever winds the band onto one side of the segment and off the other,
# so the band runs to and fro under the pulleys and turns both, together, to and fro.
#
# Fully physical: the only actuator is the hand on the lever (a velocity target rocking it ±0.45 rad
# at 0.5 Hz). The band is a cord of elastic links, riveted (pin joints) to the segment at its ends,
# pretensioned by its springs, and turns the pulleys by friction alone. Where the two leaves cross,
# they are bowed apart and rub past each other (cord-on-cord contact, as No. 2).
number: 6
slug: pulleys-with-vibrating-lever
name: Pulleys with Vibrating Lever
brown: "By giving a vibratory motion to the lever secured to the semi-circular segment, the belt attached to the said segment imparts a reciprocating rotary motion to the two pulleys below."
units: cm
sim: {timestep: 0.0001, integrator: implicitfast, iterations: 50, duration_s: 8, floor: false}
bodies:
  # The lever and the segment are one casting on one hub.
  - {id: rocker, shape: assembly, pos: [0, 0, 0], color: "#e8dcc0"}
  - {id: p_left, shape: pulley, radius: 4.1, width: 2.4, groove: 1.2, flange: 0.5, pos: [-12, 0, -23.7], mass: 0.6, spokes: 4, hub: 1.1}
  - {id: p_right, shape: pulley, radius: 4.1, width: 2.4, groove: 1.2, flange: 0.5, pos: [12, 0, -23.7], mass: 0.6, spokes: 4, hub: 1.1}
wheels:
  # The semicircular segment: the lower half of a grooved wheel, three spokes, on the lever's hub.
  - {id: segment, body: rocker, pos: [0, 0, 0], radius: 9, width: 2.4, groove: 1.4, flange: 0.5, mass: 1.2, spokes: 3, hub: 1.6, arc: [3.1416, 6.2832], color: "#e8dcc0"}
shafts:
  # The lever (in front of the segment's face), with a knob at each end.
  - {id: lever, body: rocker, from: [-18, -1.9, 0.6], to: [18, -1.9, 0.6], radius: 0.6, color: "#e8dcc0"}
  - {id: knob_l, body: rocker, from: [-18.6, -1.9, 0.6], to: [-17.4, -1.9, 0.6], radius: 1.1, color: "#e8dcc0"}
  - {id: knob_r, body: rocker, from: [17.4, -1.9, 0.6], to: [18.6, -1.9, 0.6], radius: 1.1, color: "#e8dcc0"}
  - {id: segment_bar, body: rocker, from: [-9.3, 0, 0.3], to: [9.3, 0, 0.3], radius: 0.45, color: "#e8dcc0"}   # the segment's diameter
joints:
  - {id: j_lever, type: hinge, body: rocker, axis: [0, 1, 0], damping: 0.01}
  - {id: j_left, type: hinge, body: p_left, axis: [0, 1, 0], damping: 0.002}
  - {id: j_right, type: hinge, body: p_right, axis: [0, 1, 0], damping: 0.002}
belts:
  - id: belt
    # counter-clockwise: under the two pulleys from left to right, up to the segment, which the band
    # wraps from outside the lower loop (so both leaves cross), and back down to the left pulley
    around: [p_left, p_right, segment]
    outside: [segment]
    ends: {wheel: segment, from: -0.06, to: 3.2}   # fastened just below each end of the segment
    section: round
    self_contact: true     # the two leaves rub past each other where they cross
    joint_armature: 0.000001   # kg·m² on the link hinges: the light cord links diverge without it
    links: 110
    segments: 10
    thickness: 0.6        # cord diameter
    width: 0.6
    density: 950
    stiffness: 30000
    damping: 2
    pretension: 15
    friction: 0.6
contact: {solref: [0.002, 1], solimp: [0.9, 0.95, 0.001], margin: 0}
# The hand: the lever's angular velocity follows 0.45·2π·0.5·cos(2π·0.5·t), i.e. it rocks ±0.45 rad.
driver: {joint: j_lever, kind: velocity, rpm: 0, swing: {amplitude: 0.45, hz: 0.5}, kv: 20, max_torque: 40}
checks:
  # The band does not slip on the segment (it is fastened), so each pulley turns through
  # (9 + 0.3)/(4.1 + 0.3) = 2.114 times the lever's angle, the opposite way (the leaves cross).
  # Over one full stroke (0.5 to 2.5 s): slope of pulley angle against lever angle, and r².
  - {type: follow, out: j_left, in: j_lever, expect: -2.114, tol: 0.08, settle_s: 0.5, window_s: 2}
  - {type: follow, out: j_right, in: j_lever, expect: -2.114, tol: 0.08, settle_s: 0.5, window_s: 2}
  - {type: self_contact, min_contacts: 50, max_penetration: 0.2, settle_s: 0.5}   # cord diameter 0.6
  - {type: penetration, max: 0.002, settle_s: 0.5}
camera: {target: [0, 0, -11], position: [22, -112, -3], fov: 30}
display:
  output: j_left
  labels: {j_lever: Lever and segment (hand), j_left: Left pulley, j_right: Right pulley}
  expect: {default: -2.114}
