# No. 292 (Brown 1868): "Stud escapement, used in large clocks. One pallet, B, works in front of the wheel and the other at the back. The studs are arranged in the same manner, and rest alternately upon the front or back pallet. As the curve of the pallets is an arc described from F, this is a repose or dead-beat escapement."
#
# Model (cm, gravity on). The escape-wheel (axis at the origin) carries 24 studs on its front face and 24 on its back, at r 8, the back ones half way between the front
# ones. The pallets' arbor F stands 10 up the tangent from the point where the pallets work on the studs' circle (25 degrees up the wheel's right side), so
# as the arbor rocks the pallets go in and out across the circle. B, in front, comes in from outside and catches the front studs; A, at the back, comes in from inside and
# catches the back studs. Each pallet's upper face is its locking face, square to the line from F (the arc about F, over its short length a straight line): a stud resting
# on it is not moved as the pallet slides under it, so the wheel stands dead while the pendulum swings on. The pallet's corner nearest the studs' circle is bevelled (0.35
# by 0.35): when the pallet has slid out far enough, the stud comes down the bevel and pushes it on out (the impulse), drops off, and the next stud of the other face falls
# on the other pallet, now in. The wheel goes half a stud's pitch a beat. The only input is a constant torque on the wheel (the weight), clockwise as Brown's arrow; the
# pendulum (hung from F, behind the wheel) is kept going only by the studs. Generator: opencode-runs/batch12/gen292.py.
number: 292
slug: stud-escapement
name: Stud escapement, used in large clocks
brown: "Stud escapement, used in large clocks. One pallet, B, works in front of the wheel and the other at the back. The studs are arranged in the same manner, and rest alternately upon the front or back pallet. As the curve of the pallets is an arc described from F, this is a repose or dead-beat escapement."
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.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [6.58124, 4.54833], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [5.93126, 5.36845], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [5.17979, 6.0967], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [4.3397, 6.72064], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [3.42535, 7.22959], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [2.4524, 7.61484], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [1.43748, 7.86979], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [0.39797, 7.9901], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-0.64835, 7.97368], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-1.68358, 7.82084], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-2.69, 7.53418], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-3.6504, 7.11861], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-4.54833, 6.58124], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-5.36845, 5.93126], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-6.0967, 5.17979], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-6.72064, 4.3397], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-7.22959, 3.42535], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-7.61484, 2.4524], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-7.86979, 1.43748], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-7.9901, 0.39797], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-7.97368, -0.64835], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-7.82084, -1.68358], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-7.53418, -2.69], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-7.11861, -3.6504], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-6.58124, -4.54833], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-5.93126, -5.36845], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-5.17979, -6.0967], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-4.3397, -6.72064], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-3.42535, -7.22959], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-2.4524, -7.61484], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [-1.43748, -7.86979], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [-0.39797, -7.9901], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [0.64835, -7.97368], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [1.68358, -7.82084], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [2.69, -7.53418], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [3.6504, -7.11861], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [4.54833, -6.58124], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [5.36845, -5.93126], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [6.0967, -5.17979], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [6.72064, -4.3397], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [7.22959, -3.42535], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [7.61484, -2.4524], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [7.86979, -1.43748], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [7.9901, -0.39797], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [7.97368, 0.64835], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
      - {kind: disc, center: [7.82084, 1.68358], radius: 0.2, y: [-0.6, -0.2], collide: 2, color: "#8f8a80"}   # a front stud
      - {kind: disc, center: [7.53418, 2.69], radius: 0.2, y: [0.2, 0.6], collide: 2, color: "#8f8a80"}   # a back stud
  - 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: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front (its bevel)
      - {kind: poly, points: [[7.53859, 3.1304], [7.38593, 3.44536], [7.59469, 3.54957], [7.75465, 3.23826]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[7.75465, 3.23826], [7.59469, 3.54957], [7.80096, 3.65862], [7.96815, 3.35113]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[7.96815, 3.35113], [7.80096, 3.65862], [8.00464, 3.77246], [8.17895, 3.46896]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[8.17895, 3.46896], [8.00464, 3.77246], [8.2056, 3.89102], [8.38695, 3.59166]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[8.38695, 3.59166], [8.2056, 3.89102], [8.40374, 4.01423], [8.59202, 3.71919]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[8.59202, 3.71919], [8.40374, 4.01423], [8.59896, 4.14204], [8.79407, 3.85147]], y: [-0.65, -0.25], collide: 1, color: "#b85c38"}   # the pallet B, in front
      - {kind: poly, points: [[7.57964, 3.14826], [7.11405, 3.31858], [7.25719, 2.99918]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back (its bevel)
      - {kind: poly, points: [[7.25719, 2.99918], [7.11405, 3.31858], [6.90002, 3.22564], [7.03568, 2.903]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[7.03568, 2.903], [6.90002, 3.22564], [6.68389, 3.13772], [6.81198, 2.812]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[6.81198, 2.812], [6.68389, 3.13772], [6.46577, 3.05487], [6.58622, 2.72625]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[6.58622, 2.72625], [6.46577, 3.05487], [6.24577, 2.97714], [6.35853, 2.64579]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[6.35853, 2.64579], [6.24577, 2.97714], [6.02402, 2.90455], [6.12901, 2.57067]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[6.12901, 2.57067], [6.02402, 2.90455], [5.80064, 2.83716], [5.89781, 2.50092]], y: [0.25, 0.65], collide: 1, color: "#b85c38"}   # the pallet A, at the back
      - {kind: poly, points: [[3.28052, 12.60005], [8.60479, 3.85592], [8.09231, 3.54388], [2.76804, 12.288]], y: [-0.65, -0.35]}   # B's arm
      - {kind: poly, points: [[3.30851, 12.54002], [6.58452, 2.84078], [6.01606, 2.64878], [2.74005, 12.34802]], y: [0.35, 0.65]}   # A's arm
      - {kind: disc, center: [3.02428, 12.44402], radius: 1.0, y: [-0.7, 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 stud's pitch a beat
  - {type: advance, joint: j_wheel, beat: j_pend, expect: 0.1309, tol: 0.03, settle_s: 3, window_s: 6.7}
  # dead beat: the wheel stands while a stud 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: "Stud wheel (weight)", j_pend: "Pendulum and pallets A B"}
  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"}

