# No. 225 (Brown 1868): "Intermittent circular motion of the ratchet-wheel from vibratory motion of the arm carrying a pawl."
#
# Model (cm): a 30-tooth ratchet-wheel (tips 8, roots 7) turns on a fixed centre against a little bearing friction. An arm on the same centre is rocked
# by hand +-0.344 rad at 0.5 Hz (the one driven joint). A pin on the arm, 10.2 from the centre, carries the pawl, which lies by its weight among the teeth at
# the top of the wheel. As the arm swings to the right the pawl pushes a tooth and the wheel turns 3 teeth clockwise; as it swings back the pawl rides over the
# teeth' backs and the wheel stands. Generator: opencode-runs/batch11/gen225.py.
number: 225
slug: arm-pawl-ratchet
name: A ratchet-wheel turned by a vibrating arm and pawl
brown: "Intermittent circular motion of the ratchet-wheel from vibratory motion of the arm carrying a pawl."
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: 7.0, 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: [[0.4073, 6.888], [-1.1984, 7.9097], [-1.0337, 6.8221]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.0337, 6.8221], [-2.8168, 7.4877], [-2.4295, 6.4581]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.4295, 6.4581], [-4.312, 6.7384], [-3.7191, 5.8119]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.7191, 5.8119], [-5.6188, 5.6947], [-4.8462, 4.9117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.8462, 4.9117], [-6.68, 4.402], [-5.7615, 3.7967]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.7615, 3.7967], [-7.4492, 2.917], [-6.425, 2.5159]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.425, 2.5159], [-7.8929, 1.3044], [-6.8077, 1.1251]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.8077, 1.1251], [-7.9917, -0.3651], [-6.8928, -0.3149]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.8928, -0.3149], [-7.7411, -2.0187], [-6.6767, -1.7411]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.6767, -1.7411], [-7.1523, -3.584], [-6.1688, -3.0912]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.1688, -3.0912], [-6.2508, -4.9927], [-5.3913, -4.3062]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.3913, -4.3062], [-5.0762, -6.1833], [-4.3782, -5.3331]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.3782, -5.3331], [-3.6797, -7.1035], [-3.1737, -6.1268]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.1737, -6.1268], [-2.1223, -7.7133], [-1.8305, -6.6528]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.8305, -6.6528], [-0.4723, -7.986], [-0.4073, -6.888]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.4073, -6.888], [1.1984, -7.9097], [1.0337, -6.8221]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.0337, -6.8221], [2.8168, -7.4877], [2.4295, -6.4581]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.4295, -6.4581], [4.312, -6.7384], [3.7191, -5.8119]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.7191, -5.8119], [5.6188, -5.6947], [4.8462, -4.9117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.8462, -4.9117], [6.68, -4.402], [5.7615, -3.7967]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.7615, -3.7967], [7.4492, -2.917], [6.425, -2.5159]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.425, -2.5159], [7.8929, -1.3044], [6.8077, -1.1251]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.8077, -1.1251], [7.9917, 0.3651], [6.8928, 0.3149]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.8928, 0.3149], [7.7411, 2.0187], [6.6767, 1.7411]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.6767, 1.7411], [7.1523, 3.584], [6.1688, 3.0912]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.1688, 3.0912], [6.2508, 4.9927], [5.3913, 4.3062]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.3913, 4.3062], [5.0762, 6.1833], [4.3782, 5.3331]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.3782, 5.3331], [3.6797, 7.1035], [3.1737, 6.1268]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.1737, 6.1268], [2.1223, 7.7133], [1.8305, 6.6528]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.8305, 6.6528], [0.4723, 7.986], [0.4073, 6.888]], y: [-0.5, 0.5], collide: 1}
  - id: arm
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[0.0955, 0.8851], [-0.8374, 0.3022], [-8.5954, 12.9063], [-7.8321, 13.3832]], y: [-1.6, -1.0]}   # the arm and its handle
      - {kind: disc, center: [0, 0], radius: 1.3, inner: 0.6, y: [-1.6, -0.8]}
      - {kind: disc, center: [-5.4052, 8.6501], radius: 0.65, y: [-1.6, -1.0]}
      - {kind: rod, from: [-5.4052, -1.0, 8.6501], to: [-5.4052, 0.6, 8.6501], radius: 0.18, color: "#8f8a80"}   # the pawl's pin
  - id: pawl
    shape: part
    pos: [-5.4052, 0, 8.6501]
    mount: arm
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: disc, center: [-5.4052, 8.6501], radius: 0.45, inner: 0.18, y: [-0.4, 0.4], collide: 0}
      - {kind: rod, from: [-5.4052, 0, 8.6501], to: [-1.9605, 0, 7.5498], radius: 0.3, collide: 0}
      - {kind: rod, from: [-1.9605, 0, 7.5498], to: [-1.2937, 0, 7.3368], radius: 0.15, capsule: true, collide: 2}   # its nose
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.8, 0], to: [0, 2.4, 0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.2, -11], [1.2, -11], [0.8, 0], [-0.8, 0]], y: [1.2, 2.4]}   # the standard
      - {kind: poly, points: [[-11, -12.2], [11, -12.2], [11, -11], [-11, -11]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_arm, type: hinge, body: arm, axis: [0, -1, 0], damping: 0.001}   # the one driven joint; +: counter-clockwise
  - {id: j_pawl, type: hinge, body: pawl, axis: [0, -1, 0], damping: 0.0002, range: [-0.6, 0.6]}
  - {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_arm, kind: velocity, rpm: 0, swing: {amplitude: 0.3442, hz: 0.5}, kv: 20, max_torque: 40}
checks:
  - {type: advance, joint: j_wheel, beat: j_arm, expect: -0.31416, tol: 0.06, settle_s: 1.5, window_s: 10}   # 3 teeth (3 x 2 pi / 30) clockwise each to-and-fro, half of it a beat
  - {type: monotonic, joint: j_wheel, direction: -1, max_back: 0.03, settle_s: 1, window_s: 10.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [-1.0, 0, 1.0], position: [-1.0, -70.0, 3.0], fov: 34}
display:
  output: j_wheel
  labels: {j_arm: "Arm (driver)", j_pawl: "Pawl", j_wheel: "Ratchet-wheel"}
  proof: {label: "Pawl out of contact", sub: "the arm vibrates but the wheel never moves"}

