# No. 56 (Brown 1868): "Used for throwing in and out of gear the speed-motion on lathes. On depressing the
# lever, the shaft of the large wheel is drawn backward by reason of the slot in which it slides being
# cut eccentrically to the center or fulcrum of the lever."
#
# Model (cm; the drawing plane x-z, depth y): the pinion (14 teeth, module 0.6) is fast on the
# spindle with the stepped cone (the speed-motion, the one motor-driven shaft) on the right; the large
# wheel (40) turns on a shaft whose front end (a journal, r 0.5) slides in a horizontal slot in the
# frame (a slide joint) and lies in a curved slot in the lever. The lever turns on its fulcrum F
# (-4.0, 0.0); the slot is cut on an arc of radius 6.40 about E (-4.0, -5.0), not about F, so turning the lever
# by 0.5 rad moves the slot's crossing with the frame's slot back 1.73 cm, drawing the
# wheel out of gear (whole depth 1.35). The hand works the lever against a spring: down at
# 3 s, up again at 7 s. Generator: opencode-runs/batch7/gen056.py.
number: 56
slug: throw-out-of-gear-lathe
name: Throwing in and out of gear (lathe)
brown: "Used for throwing in and out of gear the speed-motion on lathes. On depressing the lever, the shaft of the large wheel is drawn backward by reason of the slot in which it slides being cut eccentrically to the center or fulcrum of the lever."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 11
  floor: false
bodies:
  - id: carriage
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [0, -3.0, 0], to: [0, 3.0, 0], radius: 0.4}   # the wheel's shaft
      - {kind: rod, from: [0, -3.0, 0], to: [0, -1.2, 0], radius: 0.5, collide: 1, capsule: true}   # its journal in the lever's slot
      - {kind: poly, points: [[-0.8, -0.6], [0.8, -0.6], [0.8, 0.6], [-0.8, 0.6]], y: [2.0, 3.0]}   # the slide-block in the frame's slot
  - id: gear
    shape: part
    mount: carriage
    pos: [0, 0, 0]
    density: 7800
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 11.0, inner: 0.4, y: [-0.4, 0.4]}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.4, y: [-1.0, 1.0]}
      - {kind: disc, center: [0, 7.5], radius: 1.2, y: [-0.42, -0.4], color: "#b9ab8e"}   # a boss (shows it turning)
  - id: spindle
    shape: part
    pos: [16.2, 0, 0]
    density: 7800
    color: "#d8ceba"
    pieces:
      - {kind: rod, from: [16.2, -3.0, 0], to: [16.2, 10.5, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: disc, center: [16.2, 0], radius: 8.0, inner: 0.6, y: [1.5, 3.3], color: "#cfc4a8"}   # the stepped cone
      - {kind: disc, center: [16.2, 0], radius: 6.6, inner: 0.6, y: [3.3, 5.1], color: "#cfc4a8"}
      - {kind: disc, center: [16.2, 0], radius: 5.2, inner: 0.6, y: [5.1, 6.9], color: "#cfc4a8"}
  - id: lever
    shape: part
    pos: [-4.0, 0, 0.0]
    density: 7800
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [-4.0, 0.0], radius: 1.1, y: [-2.6, -1.6]}   # its boss on the fulcrum
      - {kind: band, center: [-4.0, -5.0], r: [4.7631, 8.0431], a: [0.3461, 0.4461], slices: 1, y: [-2.6, -1.6]}   # the slot's closed ends
      - {kind: band, center: [-4.0, -5.0], r: [4.7631, 8.0431], a: [1.7461, 1.8461], slices: 1, y: [-2.6, -1.6]}
      - {kind: band, center: [-4.0, -5.0], r: [4.7631, 5.3631], a: [0.3461, 1.8461], slices: 14, y: [-2.6, -1.6]}   # the cheek round it
      - {kind: band, center: [-4.0, -5.0], r: [7.4431, 8.0431], a: [0.3461, 1.8461], slices: 14, y: [-2.6, -1.6]}
      - {kind: poly, points: [[-4.6, 0], [-3.4, 0], [-4.4, 17], [-5.4, 17]], y: [-2.6, -1.6]}   # the arm up to the handle
      - {kind: rod, from: [-4.9, -2.1, 17], to: [-4.9, -2.1, 21], radius: 0.6}           # the handle
      - {kind: band, center: [-4.0, -5.0], r: [5.3631, 5.8631], a: [0.5461, 1.6461], slices: 14, y: [-2.6, -1.6], collide: 2}   # the slot's inner wall
      - {kind: band, center: [-4.0, -5.0], r: [6.9431, 7.4431], a: [0.5461, 1.6461], slices: 14, y: [-2.6, -1.6], collide: 2}   # the slot's outer wall
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-4.5, 1.0], [4.5, 1.0], [4.5, 2.2], [-4.5, 2.2]], y: [1.9, 3.1]}   # the slot's upper cheek (behind)
      - {kind: poly, points: [[-4.5, -2.2], [4.5, -2.2], [4.5, -1.0], [-4.5, -1.0]], y: [1.9, 3.1]}   # and lower
      - {kind: poly, points: [[-5, -24], [5, -24], [5, -2.2], [-5, -2.2]], y: [1.9, 3.1]}   # the standard
      - {kind: poly, points: [[14.7, -24], [17.7, -24], [17.2, 0], [15.2, 0]], y: [-4.0, -3.0]}   # the spindle's bearings
      - {kind: disc, center: [16.2, 0], radius: 1.3, y: [-4.0, -3.0]}
      - {kind: poly, points: [[14.7, -24], [17.7, -24], [17.2, 0], [15.2, 0]], y: [10.5, 11.5]}
      - {kind: disc, center: [16.2, 0], radius: 1.3, y: [10.5, 11.5]}
      - {kind: rod, from: [-4.0, -3.2, 0.0], to: [-4.0, 1.9, 0.0], radius: 0.45, color: "#8f8a80"}   # the fulcrum stud
      - {kind: poly, points: [[-16, -25], [26.2, -25], [26.2, -24], [-16, -24]], y: [-6, 13], color: "#b9b09c"}
joints:
  - {id: j_spindle, type: hinge, body: spindle, axis: [0, 1, 0], damping: 0.001}
  - {id: j_slide, type: slide, body: carriage, axis: [1, 0, 0], range: [-2.4, 0.4], damping: 2}
  - {id: j_gear, type: hinge, body: gear, axis: [0, 1, 0], damping: 0.2}   # the work (the lathe's back gear)
  - {id: j_lever, type: hinge, body: lever, axis: [0, 1, 0], range: [-0.05, 0.6], stiffness: 6, springref: 0, damping: 1}
spurs:
  - {id: gear_g, body: gear, pos: [0, 0, 0], teeth: 40, module: 0.6, width: 1.4, backlash: 0.03, phase: 0.07853981633974483}
  - {id: pinion_g, body: spindle, pos: [0, 0, 0], teeth: 14, module: 0.6, width: 1.4, backlash: 0.03, phase: 0}
hand:
  - {t: 3, springref: {j_lever: 0.5}}
  - {t: 7, springref: {j_lever: 0}}
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_spindle, kind: velocity, rpm: 30, kv: 1, max_torque: 6}
checks:
  # in gear: the wheel turns back the other way at 14/40
  - {type: ratio, out: j_gear, in: j_spindle, expect: -0.35, tol: 0.005, settle_s: 0.5, window_s: 2.3}
  # the lever down at 3 s: the wheel drawn back out of gear stands
  - {type: ratio, out: j_gear, in: j_spindle, expect: 0, tol: 0.01, settle_s: 4.5, window_s: 2.3}
  # up again at 7 s: back in gear
  - {type: ratio, out: j_gear, in: j_spindle, expect: -0.35, tol: 0.005, settle_s: 8.5, window_s: 2.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [4, 0, -2], position: [10, -95, 25], fov: 34}
display:
  output: j_gear
  labels: {j_spindle: "Spindle with cone and pinion (driver)", j_gear: "Large wheel (back gear)", j_slide: "Wheel's shaft in the frame's slot", j_lever: "Lever"}
  proof: {label: "Lever's slot out of contact", sub: "the lever turns, but nothing draws the journal back: the wheel stays in gear"}
