# No. 297 (Brown 1868): "An escapement with a lantern wheel. An arm, A, carries the two pallets, B and C."
#
# Model (cm, gravity on). The lantern wheel (axis at the origin) has 8 staves (radius 0.5) on a circle of radius 5, between two plates, and turns counter-clockwise
# as Brown's arrow. The arm A hangs from its pivot, 3.8 right of and 9 above the wheel's axis, behind the wheel, and goes on down to a bob: it is the pendulum. It carries two flat
# pallets across the staves' path: B outside the circle, crossing it 40 degrees up the right side, and C inside it, crossing 17.5 degrees up.
# As the arm swings to the right, C goes out into the staves' path and B comes out of it; swinging to the left, B goes in and C comes out. A rising stave meets the
# underside of the pallet in its way. Each underside slopes, so the stave pushes the pallet out of its way and the arm along (the impulse), slips off the tip, and the
# arm, now swung over, has put the other pallet in the way of the next stave. The only input is a constant torque on the wheel (the weight). The arm starts hanging
# at rest and is set going by the staves. Generator: opencode-runs/batch12/gen297.py.
number: 297
slug: lantern-wheel-escapement
name: An escapement with a lantern wheel
brown: "An escapement with a lantern wheel. An arm, A, carries the two pallets, B and C."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 50, duration_s: 10.0, 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: 6.0, y: [0.5, 0.8]}   # the back plate
      - {kind: disc, center: [0, 0], radius: 1.3, inner: 0.6, y: [-0.8, 0.5]}   # the hub
      - {kind: disc, center: [0, 0], radius: 0.6, y: [-1.0, 1.2], color: "#8f8a80"}   # the arbor
      - {kind: disc, center: [4.95134, 0.69587], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [3.00908, 3.99318], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [-0.69587, 4.95134], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [-3.99318, 3.00908], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [-4.95134, -0.69587], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [-3.00908, -3.99318], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [0.69587, -4.95134], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
      - {kind: disc, center: [3.99318, -3.00908], radius: 0.5, y: [-0.5, 0.5], collide: 2, color: "#8f8a80"}   # a stave
  - id: arm
    shape: part
    pos: [3.8, 0, 9.0]
    mass: 2.0
    friction: 0.1
    color: "#d9cfba"
    pieces:
      - {kind: disc, center: [3.8, 9.0], radius: 0.5, y: [0.85, 1.25]}   # the arm's boss on its pivot
      - {kind: poly, points: [[3.45, 9.0], [4.15, 9.0], [4.15, -9.0], [3.45, -9.0]], y: [0.9, 1.2]}   # the arm A, behind the wheel (dashed in Brown)
      - {kind: poly, points: [[4.09834, 3.43891], [6.39347, 2.73722], [6.52504, 3.16756], [4.22991, 3.86925]], y: [-0.6, 0.45], collide: 1, color: "#b85c38"}   # the pallet B
      - {kind: poly, points: [[4.43478, 1.39828], [1.67327, 0.22609], [1.49744, 0.64032], [4.25895, 1.81251]], y: [-0.6, 0.45], collide: 1, color: "#b85c38"}   # the pallet C
      - {kind: disc, center: [3.8, -9.0], radius: 1.6, y: [0.9, 1.5], density: 8500, color: "#e6d7b0"}   # the bob
  - id: cock
    shape: part
    pos: [3.8, 0, 9.0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [3.8, 9.0], radius: 0.18, y: [0.2, 1.5], color: "#8f8a80"}
      - {kind: poly, points: [[2.8, 10.5], [3.3, 9.0], [4.3, 9.0], [4.8, 10.5]], y: [1.3, 1.6]}
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, 1, 0], damping: 2e-05}   # the lantern wheel; - : counter-clockwise (its way)
  - {id: j_pend, type: hinge, body: arm, axis: [0, 1, 0], damping: 0.002}   # the arm and its bob (air and pivot losses)
contact: {solref: [0.001, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
# The weight: a constant torque on the wheel, counter-clockwise. Nothing else is driven.
driver: {joint: j_wheel, kind: torque, torque: -0.025, max_torque: 0.5}
checks:
  - {type: advance, joint: j_wheel, beat: j_pend, expect: -0.3927, tol: 0.03, settle_s: 3, window_s: 6.2}
  # the pendulum keeps time near the compound pendulum's 2 pi sqrt(I/(m g d)), a little quicker: the pallets push it back toward the middle
  # through each recoil (a recoil clock's rate depends on its weight)
  - {type: period, joint: j_pend, tol: 0.08, settle_s: 3, window_s: 6}
  - {type: amplitude, joint: j_pend, min: 0.04, max: 0.3, sustain: 0.9, settle_s: 3, window_s: 6}
  - {type: penetration, max: 0.0005, settle_s: 1}
camera: {target: [1.9, 0, 1.5], position: [1.9, -41.0, 1.5], fov: 30}
display:
  output: j_pend
  swing: j_pend
  labels: {j_wheel: "Lantern wheel (weight)", j_pend: "Arm A and pendulum"}
  proof: {label: "Pallets out of contact", sub: "nothing makes good the pendulum's losses, so it hangs still, and the weight spins the wheel freely"}

