# No. 416 (Brown 1868): "A device for assisting the crank of a treadle motion over the dead-centers. The helical spring, A, has a tendency to move the crank, B, in direction at right-angles to dead-centers."
#
# Model (cm, Brown's front view, no gravity). The fly-wheel carries the crank B (4.6 cm); the connecting-rod takes it down to the treadle, a lever
# on a stud with the rod at its short end and the foot at its long one. The spring A is coiled on a stud to the left and its wire runs to the
# crank-pin: the wire slides out of the coil against the spring (20 N/m, free 6 cm), so it always draws B towards A, at right angles to the
# dead-centers (B straight above or below the shaft, in line with the rod). The foot (the one input, press-only) presses the treadle's long end down
# from each lower dead-center through the half-turn that lifts the rod, timed by the wheel's own position (feet.timed on j_w), and lets it rise
# for the other half. The wheel starts at rest on its lower dead-center, where the foot alone could not start it: the spring draws B off the
# centre, the foot takes it up and the fly-wheel turns on (clockwise as drawn). Generator: opencode-runs/batch13/gen416.py.
number: 416
slug: treadle-crank-spring-over-dead-centers
name: Spring assisting a treadle crank over the dead-centers
brown: "A device for assisting the crank of a treadle motion over the dead-centers. The helical spring, A, has a tendency to move the crank, B, in direction at right-angles to dead-centers."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  duration_s: 16
  floor: false
  gravity: 0
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 0], radius: 8.0, inner: 5.8, y: [-0.4, 1.4]}   # the fly-wheel's heavy rim
      - {kind: disc, center: [0, 0], radius: 5.8, inner: 1.0, y: [0.6, 1.0], color: "#a39d90"}   # its web
      - {kind: disc, center: [0, 0], radius: 1.1, inner: 0.45, y: [-1.2, 1.2], color: "#6f6a60"}   # the hub on the shaft
      - {kind: poly, points: [[0.8, 0.0], [0.8, -4.6], [-0.8, -4.6], [-0.8, 0.0]], y: [-1.2, -0.6], color: "#7d776c"}   # the crank
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-1.2, -0.6], color: "#7d776c"}
      - {kind: disc, center: [0.0, -4.6], radius: 0.8, y: [-1.2, -0.6], color: "#7d776c"}
      - {kind: rod, from: [0.0, -0.6, -4.6], to: [0.0, -2.8, -4.6], radius: 0.28, color: "#5a564e"}   # the crank-pin B
  - id: coil
    shape: part
    pos: [-13.8, 0, -2.7]
    mass: 0.05
    color: "#3d3a35"
    pieces:
      - {kind: rod, from: [-14.6816, -2.4, -3.1719], to: [-14.5995, -2.4, -3.3829], radius: 0.1}   # the spring A, coiled round its stud
      - {kind: rod, from: [-14.5995, -2.4, -3.3829], to: [-14.4661, -2.4, -3.579], radius: 0.1}
      - {kind: rod, from: [-14.4661, -2.4, -3.579], to: [-14.2844, -2.4, -3.7477], radius: 0.1}
      - {kind: rod, from: [-14.2844, -2.4, -3.7477], to: [-14.0603, -2.4, -3.8773], radius: 0.1}
      - {kind: rod, from: [-14.0603, -2.4, -3.8773], to: [-13.8027, -2.4, -3.9571], radius: 0.1}
      - {kind: rod, from: [-13.8027, -2.4, -3.9571], to: [-13.5231, -2.4, -3.9789], radius: 0.1}
      - {kind: rod, from: [-13.5231, -2.4, -3.9789], to: [-13.2347, -2.4, -3.9369], radius: 0.1}
      - {kind: rod, from: [-13.2347, -2.4, -3.9369], to: [-12.9525, -2.4, -3.8286], radius: 0.1}
      - {kind: rod, from: [-12.9525, -2.4, -3.8286], to: [-12.6918, -2.4, -3.655], radius: 0.1}
      - {kind: rod, from: [-12.6918, -2.4, -3.655], to: [-12.4681, -2.4, -3.4205], radius: 0.1}
      - {kind: rod, from: [-12.4681, -2.4, -3.4205], to: [-12.2955, -2.4, -3.1334], radius: 0.1}
      - {kind: rod, from: [-12.2955, -2.4, -3.1334], to: [-12.1863, -2.4, -2.8051], radius: 0.1}
      - {kind: rod, from: [-12.1863, -2.4, -2.8051], to: [-12.1503, -2.4, -2.45], radius: 0.1}
      - {kind: rod, from: [-12.1503, -2.4, -2.45], to: [-12.1938, -2.4, -2.0847], radius: 0.1}
      - {kind: rod, from: [-12.1938, -2.4, -2.0847], to: [-12.3195, -2.4, -1.7274], radius: 0.1}
      - {kind: rod, from: [-12.3195, -2.4, -1.7274], to: [-12.5257, -2.4, -1.3966], radius: 0.1}
      - {kind: rod, from: [-12.5257, -2.4, -1.3966], to: [-12.8065, -2.4, -1.1107], radius: 0.1}
      - {kind: rod, from: [-12.8065, -2.4, -1.1107], to: [-13.1519, -2.4, -0.8866], radius: 0.1}
      - {kind: rod, from: [-13.1519, -2.4, -0.8866], to: [-13.5479, -2.4, -0.739], radius: 0.1}
      - {kind: rod, from: [-13.5479, -2.4, -0.739], to: [-13.9774, -2.4, -0.6792], radius: 0.1}
      - {kind: rod, from: [-13.9774, -2.4, -0.6792], to: [-14.4206, -2.4, -0.7148], radius: 0.1}
      - {kind: rod, from: [-14.4206, -2.4, -0.7148], to: [-14.8562, -2.4, -0.8486], radius: 0.1}
      - {kind: rod, from: [-14.8562, -2.4, -0.8486], to: [-15.2619, -2.4, -1.079], radius: 0.1}
      - {kind: rod, from: [-15.2619, -2.4, -1.079], to: [-15.6165, -2.4, -1.399], radius: 0.1}
      - {kind: rod, from: [-15.6165, -2.4, -1.399], to: [-15.8998, -2.4, -1.7971], radius: 0.1}
      - {kind: rod, from: [-15.8998, -2.4, -1.7971], to: [-16.0948, -2.4, -2.2571], radius: 0.1}
      - {kind: rod, from: [-16.0948, -2.4, -2.2571], to: [-16.1878, -2.4, -2.7591], radius: 0.1}
      - {kind: rod, from: [-16.1878, -2.4, -2.7591], to: [-16.17, -2.4, -3.2804], radius: 0.1}
      - {kind: rod, from: [-16.17, -2.4, -3.2804], to: [-16.0373, -2.4, -3.7962], radius: 0.1}
      - {kind: rod, from: [-16.0373, -2.4, -3.7962], to: [-15.7915, -2.4, -4.2811], radius: 0.1}
      - {kind: rod, from: [-15.7915, -2.4, -4.2811], to: [-15.44, -2.4, -4.7101], radius: 0.1}
      - {kind: rod, from: [-15.44, -2.4, -4.7101], to: [-14.9957, -2.4, -5.0601], radius: 0.1}
      - {kind: rod, from: [-14.9957, -2.4, -5.0601], to: [-14.4764, -2.4, -5.3109], radius: 0.1}
      - {kind: rod, from: [-14.4764, -2.4, -5.3109], to: [-13.9047, -2.4, -5.4466], radius: 0.1}
      - {kind: rod, from: [-13.9047, -2.4, -5.4466], to: [-13.3061, -2.4, -5.4561], radius: 0.1}
      - {kind: rod, from: [-13.3061, -2.4, -5.4561], to: [-12.7086, -2.4, -5.3343], radius: 0.1}
      - {kind: rod, from: [-12.7086, -2.4, -5.3343], to: [-12.1414, -2.4, -5.0823], radius: 0.1}
      - {kind: rod, from: [-12.1414, -2.4, -5.0823], to: [-11.6327, -2.4, -4.7077], radius: 0.1}
      - {kind: rod, from: [-11.6327, -2.4, -4.7077], to: [-11.2093, -2.4, -4.2241], radius: 0.1}
      - {kind: rod, from: [-11.2093, -2.4, -4.2241], to: [-10.8946, -2.4, -3.651], radius: 0.1}
      - {kind: rod, from: [-10.8946, -2.4, -3.651], to: [-10.7072, -2.4, -3.0132], radius: 0.1}
      - {kind: rod, from: [-10.7072, -2.4, -3.0132], to: [-10.6607, -2.4, -2.3389], radius: 0.1}
      - {kind: rod, from: [-10.6607, -2.4, -2.3389], to: [-10.7618, -2.4, -1.6596], radius: 0.1}
      - {kind: rod, from: [-10.7618, -2.4, -1.6596], to: [-11.0104, -2.4, -1.0075], radius: 0.1}
      - {kind: rod, from: [-11.0104, -2.4, -1.0075], to: [-11.3995, -2.4, -0.4149], radius: 0.1}
      - {kind: rod, from: [-11.3995, -2.4, -0.4149], to: [-11.9146, -2.4, 0.0881], radius: 0.1}
      - {kind: rod, from: [-11.9146, -2.4, 0.0881], to: [-12.5351, -2.4, 0.4744], radius: 0.1}
      - {kind: rod, from: [-12.5351, -2.4, 0.4744], to: [-13.2346, -2.4, 0.7222], radius: 0.1}
      - {kind: rod, from: [-13.2346, -2.4, 0.7222], to: [-13.9818, -2.4, 0.8153], radius: 0.1}
      - {kind: rod, from: [-13.9818, -2.4, 0.8153], to: [-14.7426, -2.4, 0.7448], radius: 0.1}
      - {kind: rod, from: [-14.7426, -2.4, 0.7448], to: [-15.4811, -2.4, 0.5092], radius: 0.1}
      - {kind: rod, from: [-15.4811, -2.4, 0.5092], to: [-16.1613, -2.4, 0.1151], radius: 0.1}
      - {kind: rod, from: [-16.1613, -2.4, 0.1151], to: [-16.7492, -2.4, -0.4233], radius: 0.1}
      - {kind: rod, from: [-16.7492, -2.4, -0.4233], to: [-17.2141, -2.4, -1.0843], radius: 0.1}
      - {kind: rod, from: [-17.2141, -2.4, -1.0843], to: [-17.5307, -2.4, -1.8399], radius: 0.1}
      - {kind: rod, from: [-17.5307, -2.4, -1.8399], to: [-17.6798, -2.4, -2.6567], radius: 0.1}
      - {kind: rod, from: [-17.6798, -2.4, -2.6567], to: [-17.6497, -2.4, -3.4975], radius: 0.1}
      - {kind: rod, from: [-17.6497, -2.4, -3.4975], to: [-17.4372, -2.4, -4.3229], radius: 0.1}
      - {kind: rod, from: [-17.4372, -2.4, -4.3229], to: [-17.0476, -2.4, -5.0934], radius: 0.1}
      - {kind: rod, from: [-17.0476, -2.4, -5.0934], to: [-16.4949, -2.4, -5.771], radius: 0.1}
      - {kind: rod, from: [-16.4949, -2.4, -5.771], to: [-15.801, -2.4, -6.321], radius: 0.1}
      - {kind: rod, from: [-15.801, -2.4, -6.321], to: [-14.9954, -2.4, -6.7144], radius: 0.1}
      - {kind: rod, from: [-14.9954, -2.4, -6.7144], to: [-14.1134, -2.4, -6.9284], radius: 0.1}
      - {kind: rod, from: [-14.1134, -2.4, -6.9284], to: [-13.1951, -2.4, -6.9486], radius: 0.1}
      - {kind: rod, from: [-13.1951, -2.4, -6.9486], to: [-12.2829, -2.4, -6.7693], radius: 0.1}
      - {kind: rod, from: [-12.2829, -2.4, -6.7693], to: [-11.4203, -2.4, -6.3941], radius: 0.1}
      - {kind: rod, from: [-11.4203, -2.4, -6.3941], to: [-10.6492, -2.4, -5.8363], radius: 0.1}
      - {kind: rod, from: [-10.6492, -2.4, -5.8363], to: [-10.0082, -2.4, -5.118], radius: 0.1}
      - {kind: rod, from: [-10.0082, -2.4, -5.118], to: [-9.5307, -2.4, -4.2693], radius: 0.1}
      - {kind: rod, from: [-9.5307, -2.4, -4.2693], to: [-9.243, -2.4, -3.3274], radius: 0.1}
      - {kind: disc, center: [-13.8, -2.7], radius: 0.55, inner: 0.2, y: [-2.6, -2.2], color: "#5a564e"}
  - id: wire
    shape: part
    pos: [-13.8, 0, -2.7]
    mount: coil
    mass: 0.01
    color: "#3d3a35"
    pieces:
      - {kind: rod, from: [-13.9783, -2.4, -2.6754], to: [0.0, -2.4, -4.6], radius: 0.08}   # the wire from the spring to the crank-pin B
  - id: conrod
    shape: part
    pos: [0.0, 0, -4.6]
    mount: wheel
    mass: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [0.0, -1.9, -4.6], to: [-1.7548, -1.9, -23.9205], radius: 0.3}   # the connecting-rod
      - {kind: disc, center: [0.0, -4.6], radius: 0.6, inner: 0.28, y: [-2.1999999999999997, -1.5999999999999999]}
      - {kind: disc, center: [-1.7548, -23.9205], radius: 0.6, inner: 0.25, y: [-2.1999999999999997, -1.5999999999999999]}
  - id: treadle
    shape: part
    pos: [-6.7, 0, -19.4]
    mass: 0.3
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[-2.0921, -24.2895], [-16.6326, -10.998], [-15.9579, -10.2599], [-1.4174, -23.5514]], y: [-1.5, -0.7], color: "#a89a7e"}   # the treadle
      - {kind: rod, from: [-1.7548, -1.9, -23.9205], to: [-1.7548, -0.7, -23.9205], radius: 0.25, color: "#6f6a60"}
      - {kind: disc, center: [-6.7, -19.4], radius: 0.6, inner: 0.25, y: [-1.7, -0.5], color: "#6f6a60"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [0, 0], radius: 0.45, y: [-1.3, 2.4]}   # the wheel's shaft
      - {kind: disc, center: [-6.7, -19.4], radius: 0.25, y: [-1.8, 0.4]}   # the treadle's stud
      - {kind: disc, center: [-13.8, -2.7], radius: 0.2, y: [-2.8, 0.4]}   # the spring's stud
joints:
  - {id: j_w, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.05, frictionloss: 0.01}   # the fly-wheel; + : anticlockwise as drawn (it runs clockwise)
  - {id: j_a, type: hinge, body: coil, axis: [0, -1, 0], damping: 0.0005}   # the spring's coil swings on its stud as B goes round
  - {id: j_s, type: slide, body: wire, axis: [0.9907, 0, -0.1364], stiffness: 20, springref: -7.9302, damping: 0.05}   # the wire drawn out of the coil: the spring's stretch (+ : longer)
  - {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.02}   # the treadle (the foot's: the one driven joint); + : anticlockwise (the foot end down)
pins:
  - {id: pin_s, a: wire, b: wheel, at: [0.0, -2.4, -4.6]}   # the wire's eye on the crank-pin B
  - {id: pin_b, a: conrod, b: treadle, at: [-1.7548, -1.9, -23.9205]}
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: 3.5, timed: {joint: j_w, shape: sin, gain: 1, offset: 3.1416}}, max_torque: 3}
checks:
  - {type: monotonic, joint: j_w, direction: -1, max_back: 0.05, settle_s: 0.0, window_s: 15}   # from rest on the lower dead-center the wheel goes one way only
  - {type: turning, joint: j_w, direction: -1, min_mean: 3.0, min_fraction: 0.9, settle_s: 3.0, window_s: 12}   # and keeps turning, over both dead-centers every turn
  - {type: penetration, max: 0.002}
camera: {target: [-6, 0, -11.5], position: [-6, -95, -11.5], fov: 24}
display:
  output: j_w
  labels: {j_t: "Treadle (the foot)", j_w: "Fly-wheel", j_s: "Spring A's stretch", j_r: "Connecting-rod"}
  proof: {label: "Rod unpinned", sub: "the foot presses but the wheel stands"}
