# No. 156 (Brown 1868): "Circular motion into variable alternating rectilinear motion, by the wrist or crank-pin on the rotating disk working in the slot of the bell-crank or elbow-lever."
#
# Model (cm, a plan: no gravity): the disk (the one driven joint, 12 turns a minute, clockwise in the view) carries a crank-pin 3.5 cm from its centre in the slot of one arm of a bell-crank pivoted 9 cm away;
# the pivot is farther from the disk's centre than the pin's radius, so the bell-crank rocks through +-23 degrees, and its other arm, 12 cm long, carries a pin working in a slot across a sliding bar, which is carried
# 4.7 cm each way. The bar's speed is not uniform (it is quickest when the pin passes the line of centres on the near side and slow as the bell-crank comes to the end of its swing): variable. All by real contact in the slots.
# Generator: opencode-runs/batch11/gen156.py.
number: 156
slug: crank-pin-slot-bell-crank
name: Circular motion into variable alternating rectilinear motion
brown: "Circular motion into variable alternating rectilinear motion, by the wrist or crank-pin on the rotating disk working in the slot of the bell-crank or elbow-lever."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 12.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: 5.1, inner: 4.3, 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, 4.7], [0.45, 4.7], [0.45, -0.0]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[-0.0, 0.45], [4.7, 0.45], [4.7, -0.45], [0.0, -0.45]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[0.45, 0.0], [0.45, -4.7], [-0.45, -4.7], [-0.45, -0.0]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[0.0, -0.45], [-4.7, -0.45], [-4.7, 0.45], [-0.0, 0.45]], y: [0.0, 0.6], collide: 0, color: "#d9cfb6"}
      - {kind: rod, from: [3.5, -1.6, 0.0], to: [3.5, 0.0, 0.0], radius: 0.4, collide: 1, capsule: true, color: "#8f8a80"}
  - id: crank
    shape: part
    pos: [9.0, 0, 0.0]
    mass: 0.4
    friction: 0.05
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[-4.9, 0.52], [4.7, 0.52], [4.7, 1.07], [-4.9, 1.07]], y: [-1.6, -0.2], collide: 2, color: "#a89a7e"}
      - {kind: poly, points: [[-4.9, -1.07], [4.7, -1.07], [4.7, -0.52], [-4.9, -0.52]], y: [-1.6, -0.2], collide: 2, color: "#a89a7e"}
      - {kind: poly, points: [[-5.4, -1.07], [-4.9, -1.07], [-4.9, 1.07], [-5.4, 1.07]], y: [-1.6, -0.2], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[4.7, -1.07], [5.2, -1.07], [5.2, 1.07], [4.7, 1.07]], y: [-1.6, -0.2], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[4.7, -0.5], [9.0, -0.5], [9.0, 0.5], [4.7, 0.5]], y: [-0.2, 0.4], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [9.0, -1.6, 0.0], to: [9.0, 2.6, 0.0], radius: 0.9, collide: 0, color: "#8f8a80"}
      - {kind: poly, points: [[8.45, -12.6], [9.55, -12.6], [9.55, 0.0], [8.45, 0.0]], y: [0.8, 1.6], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [9.0, 0.8, -12.0], to: [9.0, 3.2, -12.0], radius: 0.4, collide: 1, capsule: true, color: "#8f8a80"}
  - id: bar
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-5.0, -15.1], [23.0, -15.1], [23.0, -14.2], [-5.0, -14.2]], y: [1.6, 3.4], collide: 0, color: "#b8ad97"}
      - {kind: poly, points: [[7.93, -14.2], [8.48, -14.2], [8.48, -9.8], [7.93, -9.8]], y: [1.9, 3.4], collide: 2, color: "#b8ad97"}
      - {kind: poly, points: [[9.52, -14.2], [10.07, -14.2], [10.07, -9.8], [9.52, -9.8]], y: [1.9, 3.4], collide: 2, color: "#b8ad97"}
      - {kind: poly, points: [[7.93, -9.8], [10.07, -9.8], [10.07, -9.3], [7.93, -9.3]], y: [1.9, 3.4], collide: 0, color: "#b8ad97"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-12.0, -22.5], [24.0, -22.5], [24.0, -21.5], [-12.0, -21.5]], y: [-3.5, 5.0], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-1.0, -21.5], [1.0, -21.5], [1.0, -1.0], [-1.0, -1.0]], y: [3.4, 4.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[8.1, -21.5], [9.9, -21.5], [9.9, -1.0], [8.1, -1.0]], y: [3.4, 4.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-6.5, -16.6], [-5.5, -16.6], [-5.5, -15.1], [-6.5, -15.1]], y: [1.6, 3.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[23.5, -16.6], [24.5, -16.6], [24.5, -15.1], [23.5, -15.1]], y: [1.6, 3.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-6.5, -16.6], [24.5, -16.6], [24.5, -15.6], [-6.5, -15.6]], y: [1.2, 3.8], 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_c, type: hinge, body: crank, axis: [0, 1, 0], damping: 0.01}   # the bell-crank; + : clockwise (arm 1's tip rises)
  - {id: j_b, type: slide, body: bar, axis: [1, 0, 0], damping: 0.3}   # the sliding bar; + : to the right
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_d, kind: velocity, rpm: 12, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_b, in: j_c, expect: -0.1196, tol: 0.0048, min_r2: 0.995, settle_s: 2.0, window_s: 1.0}
  - {type: follow, out: j_b, in: j_c, expect: -0.1196, tol: 0.0048, min_r2: 0.995, settle_s: 7.0, window_s: 1.0}
  - {type: follow, out: j_c, in: j_d, expect: 0.2535, tol: 0.0304, min_r2: 0.97, settle_s: 1.5, window_s: 0.9}
  - {type: follow, out: j_c, in: j_d, expect: 0.2535, tol: 0.0304, min_r2: 0.97, settle_s: 6.5, window_s: 0.9}
  - {type: position, joint: j_c, min: -0.4394, max: 0.4394, settle_s: 0.3, window_s: 11.2}
  - {type: position, joint: j_b, min: -5.0667, max: 5.0667, settle_s: 0.3, window_s: 11.2}
  - {type: penetration, max: 0.0015, settle_s: 0.5}
camera: {target: [6.0, 0, -8.0], position: [6.0, -68.0, -8.0], fov: 34}
display:
  output: j_b
  labels: {j_d: "Disk (driver)", j_c: "Bell-crank", j_b: "Sliding bar"}
  proof: {label: "Crank-pin out of its slot", sub: "the disk turns but the bell-crank and the bar stand"}

