# No. 206 (Brown 1868): "A continuous circular movement of the ratchet-wheel, produced by the vibration of the lever carrying two pawls, one of which engages the ratchet-teeth in rising and the other in falling."
#
# Model (cm): a 40-tooth ratchet-wheel (tips 8, roots 7.3) turns on a fixed centre against a little bearing friction. Above it a lever on a fulcrum
# to the upper right (6.5, 12.6) is rocked by hand, +-0.3 rad at 0.5 Hz (the one driven joint); at its left end, 6.63 from the fulcrum, a pin
# carries the double pawl, which straddles the top of the wheel as in the plate and hooks in among the teeth on both sides (150 and
# 65 deg round). The pawl is made as two arms on the one pin, so each hook can fall by its weight into the teeth and ride over them. As the
# lever rises the left hook lifts the teeth on the left side while the right one slides up over the backs of its teeth; as it falls the right hook presses the
# right side down while the left slides back. The wheel goes the same way (clockwise) on both strokes, three teeth for each rise and fall of the lever. Generator: opencode-runs/batch11/gen206.py.
number: 206
slug: lever-double-pawl
name: A ratchet-wheel turned by a lever with a double pawl
brown: "A continuous circular movement of the ratchet-wheel, produced by the vibration of the lever carrying two pawls, one of which engages the ratchet-teeth in rising and the other in falling."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 13.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 7.3, inner: 0.6, y: [-0.5, 0.5]}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.6, y: [-0.8, 0.8], color: "#cfc6b4"}
      - {kind: poly, points: [[-5.488, 4.6607], [-6.8328, 4.1609], [-6.1495, 3.7448]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.1495, 3.7448], [-7.3996, 3.0407], [-6.6596, 2.7367]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.6596, 2.7367], [-7.7842, 1.8457], [-7.0057, 1.6612]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-7.0057, 1.6612], [-7.9771, 0.6053], [-7.1794, 0.5448]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-7.1794, 0.5448], [-7.9735, -0.65], [-7.1762, -0.585]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-7.1762, -0.585], [-7.7737, -1.8894], [-6.9963, -1.7004]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.9963, -1.7004], [-7.3824, -3.0822], [-6.6442, -2.774]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.6442, -2.774], [-6.8094, -4.1991], [-6.1284, -3.7792]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.1284, -3.7792], [-6.0687, -5.2126], [-5.4618, -4.6914]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.4618, -4.6914], [-5.1785, -6.0978], [-4.6607, -5.488]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.6607, -5.488], [-4.1609, -6.8328], [-3.7448, -6.1495]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.7448, -6.1495], [-3.0407, -7.3996], [-2.7367, -6.6596]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.7367, -6.6596], [-1.8457, -7.7842], [-1.6612, -7.0057]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.6612, -7.0057], [-0.6053, -7.9771], [-0.5448, -7.1794]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.5448, -7.1794], [0.65, -7.9735], [0.585, -7.1762]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.585, -7.1762], [1.8894, -7.7737], [1.7004, -6.9963]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.7004, -6.9963], [3.0822, -7.3824], [2.774, -6.6442]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.774, -6.6442], [4.1991, -6.8094], [3.7792, -6.1284]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.7792, -6.1284], [5.2126, -6.0687], [4.6914, -5.4618]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.6914, -5.4618], [6.0978, -5.1785], [5.488, -4.6607]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.488, -4.6607], [6.8328, -4.1609], [6.1495, -3.7448]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.1495, -3.7448], [7.3996, -3.0407], [6.6596, -2.7367]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.6596, -2.7367], [7.7842, -1.8457], [7.0057, -1.6612]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[7.0057, -1.6612], [7.9771, -0.6053], [7.1794, -0.5448]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[7.1794, -0.5448], [7.9735, 0.65], [7.1762, 0.585]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[7.1762, 0.585], [7.7737, 1.8894], [6.9963, 1.7004]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.9963, 1.7004], [7.3824, 3.0822], [6.6442, 2.774]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.6442, 2.774], [6.8094, 4.1991], [6.1284, 3.7792]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.1284, 3.7792], [6.0687, 5.2126], [5.4618, 4.6914]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.4618, 4.6914], [5.1785, 6.0978], [4.6607, 5.488]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.6607, 5.488], [4.1609, 6.8328], [3.7448, 6.1495]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.7448, 6.1495], [3.0407, 7.3996], [2.7367, 6.6596]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.7367, 6.6596], [1.8457, 7.7842], [1.6612, 7.0057]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.6612, 7.0057], [0.6053, 7.9771], [0.5448, 7.1794]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.5448, 7.1794], [-0.65, 7.9735], [-0.585, 7.1762]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.585, 7.1762], [-1.8894, 7.7737], [-1.7004, 6.9963]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.7004, 6.9963], [-3.0822, 7.3824], [-2.774, 6.6442]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.774, 6.6442], [-4.1991, 6.8094], [-3.7792, 6.1284]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.7792, 6.1284], [-5.2126, 6.0687], [-4.6914, 5.4618]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.6914, 5.4618], [-6.0978, 5.1785], [-5.488, 4.6607]], y: [-0.5, 0.5], collide: 1}
  - id: lever
    shape: part
    pos: [6.5, 0, 12.6]
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[0.0, 10.9], [6.5, 12.1], [13.5, 14.2], [13.5, 14.9], [6.5, 13.1], [0.0, 11.7]], y: [-1.6, -1.0]}   # the lever and its handle
      - {kind: disc, center: [6.5, 12.6], radius: 0.9, inner: 0.4, y: [-1.6, -1.0]}
      - {kind: disc, center: [0.0, 11.3], radius: 0.7, y: [-1.6, -1.0]}
      - {kind: rod, from: [0.0, -1.0, 11.3], to: [0.0, 0.6, 11.3], radius: 0.18, color: "#8f8a80"}   # the pin Q
  - id: hook_l
    shape: part
    pos: [0.0, 0, 11.3]
    mount: lever
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [0.0, 0, 11.3], to: [-4.0218, 0, 9.2909], radius: 0.22, collide: 0}
      - {kind: rod, from: [-4.0218, 0, 9.2909], to: [-6.7079, 0, 6.2963], radius: 0.22, collide: 0}
      - {kind: rod, from: [-6.7079, 0, 6.2963], to: [-8.4608, 0, 3.6131], radius: 0.22, collide: 0}
      - {kind: rod, from: [-8.4608, 0, 3.6131], to: [-7.3624, 0, 3.7583], radius: 0.22, collide: 0}
      - {kind: rod, from: [-7.3624, 0, 3.7583], to: [-6.6684, 0, 3.85], radius: 0.15, capsule: true, collide: 2}   # the hook
  - id: hook_r
    shape: part
    pos: [0.0, 0, 11.3]
    mount: lever
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [0.0, 0, 11.3], to: [1.9589, 0, 9.9327], radius: 0.22, collide: 0}
      - {kind: rod, from: [1.9589, 0, 9.9327], to: [3.4929, 0, 8.5111], radius: 0.22, collide: 0}
      - {kind: rod, from: [3.4929, 0, 8.5111], to: [4.8583, 0, 7.8126], radius: 0.22, collide: 0}
      - {kind: rod, from: [4.8583, 0, 7.8126], to: [3.8753, 0, 7.3015], radius: 0.22, collide: 0}
      - {kind: rod, from: [3.8753, 0, 7.3015], to: [3.2542, 0, 6.9786], radius: 0.15, capsule: true, collide: 2}   # the hook
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.6, 0], to: [0, 2.4, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: rod, from: [6.5, 2.4, 12.6], to: [6.5, -1.0, 12.6], radius: 0.4, color: "#8f8a80"}   # the fulcrum
      - {kind: poly, points: [[-1.2, -11], [1.2, -11], [0.8, 0], [-0.8, 0]], y: [1.2, 2.4]}   # the wheel's standard
      - {kind: poly, points: [[6.1, -11], [6.9, -11], [6.9, 12.6], [6.1, 12.6]], y: [1.8, 2.4]}   # the fulcrum's standard
      - {kind: poly, points: [[-11, -12.2], [10.5, -12.2], [10.5, -11], [-11, -11]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_lever, type: hinge, body: lever, axis: [0, -1, 0], damping: 0.001}   # the one driven joint; +: counter-clockwise (Q falls)
  - {id: j_hl, type: hinge, body: hook_l, axis: [0, -1, 0], damping: 0.0002, range: [-0.9, 0.9]}
  - {id: j_hr, type: hinge, body: hook_r, axis: [0, -1, 0], damping: 0.0002, range: [-0.9, 0.9]}
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.01}   # +: counter-clockwise
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_lever, kind: velocity, rpm: 0, swing: {amplitude: 0.3, hz: 0.5}, kv: 20, max_torque: 40}
checks:
  - {type: advance, joint: j_wheel, beat: j_lever, expect: -0.23562, tol: 0.06, settle_s: 1.5, window_s: 11}   # three teeth (3 x 2 pi / 40) clockwise each rise-and-fall
  - {type: monotonic, joint: j_wheel, direction: -1, max_back: 0.03, settle_s: 1, window_s: 11.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [2, 0, 1], position: [2, -70, 3], fov: 34}
display:
  output: j_wheel
  labels: {j_lever: "Lever (driver)", j_hl: "Left hook", j_hr: "Right hook", j_wheel: "Ratchet-wheel"}
  proof: {label: "Hooks out of contact", sub: "the lever vibrates but the wheel never moves"}

