# No. 374 (Brown 1868): "Rotary motion of shaft from treadle by means of an endless band running from a roller on the treadle to an eccentric on the shaft."
#
# Reading of the figure (cm, gravity on; Brown's elevation): the shaft runs through the eccentric (7 cm, its centre 3.5 cm
# from the shaft), and carries a flywheel behind it (Brown's dotted circle). The endless band goes round the eccentric and round the
# roller on the treadle below, which is pivoted at the right. The treadle is the one driven joint, worked by the foot: it presses
# the treadle down (press-only, never lifts it) through the half-turn in which the eccentric is going down, timed by the shaft's
# own position (an operator who feels the machine: feet.timed on j_s), and lets it rise for the other half, when the eccentric lifts
# the band, the roller and the treadle with it and the flywheel carries the shaft past both dead points. The shaft starts at rest
# with the eccentric level with it, and works against a light viscous load. The band, taut under the treadle's weight, is modelled
# as a stiff loop free to move and turn in the plane, touching the eccentric and the roller only.
# Generator: opencode-runs/batch12/gen374.py.
number: 374
slug: treadle-band-eccentric
name: A treadle turning a shaft by a band on an eccentric
brown: "Rotary motion of shaft from treadle by means of an endless band running from a roller on the treadle to an eccentric on the shaft."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 16
  floor: false
bodies:
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    density: 30.0
    friction: 0.08
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [-3.5, 0.0], radius: 7.0, y: [-1.0, 1.0], collide: 1}   # the eccentric
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-1.2, 1.2], collide: 0, color: "#6f6a62"}   # the shaft's eye in it
      - {kind: rod, from: [0, -1.3, 0], to: [0, 4.5, 0], radius: 0.9, collide: 0, color: "#8f8a80"}   # the shaft
      - {kind: disc, center: [0, 0], radius: 7.0, inner: 4.6, y: [1.6, 3.4], collide: 0, density: 20000, color: "#8f8a80"}   # the flywheel (Brown's dotted circle)
      - {kind: disc, center: [0, 0], radius: 1.7, y: [1.6, 2.4], collide: 0, density: 7800, color: "#8f8a80"}
      - {kind: rod, from: [1.5285, 2.0, 0.4728], to: [6.5918, 2.0, 2.0391], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [0.3548, 2.0, 1.5602], to: [1.53, 2.0, 6.7282], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-1.1738, 2.0, 1.0873], to: [-5.0618, 2.0, 4.6891], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-1.5285, 2.0, -0.4728], to: [-6.5918, 2.0, -2.0391], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-0.3548, 2.0, -1.5602], to: [-1.53, 2.0, -6.7282], radius: 0.35, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [1.1738, 2.0, -1.0873], to: [5.0618, 2.0, -4.6891], radius: 0.35, collide: 0, color: "#8f8a80"}
  - id: band_x
    shape: part
    pos: [-3.5, 0, 0.0]
    mass: 0.01
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [-3.5, -0.2, 0.0], to: [-3.5, 0.2, 0.0], radius: 0.05, collide: 0}
  - id: band_z
    shape: part
    mount: band_x
    pos: [-3.5, 0, 0.0]
    mass: 0.01
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [-3.5, -0.2, 0.0], to: [-3.5, 0.2, 0.0], radius: 0.05, collide: 0}
  - id: band
    shape: part
    mount: band_z
    pos: [-3.5, 0, 0.0]
    mass: 0.01
    friction: 0.08
    color: "#6b5a44"
    pieces:
      - {kind: band, center: [-3.5, 0.0], r: [7.15, 7.6], a: [0.2191, 2.9225], y: [-0.8, 0.8], slices: 48, collide: 2}   # round the eccentric
      - {kind: band, center: [-3.5, -23.0], r: [2.15, 2.6], a: [2.9225, 6.5023], y: [-0.8, 0.8], slices: 24, collide: 2}   # round the roller
      - {kind: rod, from: [3.6986, 0, 1.6033], to: [-1.1818, 0, -22.4837], radius: 0.225, collide: 0}   # the straight runs
      - {kind: rod, from: [-10.6986, 0, 1.6033], to: [-5.8182, 0, -22.4837], radius: 0.225, collide: 0}
  - id: treadle
    shape: part
    pos: [11.2, 0, -27.0]
    mass: 0.05
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[11.3838, -26.3246], [-20.2484, -16.8881], [-20.6422, -18.3355], [11.0162, -27.6754]], y: [-2.6, -1.4], collide: 0}   # the treadle
      - {kind: disc, center: [11.2, -27.0], radius: 1.1, y: [-2.8, -1.2], collide: 0, color: "#8f8a80"}   # its pivot
      - {kind: disc, center: [11.2, -27.0], radius: 0.4, y: [-2.9, -1.1], collide: 0, color: "#55504a"}
      - {kind: rod, from: [-3.5, -2.6, -23.0], to: [-3.5, 1.6, -23.0], radius: 0.35, collide: 0, color: "#8f8a80"}   # the roller's pin
      - {kind: poly, points: [[-4.0, -23.0], [-3.0, -23.0], [-3.0, -24.2], [-4.0, -24.2]], y: [1.1, 1.6], collide: 0}   # its back cheek
  - id: roller
    shape: part
    mount: treadle
    pos: [-3.5, 0, -23.0]
    mass: 0.01
    friction: 0.08
    color: "#d8ceba"
    pieces:
      - {kind: disc, center: [-3.5, -23.0], radius: 2.0, y: [-1.0, 1.0], collide: 1}
      - {kind: disc, center: [-3.5, -23.0], radius: 0.5, y: [-1.1, 1.1], collide: 0, color: "#55504a"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.2, 4.5], [1.2, 4.5], [1.2, -1.2], [-1.2, -1.2]], y: [4.5, 5.5], collide: 0}   # the shaft's bearing, behind
      - {kind: poly, points: [[10.2, -27.4], [12.2, -27.4], [12.8, -30.0], [9.6, -30.0]], y: [-3.4, -0.4], collide: 0}   # the treadle's stand
joints:
  - {id: j_s, type: hinge, body: shaft, axis: [0, 1, 0], damping: 0.004}   # the shaft; + : its left side goes down
  - {id: j_bx, type: slide, body: band_x, axis: [1, 0, 0], damping: 0.002}
  - {id: j_bz, type: slide, body: band_z, axis: [0, 0, 1], damping: 0.002}
  - {id: j_br, type: hinge, body: band, axis: [0, 1, 0], damping: 0.0005}
  - {id: j_t, type: hinge, body: treadle, axis: [0, -1, 0], damping: 0.002}   # the treadle (the one driven joint); + : the roller goes down
  - {id: j_ro, type: hinge, body: roller, axis: [0, 1, 0], damping: 0.0002}
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_s, shape: sin, gain: 1, offset: -1.5708}}, max_torque: 5.0}
checks:
  - {type: advance, joint: j_s, beat: j_t, expect: -3.1416, tol: 0.05, settle_s: 6, window_s: 9}   # the shaft goes half a turn to each down or up stroke of the treadle (one turn a down-and-up)
  - {type: monotonic, joint: j_s, direction: -1, max_back: 0.05, settle_s: 0.0, window_s: 15}   # from rest it goes one way only
  - {type: turning, joint: j_s, direction: -1, min_mean: 6.0, min_fraction: 0.9, settle_s: 6.0, window_s: 9}   # and keeps turning, over both dead points every turn
  - {type: penetration, max: 0.0015, settle_s: 0.5}
camera: {target: [-3.0, 0, -13.0], position: [-3.0, -115.0, -9.5], fov: 27}
display:
  output: j_s
  labels: {j_t: "Treadle (driver)", j_s: "Shaft", j_br: "Band"}

