# No. 222 (Brown 1868): "If for the eccentric wheel described in the last figure an ordinary spur-gear moving on an eccentric center of motion be substituted, a simple link
# connecting the center of the wheel with that of the pinion with which it gears will maintain proper pitching of teeth in a more simple manner than the groove."
#
# Model (cm; drawing plane x-z, the shafts along y): C, a spur-gear of 24 teeth (module 0.6, pitch radius 7.2), turns on a centre D 2 from its own centre. The pinion B
# (10 teeth) gears with C and with the wheel A (12 teeth), and turns on an arm (6.6) that swings on A's centre, as in No. 221. The link (10.2) turns on C's centre and is pinned
# to the arm at B's centre, so B stays at C's pitching while the arm swings 38.7 degrees. A turns 24/12 = 2 times C on the mean, and
# 0.954 to 2.945 times as fast (kinematics: B rolling on C's and A's pitch circles). Straight-flanked teeth. Gravity is on. Only C is driven (6 rpm).
# Generator: opencode-runs/batch11/gen222.py.
number: 222
slug: eccentric-spur-gear-link
name: A spur-gear on an eccentric centre, its pinion kept in pitch by a link
brown: "If for the eccentric wheel described in the last figure an ordinary spur-gear moving on an eccentric center of motion be substituted, a simple link connecting the center of the wheel with that of the pinion with which it gears will maintain proper pitching of teeth in a more simple manner than the groove."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 13.0
bodies:
  - id: gearC
    shape: part
    pos: [0, 0, 0]
    density: 2700
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[-0.5954, -4.6], [0.5954, -4.6], [0.2241, -5.62], [-0.2241, -5.62]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[1.1331, -4.5292], [2.2833, -4.221], [2.1887, -5.3023], [1.7557, -5.4184]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[2.7844, -4.0135], [3.8156, -3.4181], [4.0041, -4.4871], [3.6159, -4.7112]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[4.2459, -3.0879], [5.0879, -2.2459], [5.5466, -3.2297], [5.2297, -3.5466]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[5.4181, -1.8156], [6.0135, -0.7844], [6.7112, -1.6159], [6.4871, -2.0041]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[6.221, -0.2833], [6.5292, 0.8669], [7.4184, 0.2443], [7.3023, -0.1887]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[6.6, 1.4046], [6.6, 2.5954], [7.62, 2.2241], [7.62, 1.7759]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[6.5292, 3.1331], [6.221, 4.2833], [7.3023, 4.1887], [7.4184, 3.7557]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[6.0135, 4.7844], [5.4181, 5.8156], [6.4871, 6.0041], [6.7112, 5.6159]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[5.0879, 6.2459], [4.2459, 7.0879], [5.2297, 7.5466], [5.5466, 7.2297]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[3.8156, 7.4181], [2.7844, 8.0135], [3.6159, 8.7112], [4.0041, 8.4871]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[2.2833, 8.221], [1.1331, 8.5292], [1.7557, 9.4184], [2.1887, 9.3023]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[0.5954, 8.6], [-0.5954, 8.6], [-0.2241, 9.62], [0.2241, 9.62]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-1.1331, 8.5292], [-2.2833, 8.221], [-2.1887, 9.3023], [-1.7557, 9.4184]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-2.7844, 8.0135], [-3.8156, 7.4181], [-4.0041, 8.4871], [-3.6159, 8.7112]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-4.2459, 7.0879], [-5.0879, 6.2459], [-5.5466, 7.2297], [-5.2297, 7.5466]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-5.4181, 5.8156], [-6.0135, 4.7844], [-6.7112, 5.6159], [-6.4871, 6.0041]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-6.221, 4.2833], [-6.5292, 3.1331], [-7.4184, 3.7557], [-7.3023, 4.1887]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-6.6, 2.5954], [-6.6, 1.4046], [-7.62, 1.7759], [-7.62, 2.2241]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-6.5292, 0.8669], [-6.221, -0.2833], [-7.3023, -0.1887], [-7.4184, 0.2443]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-6.0135, -0.7844], [-5.4181, -1.8156], [-6.4871, -2.0041], [-6.7112, -1.6159]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-5.0879, -2.2459], [-4.2459, -3.0879], [-5.2297, -3.5466], [-5.5466, -3.2297]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-3.8156, -3.4181], [-2.7844, -4.0135], [-3.6159, -4.7112], [-4.0041, -4.4871]], y: [-0.4, 0.4], collide: 2}
      - {kind: poly, points: [[-2.2833, -4.221], [-1.1331, -4.5292], [-1.7557, -5.4184], [-2.1887, -5.3023]], y: [-0.4, 0.4], collide: 2}
      - {kind: disc, center: [0.0, 2.0], radius: 6.55, y: [-0.4, 0.4], collide: 0}
      - {kind: disc, center: [0.0, 2.0], radius: 0.8, y: [-1.7, -0.4], collide: 0, color: "#8f8a80"}   # the stud at C's centre, for the link
      - {kind: disc, center: [0.0, 0.0], radius: 1.1, y: [-1.0, 0.4], collide: 0, color: "#a39d90"}   # the boss on the eccentric centre D
      - {kind: disc, center: [0.0, 0.0], radius: 0.6, y: [0.4, 3.6], collide: 0, color: "#8f8a80"}   # C's shaft at D
  - id: link
    shape: part
    pos: [0.0, 0, 2.0]
    mount: gearC
    density: 2700
    friction: 0.1
    color: "#8f8573"
    pieces:
      - {kind: poly, points: [[-0.55, 2.0], [0.55, 2.0], [0.45, 12.2], [-0.45, 12.2]], y: [-2.4, -1.8], collide: 0}   # the link
      - {kind: disc, center: [0.0, 2.0], radius: 1.0, y: [-2.4, -1.8], collide: 0}
      - {kind: disc, center: [0.0, 12.2], radius: 0.7, y: [-2.4, -1.8], collide: 0}
  - id: arm
    shape: part
    pos: [6.6, 0, 12.2]
    density: 2700
    friction: 0.1
    color: "#a39a86"
    pieces:
      - {kind: poly, points: [[6.6, 11.55], [6.6, 12.85], [0.0, 12.7], [0.0, 11.7]], y: [-3.0, -2.4], collide: 0}   # the arm, in front of the link
      - {kind: disc, center: [6.6, 12.2], radius: 0.9, y: [-3.0, -2.4], collide: 0}
      - {kind: disc, center: [0.0, 12.2], radius: 0.7, y: [-3.0, -2.4], collide: 0}
      - {kind: disc, center: [0.0, 12.2], radius: 0.3, y: [-3.1, -1.4], collide: 0, color: "#6f6a60"}   # B's stud, the link's pin
  - id: pinionB
    shape: part
    pos: [0.0, 0, 12.2]
    mount: arm
    density: 2700
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[2.4, 11.6046], [2.4, 12.7954], [3.42, 12.4241], [3.42, 11.9759]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[2.2916, 13.129], [1.5917, 14.0924], [2.6351, 14.3915], [2.8986, 14.0289]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[1.3079, 14.2986], [0.1754, 14.6665], [0.8437, 15.5219], [1.27, 15.3834]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[-0.1754, 14.6665], [-1.3079, 14.2986], [-1.27, 15.3834], [-0.8437, 15.5219]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[-1.5917, 14.0924], [-2.2916, 13.129], [-2.8986, 14.0289], [-2.6351, 14.3915]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[-2.4, 12.7954], [-2.4, 11.6046], [-3.42, 11.9759], [-3.42, 12.4241]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[-2.2916, 11.271], [-1.5917, 10.3076], [-2.6351, 10.0085], [-2.8986, 10.3711]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[-1.3079, 10.1014], [-0.1754, 9.7335], [-0.8437, 8.8781], [-1.27, 9.0166]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[0.1754, 9.7335], [1.3079, 10.1014], [1.27, 9.0166], [0.8437, 8.8781]], y: [-1.4, 0.4], collide: 1}
      - {kind: poly, points: [[1.5917, 10.3076], [2.2916, 11.271], [2.8986, 10.3711], [2.6351, 10.0085]], y: [-1.4, 0.4], collide: 1}
      - {kind: disc, center: [0.0, 12.2], radius: 2.35, y: [-1.4, 0.4], collide: 0}
  - id: wheelA
    shape: part
    pos: [6.6, 0, 12.2]
    density: 2700
    friction: 0.1
    color: "#c9b88f"
    pieces:
      - {kind: poly, points: [[9.6519, 12.4014], [9.3437, 13.5515], [10.425, 13.4569], [10.541, 13.024]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[9.1423, 13.9003], [8.3003, 14.7423], [9.2841, 15.201], [9.601, 14.8841]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[7.9515, 14.9437], [6.8014, 15.2519], [7.424, 16.141], [7.8569, 16.025]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[6.3986, 15.2519], [5.2485, 14.9437], [5.3431, 16.025], [5.776, 16.141]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[4.8997, 14.7423], [4.0577, 13.9003], [3.599, 14.8841], [3.9159, 15.201]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[3.8563, 13.5515], [3.5481, 12.4014], [2.659, 13.024], [2.775, 13.4569]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[3.5481, 11.9986], [3.8563, 10.8485], [2.775, 10.9431], [2.659, 11.376]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[4.0577, 10.4997], [4.8997, 9.6577], [3.9159, 9.199], [3.599, 9.5159]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[5.2485, 9.4563], [6.3986, 9.1481], [5.776, 8.259], [5.3431, 8.375]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[6.8014, 9.1481], [7.9515, 9.4563], [7.8569, 8.375], [7.424, 8.259]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[8.3003, 9.6577], [9.1423, 10.4997], [9.601, 9.5159], [9.2841, 9.199]], y: [-1.4, -0.6], collide: 2}
      - {kind: poly, points: [[9.3437, 10.8485], [9.6519, 11.9986], [10.541, 11.376], [10.425, 10.9431]], y: [-1.4, -0.6], collide: 2}
      - {kind: disc, center: [6.6, 12.2], radius: 2.95, y: [-1.4, -0.6], collide: 0}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    density: 7800
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [6.6, 12.2], radius: 0.45, y: [-3.2, 3.6], collide: 0, color: "#8f8a80"}   # A's shaft
      - {kind: disc, center: [0.0, 0.0], radius: 1.2, y: [3.0, 3.6], collide: 0}
      - {kind: disc, center: [6.6, 12.2], radius: 1.2, y: [3.0, 3.6], collide: 0}
      - {kind: poly, points: [[-0.9, 0.0], [0.9, 0.0], [1.6, -11.0], [-1.6, -11.0]], y: [3.0, 3.6], collide: 0}   # the frame, behind
      - {kind: poly, points: [[-0.5277, 0.2855], [0.5277, -0.2855], [7.1277, 11.9145], [6.0723, 12.4855]], y: [3.0, 3.6], collide: 0}
joints:
  - {id: j_c, type: hinge, body: gearC, axis: [0, -1, 0], damping: 0.01}   # the one driven joint; +: counter-clockwise
  - {id: j_link, type: hinge, body: link, axis: [0, -1, 0], damping: 0.001}   # the link on C's centre
  - {id: j_arm, type: hinge, body: arm, axis: [0, -1, 0], damping: 0.002}
  - {id: j_b, type: hinge, body: pinionB, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_a, type: hinge, body: wheelA, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.002}
pins:
  - {id: pin_b, a: link, b: arm, at: [0.0, 0, 12.2]}   # the link's eye on B's stud
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_c, kind: velocity, rpm: 6, kv: 20, max_torque: 40}
checks:
  - {type: ratio, out: j_a, in: j_c, expect: 2, tol: 0.06, settle_s: 0.5, window_s: 10}   # 24/12 on the mean (one turn of C)
  - {type: ratio_range, out: j_a, in: j_c, min: 0.811, max: 3.299, min_swing: 0.995, settle_s: 0.5, window_s: 12, slices: 48}   # 0.954..2.945 (kinematics)
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [3.0, 0, 0.0], position: [4.0, -90.0, 14.0], fov: 34}
display:
  output: j_a
  labels: {j_c: "Spur-gear C (driver)", j_a: "Wheel A", j_arm: "Arm"}
  proof: {label: "Teeth out of contact", sub: "C turns alone"}

