# No. 89 (Brown 1868): "An eccentric generally used on the crank-shaft for communicating the reciprocating
# rectilinear motion to the valves of steam engines, and sometimes used for pumping."
#
# Model (cm): the crank-shaft (the one driven joint, 30 turns a minute, clockwise in the view) carries an
# eccentric, a 3.2 cm disc whose centre is 1.5 cm from the shaft's. The strap embraces the eccentric and turns on
# it (its hinge about the eccentric's centre); the eccentric rod, forged with the strap, is pinned 16 cm away to
# the valve-rod, which slides in fixed guides to the steam-chest. The valve-rod is moved 3 cm to and fro,
# twice the eccentricity, as by a crank of that length: x = e cos(t) + sqrt(L^2 - e^2 sin^2(t)).
# Generator: opencode-runs/batch8/gen089.py.
number: 89
slug: eccentric-strap-rod
name: An eccentric, its strap and rod working a valve-rod
brown: "An eccentric generally used on the crank-shaft for communicating the reciprocating rectilinear motion to the valves of steam engines, and sometimes used for pumping."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 50
  solver: PGS
  duration_s: 10
  floor: false
bodies:
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    mass: 1.0
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, -2.4, 0], to: [0, 3.0, 0], radius: 0.8, color: "#8f8a80"}   # the crank-shaft
      - {kind: disc, center: [1.5, 0], radius: 3.2, y: [-0.8, 0.8]}   # the eccentric
  - id: strap
    shape: part
    pos: [1.5, 0, 0]
    mount: shaft
    mass: 0.4
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [1.5, 0], radius: 4.1000000000000005, inner: 3.25, y: [-0.9, 0.9]}   # the strap
      - {kind: poly, points: [[5.3, -0.7], [17.5, -0.45], [17.5, 0.45], [5.3, 0.7]], y: [-0.4, 0.4]}   # the eccentric rod
      - {kind: disc, center: [17.5, 0], radius: 0.8, y: [-0.6, 0.6]}   # its eye
  - id: valve_rod
    shape: part
    pos: [17.5, 0, 0]
    mass: 0.5
    color: "#9a8c74"
    pieces:
      - {kind: disc, center: [17.5, 0], radius: 0.55, y: [-1.2, 1.2]}   # the pin
      - {kind: rod, from: [17.5, 0, 0], to: [33.5, 0, 0], radius: 0.4}   # the valve-rod
      - {kind: poly, points: [[33.5, -1.6], [38.5, -1.6], [38.5, 1.0], [33.5, 1.0]], y: [-1.2, 1.2]}   # the slide-valve
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.6, -9], [1.6, -9], [1.1, 0], [-1.1, 0]], y: [1.6, 2.6]}   # the shaft's standard, behind
      - {kind: poly, points: [[24.5, 0.55], [27.5, 0.55], [27.5, 1.4], [24.5, 1.4]], y: [-1, 1]}   # the valve-rod's guide
      - {kind: poly, points: [[24.5, -1.4], [27.5, -1.4], [27.5, -0.55], [24.5, -0.55]], y: [-1, 1]}
      - {kind: poly, points: [[25.5, -9], [26.5, -9], [26.5, -1.4], [25.5, -1.4]], y: [1.0, 1.8]}   # its post, behind
      - {kind: poly, points: [[29.5, -3.2], [45.5, -3.2], [45.5, 3.0], [29.5, 3.0]], y: [2.0, 2.8], color: "#a8b4b8"}   # the steam-chest, behind
      - {kind: poly, points: [[29.5, -4.0], [45.5, -4.0], [45.5, -3.2], [29.5, -3.2]], y: [-1.6, 2.8], color: "#a8b4b8"}   # its valve-face
      - {kind: poly, points: [[-6, -10], [47.5, -10], [47.5, -9], [-6, -9]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_s, type: hinge, body: shaft, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_e, type: hinge, body: strap, axis: [0, 1, 0], damping: 0.001}   # the strap on the eccentric
  - {id: j_v, type: slide, body: valve_rod, axis: [1, 0, 0], damping: 0.05}   # + : to the right
pins:
  - {id: pin_v, a: strap, b: valve_rod, at: [17.5, 0, 0]}
driver: {joint: j_s, kind: velocity, rpm: 30, kv: 2.0, max_torque: 20}
checks:
  - {type: follow, out: j_v, in: j_s, expect: -0.015, tol: 0.0003, min_r2: 0.995, settle_s: 2.45, window_s: 0.1}   # mid-stroke: e a radian, as a crank
  - {type: follow, out: j_v, in: j_s, expect: 0.015, tol: 0.0003, min_r2: 0.995, settle_s: 3.45, window_s: 0.1}   # ... and back
  - {type: position, joint: j_v, min: -3.05, max: 0.05, settle_s: 0.5, window_s: 9}   # the throw: twice the eccentricity
camera: {target: [14.75, 0, -2], position: [14.75, -78, 6], fov: 34}
display:
  output: j_v
  labels: {j_s: "Crank-shaft (driver)", j_e: "Strap", j_v: "Valve-rod"}
  proof: {label: "Rod unpinned", sub: "the eccentric turns but the valve-rod stands"}

