# No. 238 (Brown 1868): "An escapement. D is the escape-wheel, and C and B the pallets. A is the axis of the pallets."
#
# Model (cm, gravity on): the escape-wheel D, a star of 6 points (tips 5, roots 3), turned counter-clockwise by a constant torque (a clock's weight;
# the one driven joint). The pallets B and C are pins on a frame that turns on the axis A below the wheel, B under the wheel on the left and C level with
# it on the right, 2.5 teeth apart round the wheel. A sits where the tangents to the wheel at B and C meet, so both pins move straight in and out
# by the same amount (with A nearer one pin than the other, that pin outruns the flank in front of it and the two lock). A counterpoise balances the
# frame on A; a spring (a joint spring, the balance-spring) holds the frame in the middle with each pin a little
# inside the points. Turning the frame one way draws B out of the wheel and puts C in, the other way the reverse. A point's flank pushes one pin out,
# which swings the frame and puts the other pin in front of a point half a tooth on; that point drives it back. So the frame vibrates and the wheel
# goes round half a tooth each beat. Generator: opencode-runs/batch11/gen238.py.
number: 238
slug: star-wheel-escapement
name: An escapement with a star-wheel and two pallets
brown: "An escapement. D is the escape-wheel, and C and B the pallets. A is the axis of the pallets."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 10.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.0, inner: 0.4, y: [-0.5, 0.5]}
      - {kind: poly, points: [[-2.6897, 0.2353], [-4.5315, -2.1131], [-1.5487, -2.2117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.5487, -2.2117], [-0.4358, -4.981], [1.1411, -2.447]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.1411, -2.447], [4.0958, -2.8679], [2.6897, -0.2353]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.6897, -0.2353], [4.5315, 2.1131], [1.5487, 2.2117]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.5487, 2.2117], [0.4358, 4.981], [-1.1411, 2.447]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.1411, 2.447], [-4.0958, 2.8679], [-2.6897, 0.2353]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 0.9, inner: 0.4, y: [-0.8, 0.8], color: "#cfc6b4"}
  - id: frame_a
    shape: part
    pos: [7.5112, 0, -16.1078]
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[8.2006, -15.5293], [6.8218, -16.6863], [-4.2132, -3.5353], [-2.8344, -2.3783]], y: [-1.4, -0.6]}
      - {kind: poly, points: [[7.9146, -16.9124], [7.1078, -15.3033], [11.0966, -13.3033], [11.9034, -14.9124]], y: [-1.4, -0.6]}
      - {kind: poly, points: [[12.3, -14.1078], [10.7, -14.1078], [10.7, 1.3988], [12.3, 1.3988]], y: [-1.4, -0.6]}
      - {kind: poly, points: [[11.5, 1.3988], [11.5, 0.1988], [4.5301, 0.1988], [4.5301, 1.3988]], y: [-1.4, -0.6]}
      - {kind: disc, center: [7.5112, -16.1078], radius: 2.2, inner: 0.4, y: [-1.4, -0.6]}
      - {kind: disc, center: [7.5112, -16.1078], radius: 1.0, inner: 0.4, y: [-1.8, -1.4], color: "#cfc6b4"}
      - {kind: disc, center: [12.5112, -16.1078], radius: 2.0, y: [-1.4, -0.6], color: "#a39780"}   # counterpoise: the frame balanced on A
      - {kind: rod, from: [-3.5238, -1.4, -2.9568], to: [-3.5238, 0.6, -2.9568], radius: 0.4, capsule: true, collide: 2, color: "#6b5a44"}   # pallet B
      - {kind: rod, from: [4.5301, -1.4, 0.7988], to: [4.5301, 0.6, 0.7988], radius: 0.4, capsule: true, collide: 2, color: "#6b5a44"}   # pallet C
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.8, 0], to: [0, 2.4, 0], radius: 0.4, color: "#8f8a80"}   # D's arbor
      - {kind: rod, from: [7.5112, -1.8, -16.1078], to: [7.5112, 2.4, -16.1078], radius: 0.4, color: "#8f8a80"}   # the axis A
      - {kind: poly, points: [[-7, -18.8], [15.2, -18.8], [15.2, 9], [-7, 9]], y: [1.2, 2.4], color: "#b9b09c"}   # the plate behind
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.0005}   # the one driven joint; +: counter-clockwise as seen
  - {id: j_frame, type: hinge, body: frame_a, axis: [0, -1, 0], damping: 0.0005, stiffness: 0.6, springref: 0}   # +: counter-clockwise (B out, C in)
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_wheel, kind: torque, torque: 0.02, max_torque: 0.1}
checks:
  - {type: advance, joint: j_wheel, beat: j_frame, expect: 0.52360, tol: 0.05, settle_s: 2, window_s: 7.5}   # half a tooth (2 pi / 6 / 2) each beat of the pallets
  - {type: amplitude, joint: j_frame, min: 0.02, max: 0.5, sustain: 0.8, settle_s: 2, window_s: 7.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [3.0, 0, -4.5], position: [3.0, -90.0, -2.0], fov: 34}
display:
  output: j_frame
  swing: j_frame
  labels: {j_wheel: "Escape-wheel D (weight)", j_frame: "Pallets B, C on A"}
  proof: {label: "Pallets out of contact", sub: "the wheel runs away"}

