# No. 235 (Brown 1868): "The oscillation of the tappet-arm produces an intermittent rotary motion of the ratchet-wheel. ..."
#
# Model (cm, gravity on): a ratchet-wheel of 6 teeth (tips 6, roots 3.4) on a fixed centre, held from running back by a click above it that lies
# by its weight on a rest. The tappet-arm, pivoted on the right at [19.0, -6.0], is rocked by hand +-0.43 rad at 0.5 Hz (the one driven joint). Near its
# end it carries the tappet on a pin; a small spring (a joint spring) holds the tappet down against a stop on the arm. As the arm rises the tappet's
# end lifts a tooth by its back and turns the wheel a tooth counter-clockwise; as it falls the next tooth's slope pushes the tappet up against the
# spring and it passes. One tooth to each to-and-fro. Generator: opencode-runs/batch11/gen235.py.
number: 235
slug: tappet-arm-ratchet-wheel
name: A ratchet-wheel turned by a tappet-arm
brown: "The oscillation of the tappet-arm produces an intermittent rotary motion of the ratchet-wheel. The small spring at the bottom of the tappet-arm keeps the tappet in the position shown in the drawing as the arm rises, yet allows it to pass the teeth on the return motion."
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: 3.4, inner: 0.5, y: [-0.5, 0.5]}
      - {kind: poly, points: [[0.6127, 3.0389], [1.1858, 5.8817], [-1.9761, 2.3885]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.3254, 2.05], [-4.5008, 3.9678], [-3.0566, -0.5171]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9381, -0.9888], [-5.6866, -1.9139], [-1.0805, -2.9056]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.6127, -3.0389], [-1.1858, -5.8817], [1.9761, -2.3885]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.3254, -2.05], [4.5008, -3.9678], [3.0566, 0.5171]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9381, 0.9888], [5.6866, 1.9139], [1.0805, 2.9056]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 1.2, inner: 0.5, y: [-0.8, 0.8], color: "#cfc6b4"}
  - id: click
    shape: part
    pos: [9.0, 0, 7.5]
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: poly, points: [[1.0659, 4.4748], [9.0, 7.0], [9.0, 8.0], [1.5757, 6.6149]], y: [-0.4, 0.4], collide: 2}   # the click
      - {kind: disc, center: [9.0, 7.5], radius: 0.8, inner: 0.2, y: [-0.4, 0.4]}
  - id: arm
    shape: part
    pos: [19.0, 0, -6.0]
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[19.6, -6.6], [19.6, -5.4], [5.454, -6.6963], [5.454, -7.8963]], y: [-1.6, -1.0]}   # the tappet-arm
      - {kind: disc, center: [19.0, -6.0], radius: 1.0, inner: 0.25, y: [-1.6, -1.0]}
      - {kind: poly, points: [[19.0, -6.5], [24.0, -6.5], [24.0, -5.5], [19.0, -5.5]], y: [-1.6, -1.0]}   # its tail
      - {kind: disc, center: [24.0, -6.0], radius: 2.6, y: [-2.2, -1.0], color: "#8f8a80"}   # the counterpoise
      - {kind: rod, from: [6.254, -1.6, -7.2963], to: [6.254, 0.0, -7.2963], radius: 0.2, color: "#8f8a80"}   # the tappet's pin
  - id: tappet
    shape: part
    pos: [6.254, 0, -7.2963]
    mount: arm
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: poly, points: [[6.5956, -7.0034], [5.9123, -7.5891], [2.7343, -3.7278], [3.2657, -3.2722]], y: [-0.4, 0.4], collide: 2}   # the tappet
      - {kind: disc, center: [6.254, -7.2963], 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.8, 0], to: [0, 2.4, 0], radius: 0.5, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.4, -16.2], [1.4, -16.2], [0.9, 0], [-0.9, 0]], y: [1.2, 2.4]}   # the standard
      - {kind: poly, points: [[8.4, 7.5], [9.6, 7.5], [0.9, 0.9], [0.9, -0.9]], y: [1.2, 2.4]}   # the click's bracket
      - {kind: rod, from: [9.0, -0.6, 7.5], to: [9.0, 2.4, 7.5], radius: 0.2, color: "#8f8a80"}
      - {kind: poly, points: [[18.1, -16.2], [19.9, -16.2], [19.6, -6.0], [18.4, -6.0]], y: [-0.6, 0.4]}   # the arm's post
      - {kind: rod, from: [19.0, -1.8, -6.0], to: [19.0, 0.4, -6.0], radius: 0.25, color: "#8f8a80"}
      - {kind: poly, points: [[-9, -17.4], [27.0, -17.4], [27.0, -16.2], [-9, -16.2]], 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 as seen (the tappet end rises)
  - {id: j_tap, type: hinge, body: tappet, axis: [0, -1, 0], damping: 0.0005, range: [-0.9, 0], stiffness: 0.2, springref: 0.3}   # 0: down on its stop; -: lifted against the spring
  - {id: j_click, type: hinge, body: click, axis: [0, -1, 0], damping: 0.0005, range: [-0.6, 0], stiffness: 0.5, springref: 0.3}   # 0: on its rest; -: lifted (against a spring)
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.05}   # +: 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.43, hz: 0.5}, kv: 20, max_torque: 30}
checks:
  - {type: advance, joint: j_wheel, beat: j_arm, expect: 0.52360, tol: 0.06, settle_s: 2.5, window_s: 9}   # one tooth (2 pi / 6) counter-clockwise each to-and-fro, half of it a beat
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.25, settle_s: 1, window_s: 10.5}
  - {type: clicks, joint: j_tap, lift: 0.1, min: 4, settle_s: 1.0, window_s: 10}   # the tappet folds past a tooth each return
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [5.0, 0, -4.0], position: [5.0, -80.0, 3.0], fov: 34}
display:
  output: j_wheel
  labels: {j_arm: "Tappet-arm (driver)", j_wheel: "Ratchet-wheel", j_tap: "Tappet"}
  proof: {label: "Tappet out of contact", sub: "the arm swings, the wheel stands"}

