# No. 121 (Brown 1868): "Alternating rectilinear motion of the rod attached to the disk-wheel produces an intermittent rotary motion of the cog-wheel by means of the click attached to the disk-wheel. This motion, which is reversible by throwing over the click, is used for the feed of planing machines and other tools."
#
# Model (cm): the ratchet (cog) wheel A, 24 teeth, turns on a fixed shaft. The disk-wheel D turns loose on the same shaft; the rod C, slid up and down 1.6 cm either way by hand (the one driven joint, a swinging slide),
# carries a pin that works in a slot at D's rim (8.5 cm out), so D rocks about 11 degrees each way. The click B is pinned to D and sprung onto A's teeth: as D turns up it pushes a tooth
# round; as D turns back the click rides over the next tooth and drops behind it, and A's bearing friction holds it. So A goes a tooth every double stroke. (Throwing the click over, to feed the other way, is the mirror
# arrangement: not modelled.) Generator: opencode-runs/batch9/gen121.py.
number: 121
slug: disk-wheel-click-feed
name: A rod rocking a disk-wheel whose click feeds a ratchet
brown: "Alternating rectilinear motion of the rod attached to the disk-wheel produces an intermittent rotary motion of the cog-wheel by means of the click attached to the disk-wheel. This motion, which is reversible by throwing over the click, is used for the feed of planing machines and other tools."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 13
  floor: false
bodies:
  - id: wheel_a
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 4.3, inner: 0.6, y: [-0.5, 0.5]}
      - {kind: poly, points: [[4.2, 0.0], [5.0, 0.0], [4.0569, 1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.0569, 1.087], [4.8296, 1.2941], [3.6373, 2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.6373, 2.1], [4.3301, 2.5], [2.9698, 2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9698, 2.9698], [3.5355, 3.5355], [2.1, 3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.1, 3.6373], [2.5, 4.3301], [1.087, 4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.087, 4.0569], [1.2941, 4.8296], [0.0, 4.2]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.0, 4.2], [0.0, 5.0], [-1.087, 4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.087, 4.0569], [-1.2941, 4.8296], [-2.1, 3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.1, 3.6373], [-2.5, 4.3301], [-2.9698, 2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9698, 2.9698], [-3.5355, 3.5355], [-3.6373, 2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6373, 2.1], [-4.3301, 2.5], [-4.0569, 1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.0569, 1.087], [-4.8296, 1.2941], [-4.2, 0.0]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.2, 0.0], [-5.0, 0.0], [-4.0569, -1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.0569, -1.087], [-4.8296, -1.2941], [-3.6373, -2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6373, -2.1], [-4.3301, -2.5], [-2.9698, -2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9698, -2.9698], [-3.5355, -3.5355], [-2.1, -3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.1, -3.6373], [-2.5, -4.3301], [-1.087, -4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.087, -4.0569], [-1.2941, -4.8296], [-0.0, -4.2]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.0, -4.2], [-0.0, -5.0], [1.087, -4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.087, -4.0569], [1.2941, -4.8296], [2.1, -3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.1, -3.6373], [2.5, -4.3301], [2.9698, -2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9698, -2.9698], [3.5355, -3.5355], [3.6373, -2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.6373, -2.1], [4.3301, -2.5], [4.0569, -1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.0569, -1.087], [4.8296, -1.2941], [4.2, -0.0]], y: [-0.5, 0.5], collide: 1}
  - id: disk_d
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [0, 0], radius: 7.6, inner: 0.6, y: [0.6, 1.2]}   # the disk-wheel, behind A
      - {kind: poly, points: [[6.0, -1.2], [8.0, -1.2], [8.0, 1.2], [6.0, 1.2]], y: [0.6, 1.2]}   # the lug with the slot
      - {kind: poly, points: [[7.3, -0.67], [10.1, -0.67], [10.1, -0.27], [7.3, -0.27]], y: [-0.5, 1.2], collide: 2}   # the slot's lower cheek
      - {kind: poly, points: [[7.3, 0.27], [10.1, 0.27], [10.1, 0.67], [7.3, 0.67]], y: [-0.5, 1.2], collide: 2}   # and upper
      - {kind: rod, from: [-0.2304, -0.5, 6.596], to: [-0.2304, 1.2, 6.596], radius: 0.2, color: "#8f8a80"}   # B's pin
  - id: click_b
    shape: part
    pos: [-0.2304, 0, 6.596]
    mount: disk_d
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [-0.2304, 0, 6.596], to: [-1.7794, 0, 4.4041], radius: 0.15, capsule: true, collide: 2}
  - id: rod_c
    shape: part
    pos: [8.5, 0, 0]
    friction: 0.1
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [8.5, -0.6, 0], to: [8.5, 0.5, 0], radius: 0.25, capsule: true, collide: 1}   # the pin in D's slot
      - {kind: rod, from: [8.5, -0.9, 0], to: [8.5, -0.6, 0], radius: 0.3}
      - {kind: rod, from: [8.5, -0.9, -0.4], to: [8.5, -0.9, 12.0], radius: 0.3}   # the rod
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.8, 0], to: [0, 2.2, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: poly, points: [[-1, -8.6], [1, -8.6], [0.8, 0], [-0.8, 0]], y: [1.4, 2.2]}   # the standard of the shaft
      - {kind: poly, points: [[7.8, 9.0], [9.2, 9.0], [9.2, 9.8], [7.8, 9.8]], y: [-1.5, -0.3]}   # C's guide
joints:
  - {id: j_c, type: slide, body: rod_c, axis: [0, 0, 1], damping: 0.05}   # the rod (the one driven joint); + : up
  - {id: j_d, type: hinge, body: disk_d, axis: [0, -1, 0], damping: 0.0005}   # + : up at its rim, against the clock
  - {id: j_bp, type: hinge, body: click_b, axis: [0, -1, 0], damping: 0.0002, range: [-0.6, 0.3], stiffness: 0.01, springref: 0.25}   # sprung onto the teeth
  - {id: j_a, type: hinge, body: wheel_a, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.01}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_c, kind: velocity, rpm: 0, swing: {amplitude: 0.016, hz: 0.5}, kv: 60000, max_torque: 600}
checks:
  - {type: advance, joint: j_a, beat: j_c, expect: 0.1309, tol: 0.003, settle_s: 2.9, window_s: 8.2}   # a tooth a double stroke: half a pitch a beat
  - {type: follow, out: j_d, in: j_c, expect: 11.7647, tol: 0.5882, min_r2: 0.98, settle_s: 0.3, window_s: 11}   # the disk-wheel rocks as the rod's pin / radius
  - {type: clicks, joint: j_bp, lift: 0.08, min: 4, settle_s: 1.0, window_s: 10.0}   # the click rides over a tooth every return
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [1.5, 0, 2], position: [1.5, -56.0, 2], fov: 34}
display:
  output: j_a
  labels: {j_c: "Rod C (driver)", j_d: "Disk-wheel D", j_bp: "Click B", j_a: "Cog-wheel A"}
  proof: {label: "Click out of contact", sub: "the rod works the disk but A never moves"}

