# No. 145 (Brown 1868): "Reciprocating curvilinear motion of the beam gives a continuous rotary motion to the crank and fly-wheel. The small standard at the right, to which is attached one end of the lever with which the beam is connected by the connecting-rod, has a horizontal reciprocating rectilinear movement."
#
# Model (cm, no gravity; a plan): a beam pivoted at its middle is rocked by a rod from its right end to a lever (pivoted on the frame); the other arm of the lever is joined by a link to a small standard that slides to and fro
# on the bed: the standard is the one driven joint (3 cm each way, 0.5 strokes a second). The left end of the beam works a connecting-rod (16 cm) on the pin of a 2.862 cm crank carrying a fly-wheel; the crank is turned by the rod alone.
# The beam swings -12.0 to +12.8 degrees, which is just what carries the crank through its two dead points (the fly-wheel takes it over them), so the crank turns once for every full stroke of the standard, clockwise.
# The rod is a sleeve with a stiff spring (a real connecting-rod yields a little at the dead points): the beam's stroke is 5% beyond the crank's reach. Generator: opencode-runs/batch10/gen145.py.
number: 145
slug: beam-crank-flywheel
name: A beam turning a crank and fly-wheel
brown: "Reciprocating curvilinear motion of the beam gives a continuous rotary motion to the crank and fly-wheel. The small standard at the right, to which is attached one end of the lever with which the beam is connected by the connecting-rod, has a horizontal reciprocating rectilinear movement."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 8.0
  floor: false
  gravity: 0
bodies:
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-25.7807, -29.0], [39.0, -29.0], [39.0, -27.0], [-25.7807, -27.0]], y: [0.0, 3.0], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-1.4, -27.0], [1.4, -27.0], [1.4, -0.8], [-1.4, -0.8]], y: [0.0, 1.4], collide: 0, color: "#c3baa6"}
      - {kind: disc, center: [0.0, 0.0], radius: 1.2, inner: 0.0, y: [-0.2, 2.0], color: "#8f8a80"}
      - {kind: poly, points: [[20.0, -27.0], [22.0, -27.0], [22.0, -9.0], [20.0, -9.0]], y: [0.0, 2.8], collide: 0, color: "#c3baa6"}
      - {kind: disc, center: [21.0, -8.0], radius: 1.0, inner: 0.0, y: [1.6, 3.0], color: "#8f8a80"}
      - {kind: poly, points: [[-14.9807, -27.0], [-12.5807, -27.0], [-12.5807, -16.9078], [-14.9807, -16.9078]], y: [0.0, 3.2], collide: 0, color: "#c3baa6"}
      - {kind: poly, points: [[24.0, -17.6], [38.0, -17.6], [38.0, -16.6], [24.0, -16.6]], y: [1.8, 4.2], collide: 0, color: "#c3baa6"}
  - id: standard
    shape: part
    pos: [29.0, 0, -15.0]
    mass: 0.2
    color: "#b3a88f"
    pieces:
      - {kind: poly, points: [[27.4, -16.6], [30.6, -16.6], [30.6, -13.4], [27.4, -13.4]], y: [2.4, 3.6], collide: 0, color: "#a89a7e"}
      - {kind: disc, center: [29.0, -15.0], radius: 0.7, inner: 0.3, y: [2.4, 3.8]}
      - {kind: poly, points: [[30.6, -15.4], [36.0, -15.4], [36.0, -14.6], [30.6, -14.6]], y: [2.8, 3.4], collide: 0, color: "#a89a7e"}
  - id: beam
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[-15.5, 0.8], [15.5, 0.8], [15.5, -0.8], [-15.5, -0.8]], y: [0.0, 0.8], collide: 0, color: "#c9bfa6"}
      - {kind: disc, center: [0.0, 0.0], radius: 1.6, inner: 0.4, y: [-0.2, 1.0]}
      - {kind: disc, center: [-14.0, 0.0], radius: 1.0, inner: 0.3, y: [0.0, 0.8]}
      - {kind: disc, center: [14.0, 0.0], radius: 1.0, inner: 0.3, y: [0.0, 0.8]}
  - id: rod_r
    shape: part
    pos: [14.0, 0, 0.0]
    mount: beam
    mass: 0.1
    color: "#d2c8ae"
    pieces:
      - {kind: poly, points: [[14.45, 0.0], [14.45, -8.0], [13.55, -8.0], [13.55, 0.0]], y: [1.0, 1.7], collide: 0, color: "#d2c8ae"}
      - {kind: disc, center: [14.0, 0.0], radius: 0.8, inner: 0.3, y: [1.0, 1.7]}
      - {kind: disc, center: [14.0, -8.0], radius: 0.8, inner: 0.3, y: [1.0, 1.7]}
  - id: lever
    shape: part
    pos: [21.0, 0, -8.0]
    mass: 0.2
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[21.0, -8.6], [14.0, -8.6], [14.0, -7.4], [21.0, -7.4]], y: [1.8, 2.5], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[21.6, -8.0], [21.6, -15.0], [20.4, -15.0], [20.4, -8.0]], y: [1.8, 2.5], collide: 0}
      - {kind: disc, center: [21.0, -8.0], radius: 1.6, inner: 0.5, y: [1.7, 2.6]}
      - {kind: disc, center: [14.0, -8.0], radius: 0.8, inner: 0.3, y: [1.8, 2.5]}
      - {kind: disc, center: [21.0, -15.0], radius: 0.8, inner: 0.3, y: [1.8, 2.5]}
  - id: link
    shape: part
    pos: [21.0, 0, -15.0]
    mount: lever
    mass: 0.1
    color: "#c9bfa6"
    pieces:
      - {kind: poly, points: [[21.0, -14.55], [29.0, -14.55], [29.0, -15.45], [21.0, -15.45]], y: [2.6, 3.3], collide: 0, color: "#c9bfa6"}
      - {kind: disc, center: [21.0, -15.0], radius: 0.7, inner: 0.3, y: [2.6, 3.3]}
      - {kind: disc, center: [29.0, -15.0], radius: 0.7, inner: 0.3, y: [2.6, 3.3]}
  - id: rod_a
    shape: part
    pos: [-14.0, 0, 0.0]
    mount: beam
    mass: 0.1
    color: "#d2c8ae"
    pieces:
      - {kind: poly, points: [[-13.5562, -0.0742], [-15.0081, -8.7536], [-15.8958, -8.6051], [-14.4438, 0.0742]], y: [1.0, 1.7], collide: 0, color: "#d2c8ae"}
      - {kind: poly, points: [[-13.5562, -0.0742], [-15.0081, -8.7536], [-15.8958, -8.6051], [-14.4438, 0.0742]], y: [1.0, 1.7], collide: 0}
      - {kind: disc, center: [-14.0, 0.0], radius: 0.8, inner: 0.3, y: [1.0, 1.7]}
  - id: rod_b
    shape: part
    pos: [-14.0, 0, 0.0]
    mount: rod_a
    mass: 0.1
    color: "#b3a88f"
    pieces:
      - {kind: poly, points: [[-14.9167, -7.1467], [-16.3686, -15.8261], [-16.9111, -15.7353], [-15.4592, -7.056]], y: [1.1, 1.6], collide: 0, color: "#b3a88f"}
      - {kind: disc, center: [-16.6399, -15.7807], radius: 0.8, inner: 0.3, y: [1.0, 1.7]}
  - id: crank
    shape: part
    pos: [-13.7807, 0, -15.9078]
    mass: 1.2
    color: "#c9bfa6"
    pieces:
      - {kind: disc, center: [-13.7807, -15.9078], radius: 9.5, inner: 1.2, y: [2.2, 3.0], color: "#c9bfa6"}
      - {kind: disc, center: [-13.7807, -15.9078], radius: 7.9, inner: 1.0, y: [2.2, 3.0], color: "#d4cab0"}
      - {kind: disc, center: [-13.7807, -15.9078], radius: 1.5, inner: 0.4, y: [1.9, 3.3], color: "#8f8a80"}
      - {kind: poly, points: [[-13.8074, -16.5072], [-16.6665, -16.3801], [-16.6132, -15.1813], [-13.7541, -15.3084]], y: [1.0, 2.2], collide: 0, color: "#a89a7e"}
      - {kind: disc, center: [-16.6399, -15.7807], radius: 0.9, inner: 0.3, y: [1.0, 2.2]}
      - {kind: disc, center: [-13.7807, -15.9078], radius: 1.4, inner: 0.3, y: [1.0, 2.2]}
      - {kind: rod, from: [-13.7807, 0.4, -15.9078], to: [-13.7807, 3.5, -15.9078], radius: 0.5, collide: 0, color: "#8f8a80"}
joints:
  - {id: j_s, type: slide, body: standard, axis: [1, 0, 0], damping: 0.05}   # the driven standard; + : to the right
  - {id: j_b, type: hinge, body: beam, axis: [0, 1, 0], damping: 0.002}      # + : clockwise (the right end down)
  - {id: j_r, type: hinge, body: rod_r, axis: [0, 1, 0], damping: 0.002}
  - {id: j_v, type: hinge, body: lever, axis: [0, 1, 0], damping: 0.002}
  - {id: j_k, type: hinge, body: link, axis: [0, 1, 0], damping: 0.002}
  - {id: j_a, type: hinge, body: rod_a, axis: [0, 1, 0], damping: 0.002}
  - {id: j_t, type: slide, body: rod_b, axis: [-0.165, 0, -0.9863], range: [-0.6, 0.6], stiffness: 40.0, springref: 0, damping: 1.0}   # the sleeve of the connecting-rod
  - {id: j_c, type: hinge, body: crank, axis: [0, 1, 0], damping: 0.001}   # the crank and fly-wheel; + : clockwise
pins:
  - {id: pin_b, a: rod_r, b: lever, at: [14.0, 0, -8.0]}
  - {id: pin_s, a: link, b: standard, at: [29.0, 0, -15.0]}
  - {id: pin_p, a: rod_b, b: crank, at: [-16.6399, 0, -15.7807]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_s, kind: velocity, rpm: 0, swing: {amplitude: 0.03, hz: 0.5}, kv: 60000.0, max_torque: 600.0}
checks:
  - {type: turning, joint: j_c, direction: 1, min_mean: 2.5133, slow: 0.3, min_fraction: 0.8, settle_s: 1.5, window_s: 6.0}
  - {type: monotonic, joint: j_c, direction: 1, max_back: 0.3, settle_s: 1.5, window_s: 6.0}
  - {type: advance, joint: j_c, beat: j_b, expect: 3.1416, tol: 0.06, settle_s: 1.5, window_s: 6.0}   # half a turn of the crank to every swing of the beam
  - {type: position, joint: j_s, min: -3.6, max: 3.6, settle_s: 0.0, window_s: 7.5}
camera: {target: [7.6096, 0, -13.0], position: [7.6096, -106.0, -13.0], fov: 34}
display:
  output: j_c
  labels: {j_s: "Standard (driver)", j_b: "Beam", j_c: "Crank and fly-wheel", j_v: "Lever"}
  proof: {label: "Connecting-rod removed", sub: "the beam rocks but the crank stands"}

