# No. 240 (Brown 1868): "Represents varieties of stops for a ratchet-wheel."
#
# Model (cm, gravity on): a ratchet-wheel of 24 teeth (tips 6, roots 5), each with a radial face looking clockwise and a slope behind,
# rocked to and fro by hand, +-0.1963 rad at 0.5 Hz (the one driven joint), about one and a half teeth each stroke. Three stops of the plate's
# kinds stand round it, their ends a whole number of teeth apart so all three catch together: A, a straight pawl on a pivot to the right, lying on
# the top teeth; B, a hook curving up from a pivot on the left, over a tooth, its end hooked down in front of the next face, so the face pulls it
# rather than pushes; and C, a short click on a pin below with a tail and knob, held up by a flat spring (a joint spring; the drawn spring stands
# still). Each pivot stands on the line along which the face pushes the end, a little outside it for A and C, which the face pushes, and inside
# it for B, which the face pulls, so either way the face draws the end deeper. A and B lie by their weight and a light spring. Turning counter-
# clockwise, the slopes lift all three over each tooth; turning clockwise, the faces meet the ends and the wheel stops. So the wheel goes round
# counter-clockwise a tooth each to-and-fro. Generator: opencode-runs/batch11/gen240.py.
number: 240
slug: ratchet-wheel-stops
name: Varieties of stops for a ratchet-wheel
brown: "Represents varieties of stops for a ratchet-wheel."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 10
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.15
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 5.0, inner: 0.5, y: [-0.5, 0.5]}
      - {kind: poly, points: [[0.8161, 4.6286], [1.0419, 5.9088], [-0.4358, 4.981], [-0.4096, 4.6821]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.4096, 4.6821], [-0.5229, 5.9772], [-1.7101, 4.6985], [-1.6075, 4.4166]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.6075, 4.4166], [-2.0521, 5.6382], [-2.8679, 4.0958], [-2.6958, 3.85]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.6958, 3.85], [-3.4415, 4.9149], [-3.8302, 3.2139], [-3.6004, 3.0211]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6004, 3.0211], [-4.5963, 3.8567], [-4.5315, 2.1131], [-4.2596, 1.9863]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.2596, 1.9863], [-5.4378, 2.5357], [-4.924, 0.8682], [-4.6286, 0.8161]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.6286, 0.8161], [-5.9088, 1.0419], [-4.981, -0.4358], [-4.6821, -0.4096]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.6821, -0.4096], [-5.9772, -0.5229], [-4.6985, -1.7101], [-4.4166, -1.6075]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.4166, -1.6075], [-5.6382, -2.0521], [-4.0958, -2.8679], [-3.85, -2.6958]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.85, -2.6958], [-4.9149, -3.4415], [-3.2139, -3.8302], [-3.0211, -3.6004]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.0211, -3.6004], [-3.8567, -4.5963], [-2.1131, -4.5315], [-1.9863, -4.2596]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.9863, -4.2596], [-2.5357, -5.4378], [-0.8682, -4.924], [-0.8161, -4.6286]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.8161, -4.6286], [-1.0419, -5.9088], [0.4358, -4.981], [0.4096, -4.6821]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.4096, -4.6821], [0.5229, -5.9772], [1.7101, -4.6985], [1.6075, -4.4166]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.6075, -4.4166], [2.0521, -5.6382], [2.8679, -4.0958], [2.6958, -3.85]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.6958, -3.85], [3.4415, -4.9149], [3.8302, -3.2139], [3.6004, -3.0211]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.6004, -3.0211], [4.5963, -3.8567], [4.5315, -2.1131], [4.2596, -1.9863]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.2596, -1.9863], [5.4378, -2.5357], [4.924, -0.8682], [4.6286, -0.8161]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.6286, -0.8161], [5.9088, -1.0419], [4.981, 0.4358], [4.6821, 0.4096]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.6821, 0.4096], [5.9772, 0.5229], [4.6985, 1.7101], [4.4166, 1.6075]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.4166, 1.6075], [5.6382, 2.0521], [4.0958, 2.8679], [3.85, 2.6958]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.85, 2.6958], [4.9149, 3.4415], [3.2139, 3.8302], [3.0211, 3.6004]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.0211, 3.6004], [3.8567, 4.5963], [2.1131, 4.5315], [1.9863, 4.2596]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.9863, 4.2596], [2.5357, 5.4378], [0.8682, 4.924], [0.8161, 4.6286]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.5, y: [-0.8, 0.8], color: "#cfc6b4"}
  - id: stop_a
    shape: part
    pos: [8.0158, 0, 4.288]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[1.0367, 5.0956], [1.276, 6.2715], [2.552, 5.8692]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[8.1736, 4.7624], [7.858, 3.8136], [1.8268, 5.8201], [2.1425, 6.769]], y: [-1.0, -0.5]}
      - {kind: disc, center: [8.0158, 4.288], radius: 0.75, inner: 0.3, y: [-1.0, -0.5]}
  - id: stop_b
    shape: part
    pos: [-8.7073, 0, 0.4726]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-2.8701, 4.3362], [-3.5324, 5.3369], [-2.3456, 5.9547]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[-8.501, 0.0727], [-8.9135, 0.8726], [-5.7808, 2.4884], [-5.3682, 1.6885]], y: [-1.0, -0.5]}
      - {kind: poly, points: [[-5.1402, 1.9704], [-6.0087, 2.2064], [-5.2274, 5.0815], [-4.3589, 4.8454]], y: [-1.0, -0.5]}
      - {kind: poly, points: [[-4.5886, 4.5626], [-4.9977, 5.3643], [-3.2521, 6.2551], [-2.843, 5.4534]], y: [-1.0, -0.5]}
      - {kind: disc, center: [-8.7073, 0.4726], radius: 0.75, inner: 0.3, y: [-1.0, -0.5]}
  - id: stop_c
    shape: part
    pos: [-2.6434, 0, -5.9224]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[0.3175, -5.1903], [0.3907, -6.3881], [-0.946, -6.3297]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[-2.8078, -6.4994], [-2.4789, -5.3454], [-0.1234, -6.0167], [-0.4523, -7.1707]], y: [-1.0, -0.5]}
      - {kind: poly, points: [[-2.7263, -5.4801], [-2.5604, -6.3647], [-5.7604, -6.9647], [-5.9263, -6.0801]], y: [-1.0, -0.5]}
      - {kind: disc, center: [-2.6434, -5.9224], radius: 0.75, inner: 0.3, y: [-1.0, -0.5]}
      - {kind: disc, center: [-5.8434, -6.5224], radius: 0.8, y: [-1.0, -0.5]}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.9, 0], to: [0, 2.4, 0], radius: 0.5, color: "#8f8a80"}   # the wheel's arbor
      - {kind: rod, from: [8.0158, -1.1, 4.288], to: [8.0158, 2.4, 4.288], radius: 0.3, color: "#8f8a80"}
      - {kind: rod, from: [-8.7073, -1.1, 0.4726], to: [-8.7073, 2.4, 0.4726], radius: 0.3, color: "#8f8a80"}
      - {kind: rod, from: [-2.6434, -1.1, -5.9224], to: [-2.6434, 2.4, -5.9224], radius: 0.3, color: "#8f8a80"}
      - {kind: poly, points: [[1.9372, -9.249], [1.7761, -8.9959], [3.9761, -7.5959], [4.1372, -7.849]], y: [-1.0, -0.6], color: "#8f8a80"}
      - {kind: poly, points: [[4.0642, -7.5726], [4.0491, -7.8722], [-4.8509, -7.4222], [-4.8358, -7.1226]], y: [-1.0, -0.6], color: "#8f8a80"}
      - {kind: disc, center: [1.8566, -9.1224], radius: 0.4, y: [-1.1, -0.6], color: "#6b5a44"}   # the spring's screw
      - {kind: poly, points: [[-11, -11], [11, -11], [11, 9], [-11, 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_stop_a, type: hinge, body: stop_a, axis: [0, -1, 0], range: [-0.5, 0], stiffness: 0.05, springref: 0.2, damping: 0.0002}
  - {id: j_stop_b, type: hinge, body: stop_b, axis: [0, -1, 0], range: [0, 0.5], stiffness: 0.05, springref: -0.2, damping: 0.0002}
  - {id: j_stop_c, type: hinge, body: stop_c, axis: [0, -1, 0], range: [-0.5, 0], stiffness: 0.2, springref: 0.2, damping: 0.0002}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_wheel, kind: velocity, rpm: 0, swing: {amplitude: 0.1963, hz: 0.5}, kv: 20, max_torque: 30}
checks:
  - {type: turning, joint: j_wheel, direction: 1, min_mean: 0.08, slow: 0.2, min_fraction: 0.2, settle_s: 1, window_s: 9}   # a tooth (p/2 per s) each to-and-fro
  - {type: clicks, joint: j_stop_a, lift: 0.04, min: 3, settle_s: 1, window_s: 9}
  - {type: clicks, joint: j_stop_b, lift: 0.04, min: 3, settle_s: 1, window_s: 9}
  - {type: clicks, joint: j_stop_c, lift: 0.06, min: 3, settle_s: 1, window_s: 9}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, -0.5], position: [0, -80.0, 1.0], fov: 34}
display:
  output: j_wheel
  labels: {j_wheel: "Ratchet-wheel (driver)", j_stop_a: "Pawl A", j_stop_b: "Hook B", j_stop_c: "Click C"}
  proof: {label: "Stops out of contact", sub: "the wheel swings to and fro and gets nowhere"}

