# No. 153 (Brown 1868): "Circular motion into alternating rectilinear motion. The studs on the rotating disk strike the projection on the under side of the horizontal bar, moving it one direction. The return motion is given by means of the bell-crank or elbow-lever, one arm of which is operated upon by the next stud, and the other strikes the stud on the front of the horizontal bar."
#
# Model (cm, no gravity; a plan): the disk (the one driven joint, 20 turns a minute, clockwise in the view) carries a stud 6 cm from its centre in front, which strikes the projection under the horizontal bar and carries it 5.5 cm to the right,
# and a second stud 4.5 cm out, behind the disk, which strikes the arm of a bell-crank pivoted at the right; the other arm of the bell-crank strikes the stud at the back of the bar and brings it back. All by real contact; the bar goes to and from once a turn.
# Generator: opencode-runs/batch10/gen153.py.
number: 153
slug: disk-studs-bar-bell-crank
name: Circular motion into alternating rectilinear motion
brown: "Circular motion into alternating rectilinear motion. The studs on the rotating disk strike the projection on the under side of the horizontal bar, moving it one direction. The return motion is given by means of the bell-crank or elbow-lever, one arm of which is operated upon by the next stud, and the other strikes the stud on the front of the horizontal bar."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 9.0
  floor: false
  gravity: 0
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 0]
    mass: 1.0
    friction: 0.05
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, 0.0, 0], to: [0, 4.0, 0], radius: 0.9, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0, 0], radius: 7.5, inner: 6.7, y: [0.0, 0.6], color: "#d9cfb6"}
      - {kind: disc, center: [0, 0], radius: 1.5, y: [0.0, 0.6], color: "#d9cfb6"}
      - {kind: poly, points: [[-0.45, 0.0], [-0.45, 7.0], [0.45, 7.0], [0.45, 0.0]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[-0.0, 0.45], [7.0, 0.45], [7.0, -0.45], [0.0, -0.45]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[0.45, 0.0], [0.45, -7.0], [-0.45, -7.0], [-0.45, -0.0]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[0.0, -0.45], [-7.0, -0.45], [-7.0, 0.45], [-0.0, 0.45]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: rod, from: [-5.1962, -1.6, 3.0], to: [-5.1962, 0.0, 3.0], radius: 0.45, collide: 1, capsule: true, color: "#8f8a80"}
      - {kind: rod, from: [-3.8971, 0.6, -2.25], to: [-3.8971, 3.2, -2.25], radius: 0.45, collide: 1, capsule: true, color: "#8f8a80"}
  - id: bar
    shape: part
    pos: [0, 0, 0]
    mass: 0.5
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-7.5, 8.6982], [11.5, 8.6982], [11.5, 9.7982], [-7.5, 9.7982]], y: [-1.6, 2.8], collide: 0, color: "#b8ad97"}
      - {kind: poly, points: [[1.55, -0.7], [2.85, -0.7], [2.85, 8.6982], [1.55, 8.6982]], y: [-1.6, -0.2], collide: 2, color: "#a89a7e"}
      - {kind: rod, from: [2.35, 2.0, 8.6982], to: [2.35, 2.0, 5.5], radius: 0.3, collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [2.35, 1.2, 5.0], to: [2.35, 3.0, 5.0], radius: 0.4, collide: 2, capsule: true, color: "#8f8a80"}
  - id: crank
    shape: part
    pos: [8.5, 0, 0.0]
    mass: 0.3
    friction: 0.05
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[8.7878, -0.2778], [3.9254, -5.3135], [3.3499, -4.7578], [8.2122, 0.2778]], y: [1.6, 2.4], collide: 2, color: "#a89a7e"}
      - {kind: poly, points: [[8.309, -0.1978], [2.4833, 5.4273], [2.8653, 5.823], [8.691, 0.1978]], y: [1.6, 2.4], collide: 1, color: "#a89a7e"}
      - {kind: disc, center: [8.5, 0.0], radius: 1.0, y: [1.4, 2.7], color: "#8f8a80"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-11, -12.5], [22, -12.5], [22, -11.5], [-11, -11.5]], y: [-3.5, 5.0], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-1.0, -11.5], [1.0, -11.5], [0.8, -1.0], [-0.8, -1.0]], y: [3.4, 4.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[7.6, -11.5], [9.4, -11.5], [9.2, -1.0], [7.8, -1.0]], y: [2.8, 3.8], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-9.0, -11.5], [-8.0, -11.5], [-8.0, 9.7982], [-9.0, 9.7982]], y: [-1.6, -0.6], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[18.2, -11.5], [19.2, -11.5], [19.2, 9.7982], [18.2, 9.7982]], y: [-1.6, -0.6], collide: 0, color: "#cfc6b4"}
joints:
  - {id: j_d, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_b, type: slide, body: bar, axis: [1, 0, 0], range: [-0.1, 5.975], damping: 1.5}   # the horizontal bar; + : to the right
  - {id: j_c, type: hinge, body: crank, axis: [0, 1, 0], range: [0, 0.8029], damping: 0.05}   # the bell-crank; + : clockwise (arm 2 swings right, back toward the stop)
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_d, kind: velocity, rpm: 20, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_b, in: j_d, expect: 0.0485, tol: 0.0049, min_r2: 0.99, settle_s: 0.725, window_s: 0.2333}
  - {type: follow, out: j_b, in: j_d, expect: 0.0485, tol: 0.0049, min_r2: 0.99, settle_s: 3.725, window_s: 0.2333}
  - {type: follow, out: j_b, in: j_d, expect: 0.0485, tol: 0.0049, min_r2: 0.99, settle_s: 6.725, window_s: 0.2333}
  - {type: follow, out: j_b, in: j_c, expect: 0.066, tol: 0.0099, min_r2: 0.98, settle_s: 1.8, window_s: 0.2}
  - {type: follow, out: j_b, in: j_c, expect: 0.066, tol: 0.0099, min_r2: 0.98, settle_s: 4.8, window_s: 0.2}
  - {type: follow, out: j_b, in: j_c, expect: 0.066, tol: 0.0099, min_r2: 0.98, settle_s: 7.8, window_s: 0.2}
  - {type: position, joint: j_b, min: -0.3, max: 5.875, settle_s: 0.0, window_s: 8.5}
camera: {target: [5, 0, 0.0], position: [-22.0, -88.0, 12.0], fov: 34}
display:
  output: j_b
  labels: {j_d: "Disk (driver)", j_b: "Horizontal bar", j_c: "Bell-crank"}
  proof: {label: "Studs out of contact", sub: "the disk turns but the bar stands"}

