# No. 159 (Brown 1868): "A modification of 158, a cord and pulley being substituted for the connecting rod."
#
# Reading of the figure (cm, gravity on, Brown's elevation): the flywheel (a disk) turns on its standard at the left, with a crank-pin
# 3.6 cm from its shaft. A cord from the crank-pin goes up over a guide pulley hung above, between the wheel and the treadle, and down
# to the treadle, which is pivoted on its standard at the right; the treadle hangs on the cord by its own weight. The foot (the one
# driven joint, press-only) presses the treadle down through the half-turn in which the crank-pin is coming up toward the pulley, timed
# by the wheel's own position (an operator who feels the machine: feet.timed on j_d), and lets it rise for the other half, when the
# pin draws the cord back and lifts the treadle; the flywheel carries the wheel past both dead points. The wheel works against a light
# viscous load. A cord only pulls: this is why the foot, not a clock, must time the stroke (a swing-driven treadle loses step, see STATUS).
# Generator: opencode-runs/batch15/gen159b.py.
number: 159
slug: treadle-cord-pulley-flywheel
name: A cord and pulley in place of the treadle's connecting-rod
brown: "A modification of 158, a cord and pulley being substituted for the connecting rod."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 16.0
  floor: false
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 0]
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [0, 0], radius: 9.0, y: [-0.8, 0.8], density: 7800.0, color: "#cfc6b4"}   # the flywheel (a disk, as Brown)
      - {kind: disc, center: [0, 0], radius: 1.2, y: [-1.0, 1.0], color: "#6f6a62"}
      - {kind: rod, from: [0, -1.0, 0], to: [0, 3.0, 0], radius: 0.7, collide: 0, color: "#8f8a80"}   # its shaft
      - {kind: rod, from: [-3.3572, -2.8000000000000003, 1.2996], to: [-3.3572, -0.8, 1.2996], radius: 0.35, collide: 0, color: "#8f8a80"}   # the crank-pin
      - {kind: disc, center: [-3.3572, 1.2996], radius: 0.75, y: [-2.9000000000000004, -2.6], color: "#8f8a80"}
  - id: treadle
    shape: part
    pos: [31.0, 0, -11.0]
    mass: 0.15
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[31.1251, -11.7902], [-5.4193, -17.5782], [-5.6696, -15.9979], [30.8749, -10.2098]], y: [-1.2, 1.2], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [14.2093, -2.8000000000000003, -13.6594], to: [14.2093, -1.2, -13.6594], radius: 0.35, collide: 0, color: "#8f8a80"}   # the cord's eye
      - {kind: disc, center: [14.2093, -13.6594], radius: 0.8, y: [-2.9000000000000004, -2.6], color: "#8f8a80"}
      - {kind: disc, center: [31.0, -11.0], radius: 1.3, y: [-1.6, 1.6], color: "#8f8a80"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-16.0, -25.0], [40.0, -25.0], [40.0, -24.0], [-16.0, -24.0]], y: [-4.0, 5.0], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-4.5, -24.0], [4.5, -24.0], [2.0, -21.0], [1.2, 0.0], [-1.2, 0.0], [-2.0, -21.0]], y: [2.2, 3.4], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[26.5, -24.0], [35.5, -24.0], [32.6, -11.0], [29.4, -11.0]], y: [1.4, 2.6], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[9.4, 15.5], [10.6, 15.5], [10.6, 23.5], [9.4, 23.5]], y: [1.0, 2.0], collide: 0, color: "#cfc6b4"}
      - {kind: disc, center: [10.0, 15.5], radius: 4.0, y: [-2.8000000000000003, -1.6], color: "#a39d90"}   # the guide pulley
      - {kind: rod, from: [10.0, -2.2, 15.5], to: [10.0, 1.0, 15.5], radius: 0.35, collide: 0, color: "#6f6a62"}
joints:
  - {id: j_d, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.006}   # the flywheel; + : clockwise as drawn
  - {id: j_t, type: hinge, body: treadle, axis: [0, -1, 0], damping: 0.0005, range: [-0.6, 0.6]}   # the treadle (the one driven joint); + : the foot end goes down
ropes:
  - {id: cord, from: {body: disk, at: [-3.3572, -2.2, 1.2996]}, over: {center: [10.0, -2.2, 15.5], radius: 4.0, axis: y, side: [10.0, -2.2, 22.5]}, to: {body: treadle, at: [14.2093, -2.2, -13.6594]}, width: 0.9, thickness: 0.7, color: "#5a4a38", section: round}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_t, kind: feet, feet: {joints: [j_t], sign: [1], force: 1.0, timed: {joint: j_d, shape: sin, gain: 1, offset: -1.5708}}, max_torque: 5.0}
checks:
  - {type: advance, joint: j_d, beat: j_t, expect: 3.1416, tol: 0.05, settle_s: 4, window_s: 11}   # the wheel goes half a turn to each down or up stroke of the treadle (the cord kept taut by the treadle's weight)
  - {type: monotonic, joint: j_d, direction: 1, max_back: 0.05, settle_s: 0.0, window_s: 15}   # from rest it goes one way only
  - {type: turning, joint: j_d, direction: 1, min_mean: 5.0, min_fraction: 0.9, settle_s: 4, window_s: 11}   # and keeps turning, over both dead points every turn
  - {type: penetration, max: 0.0015, settle_s: 0.5}
camera: {target: [12.0, 0, -3.0], position: [12.0, -130.0, -1.0], fov: 30}
display:
  output: j_d
  labels: {j_t: "Treadle (driver)", j_d: "Flywheel"}

