# No. 239 (Brown 1868): "An arrangement of stops for a spur-gear."
#
# Model (cm, gravity on): a spur-gear of 12 teeth (tips 5, roots 4) rocked to and fro by hand, +-0.39 rad at 0.5 Hz (the one driven
# joint). Two stops on pivots either side, as in the plate, hang over it with their hooked ends in two gaps at the top. Each end has a face on
# one side and a slope on the other: the left stop's face holds the gear turning counter-clockwise and its slope rides over the teeth turning
# clockwise; the right stop is its mirror image. Each pivot stands on the line along which the tooth pushes the face, a little outside it, so a
# pushed face draws the stop deeper in. A light spring and the stop's weight keep each end down in its gap. With both down the gear is locked.
# The operator lifts one stop or the other with a rocker hung above the gear (a hand lever on a damped spring, moved over about half a second),
# whose beam passes under a pin on each stop: tilted one way it lifts the left stop and the gear goes round counter-clockwise a tooth for each
# to-and-fro; tilted the other way it lifts the right stop and the gear goes clockwise. Generator: opencode-runs/batch11/gen239.py.
number: 239
slug: spur-gear-stops
name: An arrangement of stops for a spur-gear
brown: "An arrangement of stops for a spur-gear."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 14
  floor: false
bodies:
  - id: gear
    shape: part
    pos: [0, 0, 0]
    friction: 0.15
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 4.0, inner: 0.4, y: [-0.5, 0.5]}
      - {kind: poly, points: [[3.6683, -0.4829], [4.9726, -0.5226], [4.9726, 0.5226], [3.6683, 0.4829]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.4184, 1.4159], [4.5677, 2.0337], [4.0451, 2.9389], [2.9354, 2.2524]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.2524, 2.9354], [2.9389, 4.0451], [2.0337, 4.5677], [1.4159, 3.4184]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.4829, 3.6683], [0.5226, 4.9726], [-0.5226, 4.9726], [-0.4829, 3.6683]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.4159, 3.4184], [-2.0337, 4.5677], [-2.9389, 4.0451], [-2.2524, 2.9354]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9354, 2.2524], [-4.0451, 2.9389], [-4.5677, 2.0337], [-3.4184, 1.4159]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6683, 0.4829], [-4.9726, 0.5226], [-4.9726, -0.5226], [-3.6683, -0.4829]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.4184, -1.4159], [-4.5677, -2.0337], [-4.0451, -2.9389], [-2.9354, -2.2524]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.2524, -2.9354], [-2.9389, -4.0451], [-2.0337, -4.5677], [-1.4159, -3.4184]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.4829, -3.6683], [-0.5226, -4.9726], [0.5226, -4.9726], [0.4829, -3.6683]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.4159, -3.4184], [2.0337, -4.5677], [2.9389, -4.0451], [2.2524, -2.9354]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9354, -2.2524], [4.0451, -2.9389], [4.5677, -2.0337], [3.4184, -1.4159]], y: [-0.5, 0.5], collide: 1}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.4, y: [-0.8, 0.8], color: "#cfc6b4"}
  - id: stop_l
    shape: part
    pos: [-7.2521, 0, 3.6968]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-0.7206, 4.087], [-1.0245, 5.8104], [-2.6785, 5.2569]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[-7.1136, 3.2687], [-7.3906, 4.125], [-1.8196, 5.9269], [-1.5427, 5.0706]], y: [-1.0, -0.5]}
      - {kind: disc, center: [-7.2521, 3.6968], radius: 0.8, inner: 0.3, y: [-1.0, -0.5]}
      - {kind: rod, from: [-3.922, -0.6, 4.774], to: [-3.922, -2.0, 4.774], radius: 0.3, capsule: true, collide: 2, color: "#6b5a44"}
  - id: stop_r
    shape: part
    pos: [7.2521, 0, 3.6968]
    friction: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[0.7206, 4.087], [1.0245, 5.8104], [2.6785, 5.2569]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[7.1136, 3.2687], [7.3906, 4.125], [1.8196, 5.9269], [1.5427, 5.0706]], y: [-1.0, -0.5]}
      - {kind: disc, center: [7.2521, 3.6968], radius: 0.8, inner: 0.3, y: [-1.0, -0.5]}
      - {kind: rod, from: [3.922, -0.6, 4.774], to: [3.922, -2.0, 4.774], radius: 0.3, capsule: true, collide: 2, color: "#6b5a44"}
  - id: selector
    shape: part
    pos: [0, 0, 10.0]
    friction: 0.05
    color: "#a39780"
    pieces:
      - {kind: poly, points: [[-6.0, 3.724], [6.0, 3.724], [6.0, 4.324], [-6.0, 4.324]], y: [-1.9, -1.1], collide: 1}
      - {kind: poly, points: [[-0.4, 10.0], [0.4, 10.0], [0.4, 4.024], [-0.4, 4.024]], y: [-1.9, -1.1]}
      - {kind: poly, points: [[0.35, 10.0], [-0.35, 10.0], [-0.35, 14.0], [0.35, 14.0]], y: [-1.9, -1.1]}
      - {kind: disc, center: [0, 14.0], radius: 0.6, y: [-2.0, -1.0], color: "#6b5a44"}
  - 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.4, color: "#8f8a80"}   # the gear's arbor
      - {kind: rod, from: [-7.2521, -1.1, 3.6968], to: [-7.2521, 2.4, 3.6968], radius: 0.3, color: "#8f8a80"}
      - {kind: rod, from: [7.2521, -1.1, 3.6968], to: [7.2521, 2.4, 3.6968], radius: 0.3, color: "#8f8a80"}
      - {kind: rod, from: [0, -2.0, 10.0], to: [0, 2.4, 10.0], radius: 0.3, color: "#8f8a80"}   # the selector's stud
      - {kind: poly, points: [[-10, -6.5], [10, -6.5], [10, 15.5], [-10, 15.5]], y: [1.2, 2.4], color: "#b9b09c"}   # the plate behind
joints:
  - {id: j_gear, type: hinge, body: gear, axis: [0, -1, 0], damping: 0.0005}   # the one driven joint; +: counter-clockwise as seen
  - {id: j_stop_l, type: hinge, body: stop_l, axis: [0, -1, 0], range: [0, 0.5], stiffness: 0.05, springref: -0.2, damping: 0.0002}   # +: lifted
  - {id: j_stop_r, type: hinge, body: stop_r, axis: [0, -1, 0], range: [-0.5, 0], stiffness: 0.05, springref: 0.2, damping: 0.0002}   # -: lifted
  - {id: j_sel, type: hinge, body: selector, axis: [0, -1, 0], range: [-0.37, 0.37], stiffness: 20, springref: 0, damping: 10}   # damped: moved over about half a second, as by hand; -: lifts the left stop
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_gear, kind: velocity, rpm: 0, swing: {amplitude: 0.39, hz: 0.5}, kv: 20, max_torque: 30}
# The operator: both stops down at the start; the right one lifted at 1.5 s, the left one instead at 7.5 s, both down again at 12.5 s.
hand:
  - {t: 1.5, springref: {j_sel: 0.32}}
  - {t: 7.5, springref: {j_sel: -0.32}}
  - {t: 12.5, springref: {j_sel: 0}}
checks:
  - {type: position, joint: j_gear, min: -0.08, max: 0.08, settle_s: 0.2, window_s: 1.3}   # both stops down: the gear is held both ways
  - {type: turning, joint: j_gear, direction: -1, min_mean: 0.18, slow: 0.2, min_fraction: 0.2, settle_s: 2.5, window_s: 5}   # right stop lifted: clockwise, a tooth (p/2 per s) each to-and-fro
  - {type: clicks, joint: j_stop_l, lift: 0.06, min: 2, settle_s: 2.5, window_s: 5}
  - {type: turning, joint: j_gear, direction: 1, min_mean: 0.18, slow: 0.2, min_fraction: 0.2, settle_s: 8.5, window_s: 4}   # left stop lifted: counter-clockwise
  - {type: clicks, joint: j_stop_r, lift: 0.06, min: 2, settle_s: 8.5, window_s: 4}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, 4.5], position: [0, -80.0, 6.0], fov: 34}
display:
  output: j_gear
  labels: {j_gear: "Spur-gear (driver)", j_stop_l: "Left stop", j_stop_r: "Right stop", j_sel: "Selector"}
  lever: {joint: j_sel, label: "Stops", states: {"Both down (locked)": 0, "Right stop lifted (turns clockwise)": 0.32, "Left stop lifted (turns counter-clockwise)": -0.32}}
  proof: {label: "Stops out of contact", sub: "the gear swings freely both ways"}

