# No. 82, Double Treadle Ratchet (Brown 1868).
#
# "On motion being given to the two treadles, D, a nearly continuous motion is imparted, through the
# vibrating arms, B, and their attached pawls, to the ratchet-wheel, A. A chain or strap attached to
# each treadle passes over the pulley, C, and as one treadle is depressed the other is raised."
#
# Laid out as Brown draws it (1 unit = 1 cm): the ratchet wheel A (30 hooked teeth, tips r 10) on its
# shaft; two arms B swinging loose on the same shaft, one above and one below the horizontal, each
# carrying at its end a pawl held in to the teeth by a spring; a link from each arm's end down to its
# treadle D; both treadles pivoted on one block at the left, their far ends tied by a strap that runs
# up over the sheave C on its frame and down again.
#
# Fully physical. The only inputs are the two feet, each pressing (never pulling) its own treadle in
# turn. Pressing a treadle pulls its link and arm down, and the arm's pawl pushes a tooth: A turns
# clockwise. The same stroke lifts the other treadle through the strap (a cord in tension only), which
# raises the other arm, whose pawl rides back up over the teeth and clicks into the next one. Then the
# feet change. A carries a load (the work it drives, a damping torque on its shaft) and has inertia, so
# it runs on through the change: nearly continuous rotation, one way only. The strap is frictionless
# on C, so C itself stands still.
number: 82
slug: double-treadle-ratchet
name: Double Treadle Ratchet
brown: "On motion being given to the two treadles, D, a nearly continuous motion is imparted, through the vibrating arms, B, and their attached pawls, to the ratchet-wheel, A. A chain or strap attached to each treadle passes over the pulley, C, and as one treadle is depressed the other is raised."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 50, duration_s: 6, floor: false}
bodies:
  # A: the ratchet wheel, a solid cast-iron disc (its inertia carries it through the change of feet), 30 hooked teeth on the right of each tooth (seen from the front), turning clockwise
  - id: wheel
    shape: part
    pos: [0, 0, 30]
    density: 7200
    friction: 0.15
    color: "#bdb6a6"
    pieces:
      - {"kind": "wheel", "center": [0, 30], "teeth": 30, "tooth": [[10.0, 0], [8.5, -0.03], [8.5, -0.205]], "phase": -0.14835, "root": 8.8, "rim": 1.5, "hub": 1.5, "spokes": 0, "y": [-1.2, 1.2], "collide": 2}
      - {"kind": "disc", "center": [0, 30], "radius": 0.42, "y": [-3.3, 4.6], "color": "#8f8a80"}   # shaft A
      - {"kind": "disc", "center": [0, 30], "radius": 4.5, "inner": 0.42, "y": [2.4, 3.4], "color": "#8f8a80"}   # drum of the load (a hoist barrel)
  # B, upper: swings loose on A's shaft, in front of A
  - id: arm1
    shape: part
    pos: [0, 0, 30]
    pieces:
      - {"kind": "disc", "center": [0, 30], "radius": 1.3, "inner": 0.42, "y": [-2.15, -1.35]}
      - {"kind": "rod", "from": [0, -1.75, 30], "to": [12.07407, -1.75, 33.23524], "radius": 0.38}
      - {"kind": "disc", "center": [12.07407, 33.23524], "radius": 0.55, "y": [-2.15, -1.35]}
  # its pawl, on a pin at the arm's end; a spring on the pin (stiffness, springref) holds the tip in to the teeth, a stop keeps it off the rim
  - id: pawl1
    shape: part
    pos: [12.07407, 0, 33.23524]
    mount: "arm1"
    friction: 0.15
    color: "#a39d90"
    pieces:
      - {"kind": "poly", "points": [[10.21177, 28.59461], [10.10094, 28.64064], [12.00867, 33.91209], [12.59973, 33.66662]], "y": [-1.1, -0.2], "collide": 1}
      - {"kind": "disc", "center": [12.07407, 33.23524], "radius": 0.3, "y": [-2.15, -0.2], "color": "#8f8a80"}
  # the link from the arm's end down to the front treadle
  - id: link1
    shape: part
    pos: [12.07407, 0, 33.23524]
    mount: "arm1"
    pieces:
      - {"kind": "rod", "from": [12.07407, -2.4, 33.23524], "to": [12.07407, -2.4, 8.4], "radius": 0.3}
      - {"kind": "disc", "center": [12.07407, 8.4], "radius": 0.5, "y": [-2.7, -2.1]}
  # D, front: pivoted on the block at the left; the front foot presses it
  - id: treadle1
    shape: part
    pos: [-12.0, 0, 8.0]
    density: 650
    color: "#c9a878"
    pieces:
      - {"kind": "poly", "points": [[-13.0, 7.5], [34.0, 7.5], [34.0, 8.4], [-13.0, 8.4]], "y": [-3.0, -2.2]}
      - {"kind": "disc", "center": [-12.0, 8.0], "radius": 0.35, "y": [-3.3, -1.9], "color": "#8f8a80"}
  # B, lower: also in front of A; its end pin reaches back past A's rim to its pawl and link
  - id: arm2
    shape: part
    pos: [0, 0, 30]
    pieces:
      - {"kind": "disc", "center": [0, 30], "radius": 1.3, "inner": 0.42, "y": [-3.0, -2.2]}
      - {"kind": "rod", "from": [0, -2.6, 30], "to": [10.82532, -2.6, 23.75], "radius": 0.38}
      - {"kind": "disc", "center": [10.82532, 23.75], "radius": 0.55, "y": [-3.0, -2.2]}
  # its pawl
  - id: pawl2
    shape: part
    pos: [10.82532, 0, 23.75]
    mount: "arm2"
    friction: 0.15
    color: "#a39d90"
    pieces:
      - {"kind": "poly", "points": [[6.22705, 21.78543], [6.18123, 21.89634], [11.25768, 24.27485], [11.50204, 23.68334]], "y": [0.2, 1.1], "collide": 1}
      - {"kind": "disc", "center": [10.82532, 23.75], "radius": 0.3, "y": [-3.0, 2.7], "color": "#8f8a80"}
  # the link down to the back treadle
  - id: link2
    shape: part
    pos: [10.82532, 0, 23.75]
    mount: "arm2"
    pieces:
      - {"kind": "rod", "from": [10.82532, 2.4, 23.75], "to": [10.82532, 2.4, 8.4], "radius": 0.3}
      - {"kind": "disc", "center": [10.82532, 8.4], "radius": 0.5, "y": [2.1, 2.7]}
  # D, back: the back foot presses it
  - id: treadle2
    shape: part
    pos: [-12.0, 0, 8.0]
    density: 650
    color: "#c9a878"
    pieces:
      - {"kind": "poly", "points": [[-13.0, 7.5], [34.0, 7.5], [34.0, 8.4], [-13.0, 8.4]], "y": [2.2, 3.0]}
      - {"kind": "disc", "center": [-12.0, 8.0], "radius": 0.35, "y": [1.9, 3.3], "color": "#8f8a80"}
  # the frame: A's standard, the treadles' pivot block, the posts of C and C itself (a sheave on an axle across the frame)
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {"kind": "poly", "points": [[-1.6, 30], [1.6, 30], [4.5, 0.8], [-4.5, 0.8]], "y": [3.6, 4.6]}
      - {"kind": "disc", "center": [0, 30], "radius": 1.6, "y": [3.6, 4.6]}
      - {"kind": "poly", "points": [[-15, 0.8], [-9, 0.8], [-10.5, 7.2], [-13.5, 7.2]], "y": [-3.6, 3.6]}
      - {"kind": "disc", "center": [-12, 8], "radius": 0.9, "y": [-3.6, -3.2]}
      - {"kind": "disc", "center": [-12, 8], "radius": 0.9, "y": [3.2, 3.6]}
      - {"kind": "poly", "points": [[-20, 0], [40, 0], [40, 0.8], [-20, 0.8]], "y": [-5, 5], "color": "#b9b09c"}
      - {"kind": "poly", "points": [[28.3, 0.8], [29.1, 0.8], [29.1, 22.5], [28.3, 22.5]], "y": [-0.5, 0.5]}
      - {"kind": "poly", "points": [[32.9, 0.8], [33.7, 0.8], [33.7, 22.5], [32.9, 22.5]], "y": [-0.5, 0.5]}
      - {"kind": "rod", "from": [28.3, 0, 19], "to": [33.7, 0, 19], "radius": 0.22, "color": "#8f8a80"}
      - {"kind": "rod", "from": [30.3, 0, 19], "to": [31.7, 0, 19], "radius": 2.5, "color": "#e6d7b0"}
      - {"kind": "rod", "from": [30.1, 0, 19], "to": [30.3, 0, 19], "radius": 3.1, "color": "#e6d7b0"}
      - {"kind": "rod", "from": [31.7, 0, 19], "to": [31.9, 0, 19], "radius": 3.1, "color": "#e6d7b0"}
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.06}   # the load (the work A drives) and its bearings
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_arm1", "body": "arm1", "damping": 0.002}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_pawl1", "body": "pawl1", "damping": 0.0001, "range": [-0.2, 0.33726], "stiffness": 0.03, "springref": 0.58726}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_link1", "body": "link1", "damping": 0.0005}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_td1", "body": "treadle1", "damping": 0.01, "range": [-0.13, 0.13]}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_arm2", "body": "arm2", "damping": 0.002}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_pawl2", "body": "pawl2", "damping": 0.0001, "range": [-0.2, 0.33726], "stiffness": 0.03, "springref": 0.58726}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_link2", "body": "link2", "damping": 0.0005}
  - {"type": "hinge", "axis": [0, 1, 0], "id": "j_td2", "body": "treadle2", "damping": 0.01, "range": [-0.13, 0.13]}
# each link is pinned to its treadle (closing the loop arm, link, treadle, frame)
pins:
  - {"id": "pin1", "a": "treadle1", "b": "link1", "at": [12.07407, -2.4, 8.4]}
  - {"id": "pin2", "a": "treadle2", "b": "link2", "at": [10.82532, 2.4, 8.4]}
# the strap: from the front treadle's end up over C and down to the back treadle's end (tension only)
ropes:
  - {"id": "strap", "from": {"body": "treadle1", "at": [31.0, -2.6, 8.4]}, "over": {"center": [31.0, 0, 19.0], "radius": 2.6, "axis": "x", "side": [31.0, 0, 28.0]}, "to": {"body": "treadle2", "at": [31.0, 2.6, 8.4]}, "width": 0.8, "thickness": 0.2}
contact: {solref: [0.001, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
# Brown's feet: each presses its treadle down in turn (half-sine, never pulling). Nothing else is driven.
driver: {joint: j_td1, kind: feet, feet: {joints: [j_td1, j_td2], force: 0.5, hz: 1}, max_torque: 1.5}
checks:
  # A turns one way only, nearly continuously: never slower than a fifth of its mean speed, never backwards
  - {type: turning, joint: j_wheel, direction: 1, min_mean: 0.5, slow: 0.2, min_fraction: 0.95, settle_s: 1, window_s: 2}
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.01, settle_s: 0.5, window_s: 2.5}
  # each pawl rides back over the teeth and drops in (on its arm's return, or when A runs ahead of it)
  - {type: clicks, joint: j_pawl1, lift: 0.08, min: 5, settle_s: 0.5, window_s: 2.5}
  - {type: clicks, joint: j_pawl2, lift: 0.08, min: 5, settle_s: 0.5, window_s: 2.5}
  # the strap: as one treadle goes down the other comes up by the same angle
  - {type: follow, out: j_td2, in: j_td1, expect: -1, tol: 0.05, settle_s: 0.5, window_s: 2.5}
  - {type: penetration, max: 0.0005, settle_s: 0.5}
camera: {target: [10, 0, 16], position: [22, -112, 27], fov: 30}
display:
  output: j_wheel
  labels: {j_wheel: Ratchet wheel A, j_td1: Front treadle D, j_td2: Back treadle D, j_arm1: Upper arm B, j_arm2: Lower arm B, j_pawl1: Upper pawl, j_pawl2: Lower pawl}
  brake: Extra load on A
  proof: {label: Pawls off the teeth, sub: "the pawls no longer touch A: the treadles and arms still rock, but nothing turns the wheel, which stops under its load"}
