# No. 241 (Brown 1868): "Intermittent circular motion is imparted to the wheel, A, by the continuous circular motion of the smaller wheel with one tooth."
#
# Model (cm, gravity on): the wheel A, 20 ratchet teeth (tips 6, roots 5), each face looking counter-clockwise, on a bearing with a little
# friction. The smaller wheel, below on the left, turns counter-clockwise at 30 rev/min (the one driven joint); its one tooth is a curved finger
# whose end (a pin) passes once a turn into A's teeth, reaching 0.45 past the roots, meets a face and carries it clockwise until it
# runs out past the tips. A click on a pivot at the upper left, held down by a light spring and its weight, rides over the slopes as A goes round
# and drops in front of the next face, so A cannot run back and stands still while the finger is away. So A goes round one tooth each turn of the
# smaller wheel. Generator: opencode-runs/batch11/gen241.py.
number: 241
slug: one-tooth-wheel
name: A wheel turned a tooth at a time by a wheel with one tooth
brown: "Intermittent circular motion is imparted to the wheel, A, by the continuous circular motion of the smaller wheel with one tooth."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 10
  floor: false
bodies:
  - id: wheel_a
    shape: part
    pos: [0, 0, 0]
    friction: 0.15
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 5.0, inner: 0.5, y: [-0.5, 0.5]}
      - {kind: poly, points: [[-0.9772, 4.5973], [-1.2475, 5.8689], [0.5226, 4.9726], [0.4913, 4.6743]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.35, 4.0703], [-3.0, 5.1962], [-1.0396, 4.8907], [-0.9772, 4.5973]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.4928, 3.1449], [-4.4589, 4.0148], [-2.5, 4.3301], [-2.35, 4.0703]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.2937, 1.9117], [-5.4813, 2.4404], [-3.7157, 3.3457], [-3.4928, 3.1449]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.6743, 0.4913], [-5.9671, 0.6272], [-4.5677, 2.0337], [-4.2937, 1.9117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.5973, -0.9772], [-5.8689, -1.2475], [-4.9726, 0.5226], [-4.6743, 0.4913]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.0703, -2.35], [-5.1962, -3.0], [-4.8907, -1.0396], [-4.5973, -0.9772]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.1449, -3.4928], [-4.0148, -4.4589], [-4.3301, -2.5], [-4.0703, -2.35]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.9117, -4.2937], [-2.4404, -5.4813], [-3.3457, -3.7157], [-3.1449, -3.4928]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.4913, -4.6743], [-0.6272, -5.9671], [-2.0337, -4.5677], [-1.9117, -4.2937]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.9772, -4.5973], [1.2475, -5.8689], [-0.5226, -4.9726], [-0.4913, -4.6743]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.35, -4.0703], [3.0, -5.1962], [1.0396, -4.8907], [0.9772, -4.5973]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.4928, -3.1449], [4.4589, -4.0148], [2.5, -4.3301], [2.35, -4.0703]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.2937, -1.9117], [5.4813, -2.4404], [3.7157, -3.3457], [3.4928, -3.1449]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.6743, -0.4913], [5.9671, -0.6272], [4.5677, -2.0337], [4.2937, -1.9117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.5973, 0.9772], [5.8689, 1.2475], [4.9726, -0.5226], [4.6743, -0.4913]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.0703, 2.35], [5.1962, 3.0], [4.8907, 1.0396], [4.5973, 0.9772]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.1449, 3.4928], [4.0148, 4.4589], [4.3301, 2.5], [4.0703, 2.35]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.9117, 4.2937], [2.4404, 5.4813], [3.3457, 3.7157], [3.1449, 3.4928]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.4913, 4.6743], [0.6272, 5.9671], [2.0337, 4.5677], [1.9117, 4.2937]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.5, y: [-0.8, 0.8], color: "#cfc6b4"}
  - id: driver
    shape: part
    pos: [-7.1598, 0, -3.3387]
    friction: 0.15
    color: "#c9bfa6"
    pieces:
      - {kind: disc, center: [-7.1598, -3.3387], radius: 2.8, inner: 0.4, y: [0.6, 1.1]}
      - {kind: poly, points: [[-7.5046, -3.0494], [-6.8151, -3.6279], [-7.6813, -4.6602], [-8.3707, -4.0817]], y: [-1.0, -0.5]}
      - {kind: poly, points: [[-8.0269, -3.9709], [-8.0251, -4.7709], [-9.3793, -4.7741], [-9.3812, -3.9741]], y: [-1.0, -0.5]}
      - {kind: disc, center: [-7.1598, -3.3387], radius: 0.8, inner: 0.4, y: [-1.0, 1.1], color: "#cfc6b4"}
      - {kind: rod, from: [-9.3803, -1.0, -4.3741], to: [-9.3803, 0.6, -4.3741], radius: 0.2, capsule: true, collide: 2, color: "#6b5a44"}   # the tooth's end
  - id: click
    shape: part
    pos: [-7.6744, 0, 4.1224]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-1.2139, 5.0563], [-1.4941, 6.2232], [-2.9948, 5.6561]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[-7.3806, 3.7178], [-7.9682, 4.5269], [-5.4842, 6.3306], [-4.8966, 5.5214]], y: [-1.0, -0.5]}
      - {kind: poly, points: [[-5.1515, 5.4777], [-5.2293, 6.3744], [-2.3718, 6.6222], [-2.294, 5.7256]], y: [-1.0, -0.5]}
      - {kind: disc, center: [-7.6744, 4.1224], radius: 0.9, inner: 0.3, y: [-1.0, -0.5]}
  - 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.5, color: "#8f8a80"}   # A's arbor
      - {kind: rod, from: [-7.1598, -1.1, -3.3387], to: [-7.1598, 2.4, -3.3387], radius: 0.4, color: "#8f8a80"}   # the small wheel's arbor
      - {kind: rod, from: [-7.6744, -1.1, 4.1224], to: [-7.6744, 2.4, 4.1224], radius: 0.3, color: "#8f8a80"}   # the click's stud
      - {kind: poly, points: [[-12, -8], [8, -8], [8, 8.5], [-12, 8.5]], y: [1.2, 2.4], color: "#b9b09c"}   # the plate behind
joints:
  - {id: j_driver, type: hinge, body: driver, axis: [0, -1, 0], damping: 0.0005}   # the one driven joint; +: counter-clockwise as seen
  - {id: j_a, type: hinge, body: wheel_a, axis: [0, -1, 0], damping: 0.0005, frictionloss: 0.002}
  - {id: j_click, type: hinge, body: click, axis: [0, -1, 0], range: [0, 0.5], stiffness: 0.2, springref: -0.2, damping: 0.0002}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_driver, kind: velocity, rpm: 30, kv: 1, max_torque: 5}
checks:
  - {type: ratio, out: j_a, in: j_driver, expect: -0.0500, tol: 0.03, settle_s: 0.5, window_s: 8}   # one tooth of A (1/20 turn) each turn, the other way
  - {type: monotonic, joint: j_a, direction: -1, max_back: 0.16, settle_s: 0.5, window_s: 9.5}
  - {type: clicks, joint: j_click, lift: 0.04, min: 3, settle_s: 0.5, window_s: 9.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [-2.0, 0, 0.2], position: [-2.0, -80.0, 1.5], fov: 34}
display:
  output: j_a
  labels: {j_driver: "Wheel with one tooth (driver)", j_a: "Wheel A", j_click: "Click"}
  proof: {label: "Tooth out of contact", sub: "the small wheel turns, A stands"}

