# No. 233 (Brown 1868): "Shows two different kinds of stops for a lantern-wheel."
#
# Model (cm, gravity on): a wheel with 12 staves (radius 0.6) on a circle of 8, turned to and fro by hand +-0.628 rad at 0.5 Hz (the one driven
# joint, a servo of limited torque, like a hand). On the right a click, pivoted at [17.0, 6.0], lies by its weight on a rest with its end between two staves:
# turning the wheel counter-clockwise the staves lift it by its underside and it drops behind each; turning it back, the stave behind meets its end and the
# wheel stops. On the left a roller on a weighted lever lies between two staves: it rides up over each stave and settles the wheel between them (a detent).
# So the wheel goes round two staves to each to-and-fro and never back by more than the click's play. Generator: opencode-runs/batch11/gen233.py.
number: 233
slug: lantern-wheel-stops
name: Two kinds of stops for a lantern-wheel
brown: "Shows two different kinds of stops for a lantern-wheel."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 12.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 10.0, inner: 0.6, y: [0.2, 0.8]}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.6, y: [-0.6, 1.0], color: "#cfc6b4"}
      - {kind: rod, from: [7.5505, 0.5, 2.6437], to: [7.5505, -1.3, 2.6437], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [5.2171, 0.5, 6.0648], to: [5.2171, -1.3, 6.0648], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [1.4857, 0.5, 7.8608], to: [1.4857, -1.3, 7.8608], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-2.6437, 0.5, 7.5505], to: [-2.6437, -1.3, 7.5505], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-6.0648, 0.5, 5.2171], to: [-6.0648, -1.3, 5.2171], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-7.8608, 0.5, 1.4857], to: [-7.8608, -1.3, 1.4857], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-7.5505, 0.5, -2.6437], to: [-7.5505, -1.3, -2.6437], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-5.2171, 0.5, -6.0648], to: [-5.2171, -1.3, -6.0648], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [-1.4857, 0.5, -7.8608], to: [-1.4857, -1.3, -7.8608], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [2.6437, 0.5, -7.5505], to: [2.6437, -1.3, -7.5505], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [6.0648, 0.5, -5.2171], to: [6.0648, -1.3, -5.2171], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
      - {kind: rod, from: [7.8608, 0.5, -1.4857], to: [7.8608, -1.3, -1.4857], radius: 0.6, capsule: true, collide: 1, color: "#8f8a80"}
  - id: click
    shape: part
    pos: [17.0, 0, 6.0]
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: poly, points: [[5.0912, 5.0912], [17.0, 5.3], [17.0, 6.7], [6.5054, 6.5054]], y: [-1.1, -0.3], collide: 2}   # the click
      - {kind: disc, center: [17.0, 6.0], radius: 0.8, inner: 0.2, y: [-1.1, -0.3]}
  - id: roller_lever
    shape: part
    pos: [-16.0, 0, 3.0]
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-15.8142, 2.5358], [-16.1858, 3.4642], [-5.2053, 7.8042], [-4.8709, 6.9686]], y: [-1.9, -1.3]}   # the lever
      - {kind: poly, points: [[-15.8328, 2.5822], [-16.1672, 3.4178], [-18.7482, 2.3311], [-18.451, 1.5884]], y: [-1.9, -1.3]}
      - {kind: disc, center: [-16.0, 3.0], radius: 0.8, inner: 0.2, y: [-1.9, -1.3]}
      - {kind: disc, center: [-5.0381, 7.3864], radius: 0.7, y: [-1.9, -1.3]}
      - {kind: rod, from: [-5.0381, -1.4, 7.3864], to: [-5.0381, -0.2, 7.3864], radius: 0.2, color: "#8f8a80"}   # the roller's pin
  - id: roller
    shape: part
    pos: [-5.0381, 0, 7.3864]
    mount: roller_lever
    friction: 0.3
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [-5.0381, -1.0, 7.3864], to: [-5.0381, -0.5, 7.3864], radius: 1.8, capsule: true, collide: 2}   # the roller
      - {kind: disc, center: [-5.0381, 7.3864], radius: 0.35, y: [-1.25, -0.25], color: "#8f8a80"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.2, 0], to: [0, 2.4, 0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.4, -12.2], [1.4, -12.2], [0.9, 0], [-0.9, 0]], y: [1.2, 2.4]}   # the standard
      - {kind: poly, points: [[16.1, -12.2], [17.9, -12.2], [17.6, 6.0], [16.4, 6.0]], y: [-0.2, 0.6]}   # the click's post
      - {kind: rod, from: [17.0, -1.2, 6.0], to: [17.0, 0.6, 6.0], radius: 0.2, color: "#8f8a80"}
      - {kind: poly, points: [[-16.9, -12.2], [-15.1, -12.2], [-15.4, 3.0], [-16.6, 3.0]], y: [-1.2, -0.4]}   # the roller-lever's post
      - {kind: rod, from: [-16.0, -2.0, 3.0], to: [-16.0, -0.4, 3.0], radius: 0.2, color: "#8f8a80"}
      - {kind: poly, points: [[-19, -13.4], [20, -13.4], [20, -12.2], [-19, -12.2]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.002}   # the one driven joint; +: counter-clockwise as seen
  - {id: j_click, type: hinge, body: click, axis: [0, -1, 0], damping: 0.0005, range: [-0.5, 0]}   # 0: on its rest; -: lifted
  - {id: j_lever, type: hinge, body: roller_lever, axis: [0, -1, 0], damping: 0.0005, range: [-0.5, 0.5]}
  - {id: j_roller, type: hinge, body: roller, axis: [0, -1, 0], 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.6283, hz: 0.5}, kv: 20, max_torque: 20}
checks:
  - {type: turning, joint: j_wheel, direction: 1, min_mean: 0.49, slow: 0.2, min_fraction: 0.35, settle_s: 1.0, window_s: 10}   # two staves (2 x 2 pi / 12) to each to-and-fro of 2 s: 0.5236 rad/s; one would be 0.2618
  - {type: clicks, joint: j_click, lift: 0.08, min: 9, settle_s: 1.0, window_s: 10}   # the click drops behind two staves each to-and-fro
  - {type: clicks, joint: j_lever, lift: 0.08, min: 9, settle_s: 1.0, window_s: 10}   # and the roller rides over them
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.25, settle_s: 1, window_s: 10.5}   # back no more than the hand overshoots the click (12 degrees)
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [1.0, 0, -1.0], position: [1.0, -100.0, 3.0], fov: 34}
display:
  output: j_wheel
  labels: {j_wheel: "Lantern-wheel (driver)", j_click: "Click", j_lever: "Roller-lever"}
  proof: {label: "Click out of contact", sub: "the wheel is only rocked to and fro"}

