# No. 230 (Brown 1868): "Circular motion into ditto. The connecting-rods are so arranged that when one pair of connected links is over the dead point, or at
# the extremity of its stroke, the other is at right angles; continuous motion is thus insured without a fly-wheel."
#
# Model (cm, gravity on): two parallel shafts 20 apart, one over the other. Each has a crank (throw 3) at the front end and a disc-crank (the same throw) at
# the back, a quarter-turn on from the crank. A connecting-rod joins the two cranks and another the two disc-cranks; each rod turns on the upper pin and is pinned
# to the lower one. The upper shaft is turned (30 rpm, the only driven joint); the lower shaft follows it turn for turn, at a steady speed all round: when one
# rod is over its dead point (the cranks in line with it) the other is at right angles and carries the lower shaft past it. No fly-wheel.
# Generator: opencode-runs/batch11/gen230.py.
number: 230
slug: two-cranks-at-right-angles
name: Circular motion into ditto by two cranks at right angles
brown: "Circular motion into ditto. The connecting-rods are so arranged that when one pair of connected links is over the dead point, or at the extremity of its stroke, the other is at right angles; continuous motion is thus insured without a fly-wheel."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 50
  solver: PGS
  duration_s: 8
  floor: false
bodies:
  - id: upper
    shape: part
    pos: [0, 0, 0.0]
    mass: 1.5
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, -7.2, 0.0], to: [0, 8.4, 0.0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.1, -1.1], [3.0, -0.9], [3.0, 0.9], [-1.1, 1.1]], y: [-6.3, -5.7]}   # the crank
      - {kind: disc, center: [3.0, 0.0], radius: 0.9, y: [-6.3, -5.7]}   # its boss
      - {kind: rod, from: [3.0, -7.0, 0.0], to: [3.0, -6.0, 0.0], radius: 0.35, color: "#8f8a80"}   # its pin
      - {kind: disc, center: [0, 0.0], radius: 5.2, y: [5.7, 6.3]}   # the disc-crank
      - {kind: rod, from: [0, 6.3, 3.0], to: [0, 7.3, 3.0], radius: 0.35, color: "#8f8a80"}   # its pin, a quarter-turn on
  - id: lower
    shape: part
    pos: [0, 0, -20.0]
    mass: 1.5
    color: "#cfc3a8"
    pieces:
      - {kind: rod, from: [0, -7.2, -20.0], to: [0, 8.4, -20.0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.1, -21.1], [3.0, -20.9], [3.0, -19.1], [-1.1, -18.9]], y: [-6.3, -5.7]}   # the crank
      - {kind: disc, center: [3.0, -20.0], radius: 0.9, y: [-6.3, -5.7]}   # its boss
      - {kind: rod, from: [3.0, -7.0, -20.0], to: [3.0, -6.0, -20.0], radius: 0.35, color: "#8f8a80"}   # its pin
      - {kind: disc, center: [0, -20.0], radius: 5.2, y: [5.7, 6.3]}   # the disc-crank
      - {kind: rod, from: [0, 6.3, -17.0], to: [0, 7.3, -17.0], radius: 0.35, color: "#8f8a80"}   # its pin, a quarter-turn on
  - id: rod_a
    shape: part
    pos: [3.0, 0, 0.0]
    mount: upper
    mass: 0.3
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [3.0, 0.0], radius: 0.8, inner: 0.35, y: [-6.95, -6.3500000000000005]}   # its eye on the upper pin
      - {kind: poly, points: [[2.65, -0.7], [3.35, -0.7], [3.35, -19.3], [2.65, -19.3]], y: [-6.9, -6.4]}   # the rod
      - {kind: disc, center: [3.0, -20.0], radius: 0.8, inner: 0.35, y: [-6.95, -6.3500000000000005]}   # its eye on the lower pin
  - id: rod_b
    shape: part
    pos: [0.0, 0, 3.0]
    mount: upper
    mass: 0.3
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [0.0, 3.0], radius: 0.8, inner: 0.35, y: [6.65, 7.25]}   # its eye on the upper pin
      - {kind: poly, points: [[-0.35, 2.3], [0.35, 2.3], [0.35, -16.3], [-0.35, -16.3]], y: [6.7, 7.2]}   # the rod
      - {kind: disc, center: [0.0, -17.0], radius: 0.8, inner: 0.35, y: [6.65, 7.25]}   # its eye on the lower pin
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.4, -26.0], [1.4, -26.0], [1.4, 1.4], [-1.4, 1.4]], y: [8.4, 9.4]}   # the standard behind, carrying both shafts
      - {kind: poly, points: [[-6, -27.0], [6, -27.0], [6, -26.0], [-6, -26.0]], y: [-8.0, 10.0], color: "#b9b09c"}   # the bed
joints:
  - {id: j_u, type: hinge, body: upper, axis: [0, 1, 0], damping: 0.002}   # the one driven joint
  - {id: j_l, type: hinge, body: lower, axis: [0, 1, 0], damping: 0.002}
  - {id: j_ra, type: hinge, body: rod_a, axis: [0, 1, 0], damping: 0.001}   # the rods on the upper pins
  - {id: j_rb, type: hinge, body: rod_b, axis: [0, 1, 0], damping: 0.001}
pins:
  - {id: pin_a, a: rod_a, b: lower, at: [3.0, -6.65, -20.0]}
  - {id: pin_b, a: rod_b, b: lower, at: [0, 6.95, -17.0]}
driver: {joint: j_u, kind: velocity, rpm: 30, kv: 20.0, max_torque: 20}
checks:
  - {type: ratio, out: j_l, in: j_u, expect: 1.0, tol: 0.01, settle_s: 1, window_s: 6.5}   # turn for turn
  - {type: ratio_range, out: j_l, in: j_u, min: 0.97, max: 1.03, min_swing: 0.0, settle_s: 1, window_s: 6.5, slices: 24}   # steady all round, through both dead points
camera: {target: [0.0, 0, -16.0], position: [-58.0, -66.0, 14.0], fov: 34}
display:
  output: j_l
  labels: {j_u: "Upper shaft (driver)", j_l: "Lower shaft"}
  proof: {label: "Both rods unpinned below", sub: "the upper shaft turns, the lower shaft stands"}

