# No. 76 (Brown 1868): "Another contrivance for registering or counting revolutions. A tappet, B, supported
# on the fixed pivot, C, is struck at every revolution of the large wheel (partly represented) by a stud,
# D, attached to the said wheel. This causes the end of the tappet next the ratchet-wheel, A, to be lifted,
# and to turn the wheel the distance of one tooth. The tappet returns by its own weight to its original
# position after the stud, D, has passed, the end being jointed to permit it to pass the teeth of the
# ratchet-wheel."
#
# Model (cm): the large wheel (the one driven joint, clockwise, 12 rpm) carries the stud D at radius 9.0.
# The tappet B rests by its heavier right end on its stop (the joint's range). D comes down on B's left
# arm and lifts the right end about 1.4 pitches of A (16 teeth); B's jointed finger, hanging on its stop,
# pushes a tooth's face up. When D slips off the arm's end B falls back by its weight; the finger folds
# against its own weight to ride back over the next tooth and drops behind its face. A's bearing friction
# holds it meanwhile. Generator: opencode-runs/batch8/gen076.py.
number: 76
slug: revolution-counter-tappet
name: Registering revolutions by a tappet and ratchet
brown: "Is another contrivance for registering or counting revolutions. A tappet, B, supported on the fixed pivot, C, is struck at every revolution of the large wheel (partly represented) by a stud, D, attached to the said wheel. This causes the end of the tappet next the ratchet-wheel, A, to be lifted, and to turn the wheel the distance of one tooth. The tappet returns by its own weight to its original position after the stud, D, has passed, the end being jointed to permit it to pass the teeth of the ratchet-wheel."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 24
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: band, center: [0, 0], r: [9.6, 10.6], a: [-1.2, 1.2], y: [1.8, 2.6]}   # the large wheel, partly drawn
      - {kind: rod, from: [0, 2.2, 0], to: [9.6, 2.2, 0], radius: 0.4}
      - {kind: rod, from: [0, 2.2, 0], to: [5.9675, 2.2, 7.5199], radius: 0.4}
      - {kind: rod, from: [0, 2.2, 0], to: [5.9675, 2.2, -7.5199], radius: 0.4}
      - {kind: disc, center: [0, 0], radius: 1.4, y: [-0.6, 2.6]}
      - {kind: rod, from: [-0.2628, -0.6, 8.9962], to: [-0.2628, 0.5, 8.9962], radius: 0.35, capsule: true, collide: 1}   # the stud D
  - id: tappet
    shape: part
    pos: [12.0, 0, 0.0]
    friction: 0.1
    color: "#a39d90"
    pieces:
      - {kind: poly, points: [[9.0, -0.25], [16.55, -0.25], [16.55, 0.25], [9.0, 0.25]], y: [-0.5, 0.4], collide: 2}
      - {kind: disc, center: [12.0, 0.0], radius: 0.5, y: [-0.5, 0.4]}
      - {kind: disc, center: [15.65, 0], radius: 0.7, y: [-0.5, 0.4], color: "#8f8a80", density: 7800}   # its weight, the heavier end
  - id: finger
    shape: part
    pos: [16.55, 0, 0.462]
    mount: tappet
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [16.55, 1.1, 0.462], to: [15.0, 1.1, 1.0], radius: 0.13, capsule: true, collide: 2}
      - {kind: rod, from: [16.55, 0.3, 0.462], to: [16.55, 1.3, 0.462], radius: 0.15, color: "#8f8a80"}   # its joint pin
  - id: ratchet_a
    shape: part
    pos: [12.3911, 0, 0.1304]
    friction: 0.1
    color: "#e2d8bf"
    pieces:
      - {kind: disc, center: [12.3911, 0.1304], radius: 2.0, y: [0.7, 1.5]}
      - {kind: poly, points: [[14.1344, 0.886], [15.1437, 1.3235], [13.7125, 1.4956]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[13.7125, 1.4956], [14.4775, 2.286], [13.0895, 1.8974]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[13.0895, 1.8974], [13.4938, 2.9204], [12.3601, 2.0301]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[12.3601, 2.0301], [12.3422, 3.13], [11.6355, 1.8736]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[11.6355, 1.8736], [11.198, 2.8829], [11.0259, 1.4518]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[11.0259, 1.4518], [10.2355, 2.2168], [10.6241, 0.8287]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[10.6241, 0.8287], [9.6011, 1.233], [10.4914, 0.0994]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[10.4914, 0.0994], [9.3915, 0.0814], [10.6478, -0.6253]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[10.6478, -0.6253], [9.6386, -1.0627], [11.0697, -1.2349]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[11.0697, -1.2349], [10.3047, -2.0253], [11.6928, -1.6366]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[11.6928, -1.6366], [11.2884, -2.6596], [12.4221, -1.7694]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[12.4221, -1.7694], [12.4401, -2.8692], [13.1468, -1.6129]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[13.1468, -1.6129], [13.5842, -2.6222], [13.7564, -1.191]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[13.7564, -1.191], [14.5468, -1.9561], [14.1581, -0.568]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[14.1581, -0.568], [15.1811, -0.9723], [14.2909, 0.1614]], y: [0.7, 1.5], collide: 1}
      - {kind: poly, points: [[14.2909, 0.1614], [15.3907, 0.1793], [14.1344, 0.886]], y: [0.7, 1.5], collide: 1}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [12.0, -1.4, 0.0], to: [12.0, -0.5, 0.0], radius: 0.3, color: "#8f8a80"}   # C, in front
      - {kind: poly, points: [[11.4, -9], [12.6, -9], [12.4, 0], [11.6, 0]], y: [-1.6, -1.0]}
      - {kind: rod, from: [12.3911, 1.5, 0.1304], to: [12.3911, 2.4, 0.1304], radius: 0.3, color: "#8f8a80"}   # A's arbor, behind
      - {kind: poly, points: [[11.7911, -9], [12.9911, -9], [12.7911, 0.1304], [11.9911, 0.1304]], y: [1.8, 2.4]}
      - {kind: poly, points: [[2, -10], [18.55, -10], [18.55, -9], [2, -9]], y: [-2, 3], color: "#b9b09c"}
joints:
  - {id: j_w, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.0002}   # + : clockwise, as drawn
  - {id: j_t, type: hinge, body: tappet, axis: [0, -1, 0], range: [0, 0.8], damping: 0.002}   # + lifts the right end; rests on 0 by its weight
  - {id: j_f, type: hinge, body: finger, axis: [0, -1, 0], range: [-1.2, 0], damping: 0.0002}   # the joint: folds away from A (-), held on its stop (0) by its weight
  - {id: j_a, type: hinge, body: ratchet_a, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.003}   # + : against the clock
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_w, kind: velocity, rpm: 12, kv: 10, max_torque: 20}
checks:
  - {type: ratio, out: j_a, in: j_w, expect: 0.0625, tol: 0.001, settle_s: 4.0, window_s: 15.0}   # one tooth a revolution
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [10, 0, -1.5], position: [10, -42, 2], fov: 34}
display:
  output: j_a
  labels: {j_w: "Large wheel with the stud D (driver)", j_t: "Tappet B", j_f: "Its jointed end", j_a: "Ratchet-wheel A"}
  proof: {label: "Finger out of contact", sub: "the tappet is struck and lifted, but A never turns"}

