# No. 158 (Brown 1868): "Reciprocating curvilinear motion of the treadle gives a circular motion to the disk. A crank may be substituted for the disk."
#
# Model (cm, a plan: no gravity): the treadle, a lever pivoted at the left and rocked to and fro by the foot (the one driven joint: a swing of +-17.7 degrees, 0.5 a second, taken from a soft drive), carries a connecting-rod (21.5 cm) to the crank-pin of the disk, 2.5 cm out on a
# weighted flywheel (7 cm). The four-bar closed by two real pin joints turns the disk right round once for each swing to and fro of the treadle; the treadle's dead points (the rod in line with the crank) are passed by the wheel's weight.
# Generator: opencode-runs/batch11/gen158.py.
number: 158
slug: treadle-connecting-rod-flywheel
name: A treadle turning a disk through a connecting-rod
brown: "Reciprocating curvilinear motion of the treadle gives a circular motion to the disk. A crank may be substituted for the disk."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 16.0
  floor: false
  gravity: 0
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 0]
    density: 12000.0
    friction: 0.05
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [0, -0.6, 0], to: [0, 4.0, 0], radius: 0.9, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0, 0], radius: 7.0, inner: 5.4, y: [-0.6, 0.8], color: "#8f8a80"}
      - {kind: disc, center: [0, 0], radius: 1.5, y: [-0.6, 0.8], color: "#8f8a80"}
      - {kind: poly, points: [[-0.4, 0.0], [-0.4, 6.0], [0.4, 6.0], [0.4, 0.0]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: poly, points: [[-0.2, 0.3464], [4.9962, 3.3464], [5.3962, 2.6536], [0.2, -0.3464]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: poly, points: [[0.2, 0.3464], [5.3962, -2.6536], [4.9962, -3.3464], [-0.2, -0.3464]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: poly, points: [[0.4, 0.0], [0.4, -6.0], [-0.4, -6.0], [-0.4, -0.0]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: poly, points: [[0.2, -0.3464], [-4.9962, -3.3464], [-5.3962, -2.6536], [-0.2, 0.3464]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: poly, points: [[-0.2, -0.3464], [-5.3962, 2.6536], [-4.9962, 3.3464], [0.2, 0.3464]], y: [0.0, 0.6], collide: 0, color: "#a39d90"}
      - {kind: rod, from: [-2.4708, -3.2, -0.3812], to: [-2.4708, 0.0, -0.3812], radius: 0.3, collide: 0, color: "#8f8a80"}
  - id: conrod
    shape: part
    pos: [-2.4708, 0, -0.3812]
    mount: disk
    mass: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [-2.4708, -2.6, -0.3812], to: [1.981, -2.6, -21.4153], radius: 0.3, color: "#b8ad97"}
      - {kind: disc, center: [-2.4708, -0.3812], radius: 0.8, y: [-2.9, -2.3000000000000003], color: "#b8ad97"}
      - {kind: disc, center: [1.981, -21.4153], radius: 0.8, y: [-2.9, -2.3000000000000003], color: "#b8ad97"}
  - id: treadle
    shape: part
    pos: [-7.0, 0, -22.0]
    mass: 0.3
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[-7.052, -21.2017], [9.9121, -20.0972], [10.0161, -21.6938], [-6.948, -22.7983]], y: [-1.6, -0.8], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [1.981, -3.1, -21.4153], to: [1.981, -0.8, -21.4153], radius: 0.3, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [-7.0, -22.0], radius: 1.4, y: [-1.8, -0.6], color: "#8f8a80"}
      - {kind: poly, points: [[6.3675, -19.5263], [10.4589, -19.2599], [10.6668, -22.4531], [6.5754, -22.7195]], y: [-2.4, -0.4], collide: 0, color: "#b8ad97"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-14.0, -28.5], [16.0, -28.5], [16.0, -27.5], [-14.0, -27.5]], y: [-3.5, 5.0], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-1.0, -27.5], [1.0, -27.5], [1.0, -1.0], [-1.0, -1.0]], y: [3.4, 4.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-7.9, -27.5], [-6.1, -27.5], [-6.1, -23.0], [-7.9, -23.0]], y: [0.0, 1.0], collide: 0, color: "#cfc6b4"}
joints:
  - {id: j_d, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.0005}   # the disk; + : clockwise
  - {id: j_r, type: hinge, body: conrod, axis: [0, 1, 0], damping: 0.0002}
  - {id: j_t, type: hinge, body: treadle, axis: [0, -1, 0], damping: 0.0002}   # the treadle (the one driven joint); + : counter-clockwise (its far end rises)
pins:
  - {"id": "pin_b", "a": "conrod", "b": "treadle", "at": [1.981, -2.6, -21.4153]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_t, kind: velocity, rpm: 0, swing: {amplitude: 0.3096, hz: 0.5}, kv: 0.3, max_torque: 3.0}
checks:
  - {type: advance, joint: j_d, beat: j_t, expect: 3.1416, tol: 0.05, settle_s: 4, window_s: 11}   # the disk goes round once to each swing to and fro of the treadle (half a turn a beat)
  - {type: monotonic, joint: j_d, direction: 1, max_back: 0.05, settle_s: 3, window_s: 12.5}   # and always the one way
  - {type: follow, out: j_t, in: j_d, expect: 0.2557, tol: 0.02, min_r2: 0.99, settle_s: 5.5, window_s: 0.5}   # the treadle follows the disk through the four-bar's kinematics (a swing: not uniform, but fixed)
  - {type: follow, out: j_t, in: j_d, expect: 0.2557, tol: 0.02, min_r2: 0.99, settle_s: 7.5, window_s: 0.5}   # the treadle follows the disk through the four-bar's kinematics (a swing: not uniform, but fixed)
  - {type: follow, out: j_t, in: j_d, expect: 0.2557, tol: 0.02, min_r2: 0.99, settle_s: 9.5, window_s: 0.5}   # the treadle follows the disk through the four-bar's kinematics (a swing: not uniform, but fixed)
  - {type: follow, out: j_t, in: j_d, expect: 0.2557, tol: 0.02, min_r2: 0.99, settle_s: 11.5, window_s: 0.5}   # the treadle follows the disk through the four-bar's kinematics (a swing: not uniform, but fixed)
  - {type: follow, out: j_t, in: j_d, expect: 0.2557, tol: 0.02, min_r2: 0.99, settle_s: 13.5, window_s: 0.5}   # the treadle follows the disk through the four-bar's kinematics (a swing: not uniform, but fixed)
  - {type: position, joint: j_t, min: -0.3596, max: 0.3596, settle_s: 0.3, window_s: 15}
  - {type: penetration, max: 0.0015, settle_s: 0.5}
camera: {target: [2.0, 0, -9.0], position: [2.0, -112.0, -9.0], fov: 34}
display:
  output: j_d
  labels: {j_t: "Treadle (driver)", j_d: "Disk", j_r: "Connecting-rod"}
  proof: {label: "Rod unpinned", sub: "the treadle swings but the disk stands"}

