# No. 236 (Brown 1868): "A nearly continuous circular motion is imparted to the ratchet-wheel on vibrating the lever, a, to which are attached the two pawls, b and c."
#
# Model (cm, gravity on): a ratchet-wheel of 20 teeth (tips 8, roots 6.9; radial backs) on a fixed centre against a little bearing friction. The lever a,
# on a centre at [3.5, 15.2] above the wheel, is rocked by hand +-0.3 rad at 0.5 Hz by its long handle (the one driven joint; a counterpoise beyond the centre
# balances the handle). Pawl b hangs from a pin left of the centre and lies by its weight against the teeth on the left; pawl c, pinned right of and
# below the centre, lies by its weight on the teeth on top. Lowering the handle, b pushes the teeth on the left down while c slides back over the teeth
# on top; raising it, c draws the teeth on top to the left while b slides back up. The wheel goes on counter-clockwise a tooth at each stroke, both ways.
# Generator: opencode-runs/batch11/gen236.py.
number: 236
slug: two-pawl-lever-ratchet
name: A ratchet-wheel turned both ways of a lever's stroke by two pawls
brown: "A nearly continuous circular motion is imparted to the ratchet-wheel on vibrating the lever, a, to which are attached the two pawls, b and c."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 12.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 6.9, inner: 0.6, y: [-0.5, 0.5]}
      - {kind: poly, points: [[6.591, 0.3454], [7.989, 0.4187], [6.2662, 2.0724]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.1616, 2.3652], [7.4686, 2.8669], [5.3191, 3.9073]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.1292, 4.1535], [6.2172, 5.0346], [3.8514, 5.3598]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.5946, 5.5352], [4.3571, 6.7094], [2.0066, 6.2876]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.7082, 6.3751], [2.0706, 7.7274], [-0.0346, 6.5999]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.3454, 6.591], [-0.4187, 7.989], [-2.0724, 6.2662]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.3652, 6.1616], [-2.8669, 7.4686], [-3.9073, 5.3191]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.1535, 5.1292], [-5.0346, 6.2172], [-5.3598, 3.8514]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.5352, 3.5946], [-6.7094, 4.3571], [-6.2876, 2.0066]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.3751, 1.7082], [-7.7274, 2.0706], [-6.5999, -0.0346]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.591, -0.3454], [-7.989, -0.4187], [-6.2662, -2.0724]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.1616, -2.3652], [-7.4686, -2.8669], [-5.3191, -3.9073]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.1292, -4.1535], [-6.2172, -5.0346], [-3.8514, -5.3598]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.5946, -5.5352], [-4.3571, -6.7094], [-2.0066, -6.2876]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.7082, -6.3751], [-2.0706, -7.7274], [0.0346, -6.5999]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.3454, -6.591], [0.4187, -7.989], [2.0724, -6.2662]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.3652, -6.1616], [2.8669, -7.4686], [3.9073, -5.3191]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.1535, -5.1292], [5.0346, -6.2172], [5.3598, -3.8514]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.5352, -3.5946], [6.7094, -4.3571], [6.2876, -2.0066]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.3751, -1.7082], [7.7274, -2.0706], [6.5999, 0.0346]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 2.0, inner: 0.6, y: [-0.9, 0.9], color: "#cfc6b4"}
  - id: lever_a
    shape: part
    pos: [3.5, 0, 15.2]
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[3.5, 14.6], [3.5, 15.8], [-12.0, 16.8], [-12.0, 16.2]], y: [-1.6, -1.0]}   # the lever a and its handle
      - {kind: poly, points: [[3.5672, 15.7459], [3.4328, 14.6541], [-3.0611, 15.5037], [-2.9389, 16.4963]], y: [-1.6, -1.0]}
      - {kind: poly, points: [[3.1462, 14.7789], [3.8538, 15.6211], [8.8216, 11.3829], [8.1784, 10.6171]], y: [-1.6, -1.0]}
      - {kind: poly, points: [[3.5742, 14.7055], [3.4258, 15.6945], [7.4258, 16.2945], [7.5742, 15.3055]], y: [-1.6, -1.0]}
      - {kind: disc, center: [7.5, 15.8], radius: 1.693, y: [-2.8, -1.0], color: "#8f8a80"}   # the counterpoise
      - {kind: disc, center: [3.5, 15.2], radius: 0.9, inner: 0.25, y: [-1.6, -1.0]}
      - {kind: rod, from: [-3.0, -1.6, 16.0], to: [-3.0, 0.0, 16.0], radius: 0.2, color: "#8f8a80"}   # b's pin
      - {kind: rod, from: [8.5, -1.6, 11.0], to: [8.5, 0.0, 11.0], radius: 0.2, color: "#8f8a80"}   # c's pin
  - id: pawl_b
    shape: part
    pos: [-3.0, 0, 16.0]
    mount: lever_a
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: poly, points: [[-3.4254, 16.1466], [-2.5746, 15.8534], [-6.8179, 3.6958], [-7.5742, 3.9565]], y: [-0.4, 0.4], collide: 2}   # the pawl b
      - {kind: disc, center: [-3.0, 16.0], radius: 0.6, inner: 0.2, y: [-0.4, 0.4]}
  - id: pawl_c
    shape: part
    pos: [8.5, 0, 11.0]
    mount: lever_a
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: poly, points: [[8.3707, 11.431], [8.6293, 10.569], [-1.3003, 7.643], [-1.5301, 8.4093]], y: [-0.4, 0.4], collide: 2}   # the pawl c
      - {kind: disc, center: [8.5, 11.0], radius: 0.6, inner: 0.2, y: [-0.4, 0.4]}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.9, 0], to: [0, 2.4, 0], radius: 0.6, color: "#8f8a80"}   # the wheel's shaft
      - {kind: poly, points: [[-1.6, -14.2], [1.6, -14.2], [1.0, 0], [-1.0, 0]], y: [1.2, 2.4]}   # its standard
      - {kind: poly, points: [[2.3, -14.2], [4.7, -14.2], [4.2, 15.2], [2.8, 15.2]], y: [2.4, 3.4]}   # the lever's standard, behind
      - {kind: rod, from: [3.5, -1.8, 15.2], to: [3.5, 3.4, 15.2], radius: 0.25, color: "#8f8a80"}
      - {kind: poly, points: [[-14, -15.4], [14, -15.4], [14, -14.2], [-14, -14.2]], y: [-3, 4], color: "#b9b09c"}
joints:
  - {id: j_a, type: hinge, body: lever_a, axis: [0, -1, 0], damping: 0.001}   # the one driven joint; +: counter-clockwise as seen (the handle goes down)
  - {id: j_b, type: hinge, body: pawl_b, axis: [0, -1, 0], damping: 0.0005, range: [-0.5, 0.6]}
  - {id: j_c, type: hinge, body: pawl_c, axis: [0, -1, 0], damping: 0.0005, range: [-0.6, 0.5]}
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.1}   # +: counter-clockwise
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_a, kind: velocity, rpm: 0, swing: {amplitude: 0.3, hz: 0.5}, kv: 20, max_torque: 60}
checks:
  - {type: advance, joint: j_wheel, beat: j_a, expect: 0.31416, tol: 0.06, settle_s: 2.5, window_s: 9}   # a tooth (2 pi / 20) counter-clockwise at each stroke of the lever, both ways
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.05, settle_s: 1, window_s: 10.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0.0, 0, 1.0], position: [0.0, -100.0, 4.0], fov: 34}
display:
  output: j_wheel
  labels: {j_a: "Lever a (driver)", j_wheel: "Ratchet-wheel", j_b: "Pawl b", j_c: "Pawl c"}
  proof: {label: "Pawls out of contact", sub: "the lever swings, the wheel stands"}

