# No. 127 (Brown 1868): "Motion used in air-pumps."
#
# Model (cm): a spur-gear of 16 teeth (module 0.8, pitch radius 6.4, No. 34's straight-flanked teeth) and a lever of 16.0 cm hang on one shaft; the shaft is the one driven joint, swung
# to and fro by the hand at the lever 0.9 rad each way (0.25 swings a second). On the gear's two sides two racks (each 7 teeth, pitch 2.5133) slide up and down in guides; each is the rod of a piston
# working in a pump cylinder above. The right rack goes down as the gear turns clockwise and the left goes up by the same amount, 6.4 cm to the radian, about 5.8 cm each way:
# one always rises while the other falls. There is no gravity (a plan). Generator: opencode-runs/batch10/gen127.py.
number: 127
slug: air-pump-racks
name: A rocking lever with a spur-gear working two pump racks
brown: "Motion used in air-pumps."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 10
  floor: false
  gravity: 0
bodies:
  - id: gear
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 5.55, inner: 0.6, y: [-0.8, 0.8]}
      - {kind: poly, points: [[-0.2646, 5.6571], [-1.9204, 5.3277], [-1.7002, 6.7582], [-1.0154, 6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-2.4094, 5.1252], [-3.813, 4.1873], [-4.157, 5.5931], [-3.5765, 5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-4.1873, 3.813], [-5.1252, 2.4094], [-5.981, 3.5765], [-5.5931, 4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.3277, 1.9204], [-5.6571, 0.2646], [-6.8944, 1.0154], [-6.7582, 1.7002]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.6571, -0.2646], [-5.3277, -1.9204], [-6.7582, -1.7002], [-6.8944, -1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.1252, -2.4094], [-4.1873, -3.813], [-5.5931, -4.157], [-5.981, -3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-3.813, -4.1873], [-2.4094, -5.1252], [-3.5765, -5.981], [-4.157, -5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.9204, -5.3277], [-0.2646, -5.6571], [-1.0154, -6.8944], [-1.7002, -6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[0.2646, -5.6571], [1.9204, -5.3277], [1.7002, -6.7582], [1.0154, -6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[2.4094, -5.1252], [3.813, -4.1873], [4.157, -5.5931], [3.5765, -5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[4.1873, -3.813], [5.1252, -2.4094], [5.981, -3.5765], [5.5931, -4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.3277, -1.9204], [5.6571, -0.2646], [6.8944, -1.0154], [6.7582, -1.7002]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.6571, 0.2646], [5.3277, 1.9204], [6.7582, 1.7002], [6.8944, 1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.1252, 2.4094], [4.1873, 3.813], [5.5931, 4.157], [5.981, 3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[3.813, 4.1873], [2.4094, 5.1252], [3.5765, 5.981], [4.157, 5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[1.9204, 5.3277], [0.2646, 5.6571], [1.0154, 6.8944], [1.7002, 6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.0, 1.0], [1.0, 1.0], [0.8, -16.0], [-0.8, -16.0]], y: [1.0, 1.8], color: "#b9ab8a"}   # the lever on the same shaft, behind the gear
      - {kind: disc, center: [0, -16.0], radius: 1.6, inner: 0.0, y: [0.9, 1.9], color: "#a89a7e"}   # its handle
  - id: rack_r
    shape: part
    pos: [7.65, 0, 0]
    density: 7800
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[7.2, -8.7965], [8.1, -8.7965], [8.1, 8.7965], [7.2, 8.7965]], y: [-0.8, 0.8]}   # the bar behind the teeth
      - {kind: poly, points: [[7.15, 8.7965], [8.15, 8.7965], [8.15, 20.1565], [7.15, 20.1565]], y: [-0.5, 0.5]}   # the piston rod
      - {kind: poly, points: [[4.65, 20.1565], [10.65, 20.1565], [10.65, 22.9565], [4.65, 22.9565]], y: [-1.2, 1.2], color: "#a89a7e"}   # the piston
      - {kind: poly, points: [[7.2, -8.3588], [7.2, -6.7209], [6.0, -7.1576], [6.0, -7.922]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, -5.8455], [7.2, -4.2076], [6.0, -4.6443], [6.0, -5.4087]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, -3.3322], [7.2, -1.6943], [6.0, -2.1311], [6.0, -2.8955]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, -0.819], [7.2, 0.819], [6.0, 0.3822], [6.0, -0.3822]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, 1.6943], [7.2, 3.3322], [6.0, 2.8955], [6.0, 2.1311]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, 4.2076], [7.2, 5.8455], [6.0, 5.4087], [6.0, 4.6443]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.2, 6.7209], [7.2, 8.3588], [6.0, 7.922], [6.0, 7.1576]], y: [-0.8, 0.8], collide: 2}
  - id: rack_l
    shape: part
    pos: [7.65, 0, 0]
    density: 7800
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-7.2, -8.7965], [-8.1, -8.7965], [-8.1, 8.7965], [-7.2, 8.7965]], y: [-0.8, 0.8]}   # the bar behind the teeth
      - {kind: poly, points: [[-7.15, 8.7965], [-8.15, 8.7965], [-8.15, 20.1565], [-7.15, 20.1565]], y: [-0.5, 0.5]}   # the piston rod
      - {kind: poly, points: [[-4.65, 20.1565], [-10.65, 20.1565], [-10.65, 22.9565], [-4.65, 22.9565]], y: [-1.2, 1.2], color: "#a89a7e"}   # the piston
      - {kind: poly, points: [[-7.2, -8.3588], [-7.2, -6.7209], [-6.0, -7.1576], [-6.0, -7.922]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, -5.8455], [-7.2, -4.2076], [-6.0, -4.6443], [-6.0, -5.4087]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, -3.3322], [-7.2, -1.6943], [-6.0, -2.1311], [-6.0, -2.8955]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, -0.819], [-7.2, 0.819], [-6.0, 0.3822], [-6.0, -0.3822]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, 1.6943], [-7.2, 3.3322], [-6.0, 2.8955], [-6.0, 2.1311]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, 4.2076], [-7.2, 5.8455], [-6.0, 5.4087], [-6.0, 4.6443]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.2, 6.7209], [-7.2, 8.3588], [-6.0, 7.922], [-6.0, 7.1576]], y: [-0.8, 0.8], collide: 2}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.4, 0], to: [0, 2.6, 0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-24, -20.0], [24, -20.0], [24, 33.4165], [-24, 33.4165]], y: [2.0, 2.8], collide: 0}   # the plate behind
      - {kind: poly, points: [[-26, -21.0], [26, -21.0], [26, -20.0], [-26, -20.0]], y: [-3, 3], color: "#b9b09c", collide: 0}   # the bench
      - {kind: poly, points: [[3.05, 16.1565], [3.85, 16.1565], [3.85, 32.6165], [3.05, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[11.45, 16.1565], [12.25, 16.1565], [12.25, 32.6165], [11.45, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[3.05, 31.8165], [12.25, 31.8165], [12.25, 32.6165], [3.05, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[3.05, 15.3565], [6.75, 15.3565], [6.75, 16.1565], [3.05, 16.1565]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[8.55, 15.3565], [12.25, 15.3565], [12.25, 16.1565], [8.55, 16.1565]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[-12.25, 16.1565], [-11.45, 16.1565], [-11.45, 32.6165], [-12.25, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[-3.85, 16.1565], [-3.05, 16.1565], [-3.05, 32.6165], [-3.85, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[-12.25, 31.8165], [-3.05, 31.8165], [-3.05, 32.6165], [-12.25, 32.6165]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[-12.25, 15.3565], [-8.55, 15.3565], [-8.55, 16.1565], [-12.25, 16.1565]], y: [-1.8, 1.8], color: "#b9b09c"}
      - {kind: poly, points: [[-6.75, 15.3565], [-3.05, 15.3565], [-3.05, 16.1565], [-6.75, 16.1565]], y: [-1.8, 1.8], color: "#b9b09c"}
joints:
  - {id: j_g, type: hinge, body: gear, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_rr, type: slide, body: rack_r, axis: [0, 0, 1], damping: 0.05}   # + : up
  - {id: j_rl, type: slide, body: rack_l, axis: [0, 0, 1], damping: 0.05}   # + : up
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_g, kind: velocity, rpm: 0, swing: {amplitude: 0.9, hz: 0.25}, kv: 40.0, max_torque: 20}
checks:
  - {type: follow, out: j_rr, in: j_g, expect: -0.064, tol: 0.0032, min_r2: 0.995, settle_s: 0.5, window_s: 3.0}   # the right rack goes down as the gear turns clockwise
  - {type: follow, out: j_rl, in: j_g, expect: 0.064, tol: 0.0032, min_r2: 0.995, settle_s: 0.5, window_s: 3.0}   # the left goes up
  - {type: follow, out: j_rl, in: j_rr, expect: -1.0, tol: 0.03, min_r2: 0.995, settle_s: 4.5, window_s: 3.0}   # one up while the other is down
  - {type: position, joint: j_rr, min: -6.56, max: 6.56, settle_s: 0.0, window_s: 9}
camera: {target: [0, 0, 2.0], position: [0, -134.0, 2.0], fov: 34}
display:
  output: j_rr
  labels: {j_g: "Gear and lever (driver)", j_rr: "Right rack", j_rl: "Left rack"}
  proof: {label: "Teeth out of contact", sub: "the lever swings but the racks stand"}

