# No. 92 (Brown 1868): "Ordinary crank motion."
#
# Model (cm): the crank-shaft and its wheel (8 cm, the one driven joint, 30 turns a minute, clockwise in the
# view) carry the crank-pin 4 cm from the centre. The connecting-rod (13 cm) turns on the pin and is pinned to
# the cross-head, which slides between fixed guides. The cross-head moves 8 cm to and fro, twice the throw, but
# not harmonically: x = r cos t + sqrt(L^2 - r^2 sin^2 t), the rod's obliquity hurrying it through the half-stroke
# nearer the crank. Generator: opencode-runs/batch8/gen092.py.
number: 92
slug: ordinary-crank-motion
name: A crank, a connecting-rod and a cross-head in guides
brown: "Ordinary crank motion."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 50
  solver: PGS
  duration_s: 10
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    mass: 2.0
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, -1.0, 0], to: [0, 3.0, 0], radius: 0.8, color: "#8f8a80"}   # the crank-shaft
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.8, y: [-0.7, 0.7]}   # the wheel's hub
      - {kind: disc, center: [0, 0], radius: 8.0, inner: 7.1, y: [-0.6, 0.6]}   # its rim
      - {kind: poly, points: [[1.3874, 0.3969], [6.6586, 3.267], [6.1586, 4.133], [1.0374, 1.0031]], y: [-0.5, 0.5]}   # a spoke
      - {kind: poly, points: [[0.35, 1.4], [0.5, 7.4], [-0.5, 7.4], [-0.35, 1.4]], y: [-0.5, 0.5]}   # a spoke
      - {kind: poly, points: [[-1.0374, 1.0031], [-6.1586, 4.133], [-6.6586, 3.267], [-1.3874, 0.3969]], y: [-0.5, 0.5]}   # a spoke
      - {kind: poly, points: [[-1.3874, -0.3969], [-6.6586, -3.267], [-6.1586, -4.133], [-1.0374, -1.0031]], y: [-0.5, 0.5]}   # a spoke
      - {kind: poly, points: [[-0.35, -1.4], [-0.5, -7.4], [0.5, -7.4], [0.35, -1.4]], y: [-0.5, 0.5]}   # a spoke
      - {kind: poly, points: [[1.0374, -1.0031], [6.1586, -4.133], [6.6586, -3.267], [1.3874, -0.3969]], y: [-0.5, 0.5]}   # a spoke
      - {kind: disc, center: [4.0, 0], radius: 0.4, y: [-1.6, -0.5], color: "#8f8a80"}   # the crank-pin
  - id: rod
    shape: part
    pos: [4.0, 0, 0]
    mount: wheel
    mass: 0.4
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [4.0, 0], radius: 0.9, inner: 0.4, y: [-1.5, -0.9]}   # the rod's big end
      - {kind: poly, points: [[4.7, -0.5], [16.4, -0.35], [16.4, 0.35], [4.7, 0.5]], y: [-1.45, -0.95]}   # the connecting-rod
      - {kind: disc, center: [17.0, 0], radius: 0.7, inner: 0.3, y: [-1.5, -0.9]}   # its small end
  - id: crosshead
    shape: part
    pos: [17.0, 0, 0]
    mass: 0.8
    color: "#9a8c74"
    pieces:
      - {kind: poly, points: [[14.8, -1.5], [19.2, -1.5], [19.2, 1.5], [14.8, 1.5]], y: [-0.85, 0.6]}   # the cross-head
      - {kind: disc, center: [17.0, 0], radius: 0.3, y: [-1.6, -0.85], color: "#8f8a80"}   # its pin
      - {kind: rod, from: [19.2, 0, 0], to: [31.0, 0, 0], radius: 0.5}   # the piston-rod
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.6, -10], [1.6, -10], [1.1, 0], [-1.1, 0]], y: [1.8, 2.8]}   # the shaft's standard, behind
      - {kind: poly, points: [[6.800000000000001, 1.55], [22.2, 1.55], [22.2, 2.4], [6.800000000000001, 2.4]], y: [-0.9, 1.4]}   # the upper guide
      - {kind: poly, points: [[6.800000000000001, -2.4], [22.2, -2.4], [22.2, -1.55], [6.800000000000001, -1.55]], y: [-0.9, 1.4]}   # the lower guide
      - {kind: poly, points: [[6.800000000000001, -2.4], [22.2, -2.4], [22.2, 2.4], [6.800000000000001, 2.4]], y: [1.4, 1.8]}   # the guides' back plate
      - {kind: poly, points: [[16.0, -10], [18.0, -10], [18.0, -2.4], [16.0, -2.4]], y: [1.4, 2.2]}   # their post
      - {kind: poly, points: [[-10, -11], [29.0, -11], [29.0, -10], [-10, -10]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_s, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_r, type: hinge, body: rod, axis: [0, 1, 0], damping: 0.001}   # the rod on the crank-pin
  - {id: j_x, type: slide, body: crosshead, axis: [1, 0, 0], damping: 0.05}   # the cross-head in its guides; + : to the right
pins:
  - {id: pin_x, a: rod, b: crosshead, at: [17.0, 0, 0]}
driver: {joint: j_s, kind: velocity, rpm: 30, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_x, in: j_s, expect: -0.03995, tol: 0.0008, min_r2: 0.995, settle_s: 2.4722, window_s: 0.0556}   # mid-stroke: r a radian
  - {type: follow, out: j_x, in: j_s, expect: -0.03452, tol: 0.00069, min_r2: 0.995, settle_s: 2.2222, window_s: 0.0556}   # the crank at 45 deg: faster than harmonic
  - {type: follow, out: j_x, in: j_s, expect: -0.02198, tol: 0.00044, min_r2: 0.995, settle_s: 2.7222, window_s: 0.0556}   # ... and at 135 deg: slower (the obliquity)
  - {type: position, joint: j_x, min: -8.05, max: 0.05, settle_s: 0.5, window_s: 9}   # the stroke: twice the throw
camera: {target: [10.5, 0, -1.5], position: [10.5, -85, 5], fov: 34}
display:
  output: j_x
  labels: {j_s: "Crank-wheel (driver)", j_r: "Connecting-rod", j_x: "Cross-head"}
  proof: {label: "Rod unpinned", sub: "the crank turns but the cross-head stands"}

