# No. 306 (Brown 1868): "Three-legged pendulum escapement. The pallets are formed in an opening in a plate attached to the pendulum, and the three teeth of the escape-wheel operate on the upper and lower pallets alternately. One tooth is shown in operation on the upper pallet."
#
# Model (cm, gravity on). The escape-wheel has three legs, their ends (the teeth) at r 1, on an axis along y at the origin, turned clockwise by a constant torque
# (the weight). The pendulum hangs from a pivot 6 above it; the plate on the pendulum has an opening round the wheel, and the upper and lower edges of the opening
# form the two pallets. The upper pallet's top face is dead: a tooth coming over the top comes down on it 40 degrees past the top and rests there while the
# pendulum swings on. When the pendulum, coming back, carries the face's left end past the tooth, the tooth drives the pallet's upright left face to the right (the impulse);
# a sixth of a turn later the next tooth comes up under the lower pallet (the same turned half round), rests on its dead underside, and then drives its upright right
# face to the left. The dead faces are arcs about the pendulum's pivot. At rest they stop just short of the teeth, so the escapement sets itself going. A sixth of a
# turn a beat. The only input is the torque on the wheel; the pendulum is kept going only by the teeth. Generator: opencode-runs/batch12/gen306.py.
number: 306
slug: three-legged-pendulum-escapement
name: Three-legged pendulum escapement
brown: "Three-legged pendulum escapement. The pallets are formed in an opening in a plate attached to the pendulum, and the three teeth of the escape-wheel operate on the upper and lower pallets alternately. One tooth is shown in operation on the upper pallet."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 50, duration_s: 10, floor: false}
bodies:
  - id: disc
    shape: part
    pos: [0, 0, 0]
    mass: 0.01
    friction: 0.1
    color: "#e6d7b0"
    pieces:
      - {kind: disc, center: [0, 0], radius: 0.4, y: [-0.1, 0.1]}   # the hub
      - {kind: disc, center: [0, 0], radius: 0.2, y: [-0.15, 0.6], color: "#8f8a80"}   # its arbor
      - {kind: rod, from: [0, -0.3, 0], to: [-0.34202, -0.3, 0.93969], radius: 0.12, collide: 0}   # a leg
      - {kind: rod, from: [0, -0.3, 0], to: [0.98481, -0.3, -0.17365], radius: 0.12, collide: 0}
      - {kind: rod, from: [0, -0.3, 0], to: [-0.64279, -0.3, -0.76604], radius: 0.12, collide: 0}
      - {kind: disc, center: [-0.34202, 0.93969], radius: 0.15, y: [-0.6, -0.1], collide: 2, color: "#5c5348"}   # a leg's end, the tooth
      - {kind: disc, center: [0.98481, -0.17365], radius: 0.15, y: [-0.6, -0.1], collide: 2, color: "#5c5348"}
      - {kind: disc, center: [-0.64279, -0.76604], radius: 0.15, y: [-0.6, -0.1], collide: 2, color: "#5c5348"}
  - id: pendulum
    shape: part
    pos: [0, 0, 6.0]
    friction: 0.1
    color: "#9aa3ad"
    pieces:
      - {kind: poly, points: [[0.79279, 0.63608], [1.01066, 0.67283], [1.01066, 0.52283], [0.79279, 0.48608]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}   # the upper pallet: dead face on top, impulse face at its left end
      - {kind: poly, points: [[1.01066, 0.67283], [1.22853, 0.71882], [1.22853, 0.56882], [1.01066, 0.52283]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}
      - {kind: poly, points: [[1.22853, 0.71882], [1.44639, 0.77428], [1.44639, 0.62428], [1.22853, 0.56882]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}
      - {kind: poly, points: [[1.44639, 0.77428], [1.66426, 0.83954], [1.66426, 0.68954], [1.44639, 0.62428]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}
      - {kind: poly, points: [[1.66426, 0.83954], [1.88213, 0.91495], [1.88213, 0.76495], [1.66426, 0.68954]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}
      - {kind: poly, points: [[1.88213, 0.91495], [2.1, 1.00098], [2.1, 0.85098], [1.88213, 0.76495]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}
      - {kind: poly, points: [[-0.79279, -0.44975], [-2.1, -0.15676], [-2.1, -0.30676], [-1.88213, -0.37517], [-1.66426, -0.43548], [-1.44639, -0.48792], [-1.22853, -0.53268], [-1.01066, -0.56992], [-0.79279, -0.59975]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}   # the lower pallet: dead face underneath, impulse face at its right end
      - {kind: poly, points: [[2.1, -0.91604], [2.4, -0.91604], [2.4, 0.61604], [2.1, 0.61604]], y: [-0.6, -0.15]}   # the frame's right side
      - {kind: poly, points: [[-2.4, -0.91604], [-2.1, -0.91604], [-2.1, 0.61604], [-2.4, 0.61604]], y: [-0.6, -0.15]}   # the frame's left side
      - {kind: poly, points: [[-2.4, -0.91604], [2.4, -0.91604], [2.4, -1.21604], [-2.4, -1.21604]], y: [-0.6, -0.15]}   # the frame's foot
      - {kind: poly, points: [[-2.4, 0.61604], [-2.1, 0.61604], [0.15, 5.4], [-0.15, 5.4]], y: [-0.6, -0.15]}   # a stay to the pivot
      - {kind: poly, points: [[2.1, 0.61604], [2.4, 0.61604], [0.15, 5.4], [-0.15, 5.4]], y: [-0.6, -0.15]}   # and the other
      - {kind: disc, center: [0, 6.0], radius: 0.7, y: [-0.7, 1.2]}   # the pendulum's boss
      - {kind: rod, from: [0, 1.0, 6.0], to: [0.0, 1.0, -4.4], radius: 0.2, color: "#8f8a80"}   # the pendulum rod, behind the disc
      - {kind: disc, center: [0.0, -6.0], radius: 1.8, y: [0.7, 1.3], density: 60000.0, color: "#e6d7b0"}   # the bob
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [0, 6.0], radius: 0.3, y: [-0.9, 1.4], color: "#5c5348"}   # the pendulum's pin
      - {kind: poly, points: [[-0.6, -0.6], [0.6, -0.6], [0.6, 0.6], [-0.6, 0.6]], y: [0.6, 0.8]}   # the cock behind the disc
joints:
  - {id: j_disc, type: hinge, body: disc, axis: [0, 1, 0], damping: 0.0001}   # the escape-disc; + : clockwise (its way)
  - {id: j_pend, type: hinge, body: pendulum, axis: [0, 1, 0], damping: 0.002}   # the pendulum; + : clockwise
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
# The weight: a constant torque on the wheel, clockwise. Nothing else is driven.
driver: {joint: j_disc, kind: torque, torque: 0.003, max_torque: 1}
checks:
  - {type: period, joint: j_pend, tol: 0.04, settle_s: 3, window_s: 6}
  # a sixth of a turn a beat
  - {type: advance, joint: j_disc, beat: j_pend, expect: 1.0472, tol: 0.03, settle_s: 3, window_s: 6.7}
  # dead faces: the disc stands while the pin rests on one, never turning back beyond contact compliance
  - {type: monotonic, joint: j_disc, direction: 1, max_back: 0.04, settle_s: 2, window_s: 7}
  - {type: amplitude, joint: j_pend, min: 0.05, max: 0.2, sustain: 0.9, settle_s: 3, window_s: 6}
  - {type: penetration, max: 0.0005, settle_s: 1}
camera: {target: [0, 0, 0.6], position: [0, -17.0, 0.6], fov: 30}
display:
  output: j_pend
  swing: j_pend
  labels: {j_disc: "Three-legged 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"}

