# No. 216 (Brown 1868): "The external and internal mutilated cog-wheels work alternately into the pinion, and give slow forward and quick reverse motion."
#
# Model (cm): one wheel, on one arbor, carries an internal cog-ring of 42 tooth places (pitch radius 16.8) and, inside it, an external cog-wheel of 14 places (pitch
# radius 5.6); the pinion, 14 teeth, stands 11.2 below the arbor, between the two, so that it can gear with either (module 0.8; 42 = 14 + 2 x 14). Each is mutilated:
# the ring keeps 7 teeth and the inner wheel 9, on opposite sides, so they work into the pinion alternately: the inner wheel turns it slowly the opposite way to the wheel (1:1),
# the ring quickly the same way (3:1). The ring's longer arc of contact makes its 7 teeth turn the pinion as far as the inner wheel's 9, so it comes back to where it began each
# turn of the wheel (about 245 degrees each way). Straight-flanked teeth as No. 34's; the ring's and wheel's tooth phases are those of full wheels in mesh with the pinion.
# Between the arcs the pinion stands (friction). A counterweight behind balances the mutilated wheel. Only the wheel is driven (10 rpm). Generator: opencode-runs/batch11/gen216.py.
number: 216
slug: mutilated-internal-external-cog-wheels
name: Mutilated internal and external cog-wheels
brown: "The external and internal mutilated cog-wheels work alternately into the pinion, and give slow forward and quick reverse motion."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 13.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[-16.1987, -7.0594], [-15.4511, -8.5731], [-14.4061, -7.5048], [-14.7153, -6.8788]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-14.9657, -9.3949], [-14.0008, -10.7802], [-13.1267, -9.5681], [-13.5257, -8.9952]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-13.3983, -11.5205], [-12.2377, -12.7465], [-11.554, -11.4177], [-12.034, -10.9107]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-11.5316, -13.3887], [-10.2013, -14.4281], [-9.7233, -13.0122], [-10.2734, -12.5824]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-9.4073, -14.9579], [-7.9369, -15.7873], [-7.6753, -14.3161], [-8.2834, -13.973]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-7.0729, -16.1929], [-5.4953, -16.7939], [-5.4559, -15.3001], [-6.1083, -15.0515]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-4.5805, -17.0662], [-2.9309, -17.4254], [-3.1146, -15.9424], [-3.7968, -15.7938]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[4.5863, -1.497], [4.8212, 0.1748], [6.1486, -0.5116], [6.0515, -1.203]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[4.7816, 0.6412], [4.2679, 2.2494], [5.7617, 2.2069], [5.9741, 1.5418]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[4.0299, 2.6524], [2.8693, 3.8784], [4.2336, 4.4882], [4.7136, 3.9812]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[2.48, 4.1382], [0.9024, 4.7393], [1.867, 5.8806], [2.5194, 5.632]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[0.4389, 4.8044], [-1.2433, 4.6615], [-0.8694, 6.1083], [-0.1737, 6.1674]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-1.6891, 4.519], [-3.1427, 3.6604], [-3.4336, 5.1262], [-2.8325, 5.4813]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[-3.4826, 3.3386], [-4.4196, 1.9344], [-5.3178, 3.1287], [-4.9302, 3.7095]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[1.6891, -4.519], [3.1427, -3.6604], [3.4336, -5.1262], [2.8325, -5.4813]], y: [-1.0, 1.0], collide: 2}
      - {kind: poly, points: [[3.4826, -3.3386], [4.4196, -1.9344], [5.3178, -3.1287], [4.9302, -3.7095]], y: [-1.0, 1.0], collide: 2}
      - {kind: disc, center: [0, 0], radius: 19.23, inner: 17.63, y: [-1.0, 1.0], collide: 0}   # the ring's rim
      - {kind: disc, center: [0, 0], radius: 4.77, inner: 0.7, y: [-1.0, 1.0], collide: 0}   # the inner wheel's body
      - {kind: disc, center: [0, 0], radius: 19.23, inner: 0.7, y: [1.0, 1.4], collide: 0, color: "#c9bd9c"}   # the wheel's back plate, joining ring and inner wheel
      - {kind: disc, center: [5.8778, 8.0902], radius: 3.1498, y: [1.4, 2.4], collide: 0, color: "#b8ab8a"}   # counterweight behind, so the mutilated wheel is balanced
  - id: pinion
    shape: part
    pos: [0, 0, -11.2]
    density: 7800
    friction: 0.1
    color: "#cbbd99"
    pieces:
      - {kind: poly, points: [[4.8187, -10.966], [4.4431, -9.3201], [5.9279, -9.4889], [6.0832, -10.1696]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[4.24, -8.8984], [3.1874, -7.5785], [4.5984, -7.0864], [5.0337, -7.6322]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[2.8215, -7.2866], [1.3004, -6.5542], [2.3582, -5.4986], [2.9872, -5.8015]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[0.8441, -6.45], [-0.8441, -6.45], [-0.3491, -5.04], [0.3491, -5.04]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-1.3004, -6.5542], [-2.8215, -7.2866], [-2.9872, -5.8015], [-2.3582, -5.4986]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-3.1874, -7.5785], [-4.24, -8.8984], [-5.0337, -7.6322], [-4.5984, -7.0864]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-4.4431, -9.3201], [-4.8187, -10.966], [-6.0832, -10.1696], [-5.9279, -9.4889]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-4.8187, -11.434], [-4.4431, -13.0799], [-5.9279, -12.9111], [-6.0832, -12.2304]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-4.24, -13.5016], [-3.1874, -14.8215], [-4.5984, -15.3136], [-5.0337, -14.7678]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-2.8215, -15.1134], [-1.3004, -15.8458], [-2.3582, -16.9014], [-2.9872, -16.5985]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[-0.8441, -15.95], [0.8441, -15.95], [0.3491, -17.36], [-0.3491, -17.36]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[1.3004, -15.8458], [2.8215, -15.1134], [2.9872, -16.5985], [2.3582, -16.9014]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[3.1874, -14.8215], [4.24, -13.5016], [5.0337, -14.7678], [4.5984, -15.3136]], y: [-1.0, 1.0], collide: 1}
      - {kind: poly, points: [[4.4431, -13.0799], [4.8187, -11.434], [6.0832, -12.2304], [5.9279, -12.9111]], y: [-1.0, 1.0], collide: 1}
      - {kind: disc, center: [0, -11.2], radius: 4.77, inner: 0.6, y: [-1.0, 1.0], collide: 0}   # the pinion's body
      - {kind: disc, center: [0, -11.2], radius: 1.2, y: [-1.3, -1.0], collide: 0, color: "#8f8a80"}   # its arbor's end
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.2, 0], to: [0, 3.6, 0], radius: 0.7, collide: 0, color: "#8f8a80"}   # the wheel's arbor
      - {kind: disc, center: [0, 0], radius: 1.0, y: [-1.3, -1.0], collide: 0, color: "#8f8a80"}
      - {kind: poly, points: [[-1.2, -12.4], [1.2, -12.4], [1.2, 1.2], [-1.2, 1.2]], y: [2.8, 3.6], collide: 0}   # the standard, behind
      - {kind: poly, points: [[-12, -21.73], [12, -21.73], [12, -20.73], [-12, -20.73]], y: [-2, 3.6], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-1.2, -20.73], [1.2, -20.73], [1.2, -19.53], [-1.2, -19.53]], y: [2.8, 3.6], collide: 0}
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.01}   # the one driven joint; +: counter-clockwise
  - {id: j_pinion, type: hinge, body: pinion, 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_wheel, kind: velocity, rpm: 10, kv: 20, max_torque: 20}
checks:
  - {type: ratio, out: j_pinion, in: j_wheel, expect: 3.0, tol: 0.06, settle_s: 0.35, window_s: 0.85}   # the ring: quick, the same way
  - {type: ratio, out: j_pinion, in: j_wheel, expect: -1.0, tol: 0.03, settle_s: 2.2, window_s: 3.1}   # the inner wheel: slow, the other way
  - {type: ratio, out: j_pinion, in: j_wheel, expect: 3.0, tol: 0.06, settle_s: 6.35, window_s: 0.85}   # and again, the next turn
  - {type: position, joint: j_pinion, min: -0.25, max: 4.55, settle_s: 0, window_s: 12.9}   # to and fro over about 245 degrees each turn, no creep
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, -1.5], position: [0, -95, -0.5], fov: 34}
display:
  output: j_pinion
  labels: {j_wheel: "Mutilated wheels (driver)", j_pinion: "Pinion"}
  proof: {label: "Teeth out of contact", sub: "the wheels turn alone and the pinion stays put"}

