# No. 304 (Brown 1868): "Pin-wheel escapement, somewhat resembling the stud escapement shown by 292. The pins, A, B, of the escape-wheel are of two different forms, but the form of those on the right side is the best. One advantage of this kind of escapement is that if one of the pins is damaged it can easily be replaced, whereas if a tooth is damaged the whole wheel is ruined."
#
# Model (cm, gravity on). As No. 292, but the escape-wheel (axis at the origin) carries one ring of 30 round pins standing out of its front face at r 8, and both pallets
# work on those pins in front of the wheel. The pallets' arbor F stands 10 up the tangent from where the outer pallet works (25 degrees up the wheel's right
# side). The outer pallet comes in from outside the pins' circle there; the inner pallet comes in from inside, half a pitch further up. Each pallet's upper face is a locking
# face, an arc about F, so a pin resting on it does not move as the pallet slides under it (dead beat); its corner nearest the circle is bevelled (0.35 by 0.35) for the
# impulse. The pallets' arms lie in front of the pins' ends. The wheel goes half a pitch a beat. The only input is a constant torque on the wheel (the weight); the pendulum
# (hung from F, behind the wheel) is kept going only by the pins. Generator: opencode-runs/batch12/gen304.py.
number: 304
slug: pin-wheel-escapement
name: Pin-wheel escapement
brown: "Pin-wheel escapement, somewhat resembling the stud escapement shown by 292. The pins, A, B, of the escape-wheel are of two different forms, but the form of those on the right side is the best. One advantage of this kind of escapement is that if one of the pins is damaged it can easily be replaced, whereas if a tooth is damaged the whole wheel is ruined."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 50, duration_s: 10, floor: false}
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    mass: 0.05
    friction: 0.1
    color: "#e6d7b0"
    pieces:
      - {kind: disc, center: [0, 0], radius: 8.55, inner: 7.45, y: [-0.2, 0.2]}   # the rim
      - {kind: disc, center: [0, 0], radius: 1.2, y: [-0.25, 0.25]}   # the boss
      - {kind: disc, center: [0, 0], radius: 0.4, y: [-0.8, 0.8], color: "#8f8a80"}   # the arbor
      - {kind: poly, points: [[1.06066, 0.35355], [5.65685, 4.94975], [4.94975, 5.65685], [0.35355, 1.06066]], y: [-0.15, 0.15]}   # a spoke
      - {kind: poly, points: [[-0.35355, 1.06066], [-4.94975, 5.65685], [-5.65685, 4.94975], [-1.06066, 0.35355]], y: [-0.15, 0.15]}   # a spoke
      - {kind: poly, points: [[-1.06066, -0.35355], [-5.65685, -4.94975], [-4.94975, -5.65685], [-0.35355, -1.06066]], y: [-0.15, 0.15]}   # a spoke
      - {kind: poly, points: [[0.35355, -1.06066], [4.94975, -5.65685], [5.65685, -4.94975], [1.06066, -0.35355]], y: [-0.15, 0.15]}   # a spoke
      - {kind: disc, center: [7.11861, 3.6504], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}   # a pin
      - {kind: disc, center: [6.20409, 5.05067], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [5.01842, 6.2302], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [3.61343, 7.13745], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [2.05051, 7.73275], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [0.39797, 7.9901], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-1.27196, 7.89823], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-2.8863, 7.46118], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-4.3745, 6.69804], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-5.67151, 5.64216], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-6.72064, 4.3397], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-7.47605, 2.84756], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-7.90473, 1.23098], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-7.98792, -0.43941], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-7.72201, -2.09059], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-7.11861, -3.6504], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-6.20409, -5.05067], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-5.01842, -6.2302], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-3.61343, -7.13745], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-2.05051, -7.73275], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [-0.39797, -7.9901], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [1.27196, -7.89823], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [2.8863, -7.46118], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [4.3745, -6.69804], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [5.67151, -5.64216], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [6.72064, -4.3397], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [7.47605, -2.84756], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [7.90473, -1.23098], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [7.98792, 0.43941], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
      - {kind: disc, center: [7.72201, 2.09059], radius: 0.2, y: [-0.75, -0.2], collide: 2, color: "#8f8a80"}
  - id: pallets
    shape: part
    pos: [3.02428, 0, 12.44402]
    friction: 0.1
    color: "#9aa3ad"
    pieces:
      - {kind: poly, points: [[7.21712, 2.97921], [7.38593, 3.44536], [7.53859, 3.1304]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet (its bevel)
      - {kind: poly, points: [[7.53859, 3.1304], [7.38593, 3.44536], [7.59469, 3.54957], [7.75465, 3.23826]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[7.75465, 3.23826], [7.59469, 3.54957], [7.80096, 3.65862], [7.96815, 3.35113]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[7.96815, 3.35113], [7.80096, 3.65862], [8.00464, 3.77246], [8.17895, 3.46896]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[8.17895, 3.46896], [8.00464, 3.77246], [8.2056, 3.89102], [8.38695, 3.59166]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[8.38695, 3.59166], [8.2056, 3.89102], [8.40374, 4.01423], [8.59202, 3.71919]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[8.59202, 3.71919], [8.40374, 4.01423], [8.59896, 4.14204], [8.79407, 3.85147]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the outer pallet
      - {kind: poly, points: [[7.1854, 3.88605], [6.72058, 4.05868], [6.86176, 3.73842]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet (its bevel)
      - {kind: poly, points: [[6.86176, 3.73842], [6.72058, 4.05868], [6.5059, 3.96729], [6.63887, 3.64354]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[6.63887, 3.64354], [6.5059, 3.96729], [6.28896, 3.8814], [6.41365, 3.55436]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[6.41365, 3.55436], [6.28896, 3.8814], [6.0699, 3.80106], [6.18622, 3.47095]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[6.18622, 3.47095], [6.0699, 3.80106], [5.84886, 3.72632], [5.95674, 3.39336]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[5.95674, 3.39336], [5.84886, 3.72632], [5.626, 3.65723], [5.72537, 3.32164]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[5.72537, 3.32164], [5.626, 3.65723], [5.40145, 3.59384], [5.49224, 3.25582]], y: [-1.05, -0.3], collide: 1, color: "#b85c38"}   # the inner pallet
      - {kind: poly, points: [[3.28052, 12.60005], [8.60479, 3.85592], [8.09231, 3.54388], [2.76804, 12.288]], y: [-1.05, -0.8]}   # the outer pallet's arm
      - {kind: poly, points: [[3.30988, 12.53587], [6.18974, 3.58053], [5.61854, 3.39685], [2.73868, 12.35218]], y: [-1.05, -0.8]}   # the inner pallet's arm
      - {kind: disc, center: [3.02428, 12.44402], radius: 1.0, y: [-1.05, 1.4]}   # the arbor's boss at F
      - {kind: rod, from: [3.02428, 1.2, 12.44402], to: [3.02428, 1.2, -5.95598], radius: 0.2, color: "#8f8a80"}   # the pendulum rod, behind the wheel
      - {kind: disc, center: [3.02428, -7.55598], radius: 1.8, y: [0.9, 1.5], density: 20000.0, color: "#e6d7b0"}   # the bob
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [3.02428, 12.44402], radius: 0.35, y: [-1.0, 1.8], color: "#5c5348"}   # the pin F
      - {kind: poly, points: [[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0]], y: [0.85, 1.05]}   # the cock behind the wheel
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.0001}   # the escape-wheel; + : clockwise (its way)
  - {id: j_pend, type: hinge, body: pallets, axis: [0, 1, 0], damping: 0.002}   # the pendulum and pallets at F; + : clockwise (pallets in)
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
# The weight: a constant torque on the escape-wheel, clockwise. Nothing else is driven.
driver: {joint: j_wheel, kind: torque, torque: 0.015, max_torque: 1}
checks:
  - {type: period, joint: j_pend, tol: 0.03, settle_s: 3, window_s: 6}
  # half a pin's pitch a beat
  - {type: advance, joint: j_wheel, beat: j_pend, expect: 0.10472, tol: 0.03, settle_s: 3, window_s: 6.7}
  # dead beat: the wheel stands while a pin rests on a locking face, never turning back beyond contact compliance
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.005, settle_s: 2, window_s: 7}
  - {type: amplitude, joint: j_pend, min: 0.05, max: 0.15, sustain: 0.9, settle_s: 3, window_s: 6}
  - {type: penetration, max: 0.0005, settle_s: 1}
camera: {target: [1.5, 0, -2.2], position: [1.5, -90.0, -2.2], fov: 30}
display:
  output: j_pend
  swing: j_pend
  labels: {j_wheel: "Pin wheel (weight)", j_pend: "Pendulum and pallets"}
  proof: {label: "Pallets out of contact", sub: "nothing makes good the pendulum's losses, so its swing dies away, and the weight spins the wheel freely"}

