# No. 307 (Brown 1868): "A modification of the above with long stopping teeth, D and E, A and B are the pallets."
#
# Model (cm, gravity on). No. 306's three-legged wheel and pendulum, with the locking and the impulse parted. The wheel's three teeth (r 1) are turned clockwise by
# a constant torque (the weight). In the pendulum's plate, D and E are long, thin stopping teeth reaching in from the frame's sides: a tooth coming over the top comes
# down on D's top 40 degrees past the top and rests there (the dead face, an arc about the pendulum's pivot) while the pendulum swings on. A and B are the
# pallets, short blocks under D's free end and over E's: when the pendulum carries D's end past the tooth, the tooth drives A's upright face to the right (the impulse),
# and a sixth of a turn later the next tooth rests under E and then drives B's upright face to the left. At rest D and E stop just short of the teeth, so the
# escapement sets itself going. The only input is the torque on the wheel. Generator: opencode-runs/batch12/gen307.py.
number: 307
slug: three-legged-escapement-long-stopping-teeth
name: Three-legged escapement with long stopping teeth
brown: "A modification of the above with long stopping teeth, D and E, A and B are the pallets."
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.61283], [0.79279, 0.57608]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}   # D, the upper stopping tooth: its top is the dead face
      - {kind: poly, points: [[1.01066, 0.67283], [1.22853, 0.71882], [1.22853, 0.65882], [1.01066, 0.61283]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[1.22853, 0.71882], [1.44639, 0.77428], [1.44639, 0.71428], [1.22853, 0.65882]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[1.44639, 0.77428], [1.66426, 0.83954], [1.66426, 0.77954], [1.44639, 0.71428]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[1.66426, 0.83954], [1.88213, 0.91495], [1.88213, 0.85495], [1.66426, 0.77954]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[1.88213, 0.91495], [2.1, 1.00098], [2.1, 0.94098], [1.88213, 0.85495]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[-0.79279, -0.59975], [-0.79279, -0.53975], [-1.01066, -0.50992], [-1.01066, -0.56992]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}   # E, the lower stopping tooth: its underside is the dead face
      - {kind: poly, points: [[-1.01066, -0.56992], [-1.01066, -0.50992], [-1.22853, -0.47268], [-1.22853, -0.53268]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[-1.22853, -0.53268], [-1.22853, -0.47268], [-1.44639, -0.42792], [-1.44639, -0.48792]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[-1.44639, -0.48792], [-1.44639, -0.42792], [-1.66426, -0.37548], [-1.66426, -0.43548]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[-1.66426, -0.43548], [-1.66426, -0.37548], [-1.88213, -0.31517], [-1.88213, -0.37517]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[-1.88213, -0.37517], [-1.88213, -0.31517], [-2.1, -0.24676], [-2.1, -0.30676]], y: [-0.6, -0.15], collide: 1, color: "#5c6670"}
      - {kind: poly, points: [[0.79279, 0.57608], [1.14279, 0.6396], [1.14279, 0.48608], [0.79279, 0.48608]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}   # A, the upper pallet: its upright left face takes the impulse
      - {kind: poly, points: [[-0.79279, -0.44975], [-1.14279, -0.44975], [-1.14279, -0.48823], [-0.79279, -0.53975]], y: [-0.6, -0.15], collide: 1, color: "#b85c38"}   # B, the lower pallet: its upright right face takes the impulse
      - {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, stopping teeth 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"}

