# No. 48, Clutch-box (Brown 1868): "The pinion at the top gives a continuous rotary motion to the gear
# below, to which is attached half the clutch, and both turn loosely on the shaft. When it is desired
# to give motion to the shaft, the other part of the clutch, which slides upon a key or feather fixed
# in the shaft, is thrust into gear by the lever."
#
# Model (cm): the shaft runs along y. A 12-tooth pinion above (module 1, the one motor-driven
# shaft, with its driving pulley) turns a 32-tooth gear that is loose on the shaft (its own hinge on
# the shaft's line). The gear's face carries three jaws with parallel-sided slots between them, their
# ends roofed. The other half slides on the shaft's feather (a slide joint on the shaft's own body)
# and carries three round jaws (radial pins, collided as capsules: smooth against the gear's jaws).
# The lever's fork stands in the groove of its hub; a spring holds the iron lever where the hand sets
# it: thrust in at 2 s, out at 5.5 s. A pin that comes down on a jaw rides on its roof until a slot
# comes under it, then the spring drives it home. The shaft is turned only by pin on jaw.
number: 48
slug: clutch-box
name: Clutch-box
brown: "Clutch-box. The pinion at the top gives a continuous rotary motion to the gear below, to which is attached half the clutch, and both turn loosely on the shaft. When it is desired to give motion to the shaft, the other part of the clutch, which slides upon a key or feather fixed in the shaft, is thrust into gear by the lever."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 500
  solver: CG
  multiccd: true
  duration_s: 8
  floor: false
bodies:
  - id: pinion
    shape: part
    pos: [0, 0, 22]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [0, -9, 22], to: [0, -0.6, 22], radius: 0.5, color: "#8f8a80"}
      - {kind: disc, center: [0, 22], radius: 5, inner: 0.5, y: [-6.5, -5.5], color: "#9c958a"}   # the driving pulley
  - id: gear
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.15
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.2, inner: 0.7, y: [-1, 0]}
      - {kind: loft, a: [[1.4362, -0.2, -0.4328], [1.4362, 0.6, -0.4328], [1.3508, 0.8, 0.6522], [0.5543, 0.6, 1.3938], [0.5543, -0.2, 1.3938]], b: [[2.7055, -0.2, -1.2963], [2.7055, 0.6, -1.2963], [2.7016, 0.8, 1.3044], [0.6675, 0.6, 2.9248], [0.6675, -0.2, 2.9248]], collide: 1}
      - {kind: loft, a: [[-0.3433, -0.2, 1.4602], [-0.3433, 0.6, 1.4602], [-1.2402, 0.8, 0.8437], [-1.4842, 0.6, -0.2169], [-1.4842, -0.2, -0.2169]], b: [[-0.2301, -0.2, 2.9912], [-0.2301, 0.6, 2.9912], [-2.4804, 0.8, 1.6875], [-2.8667, 0.6, -0.8844], [-2.8667, -0.2, -0.8844]], collide: 1}
      - {kind: loft, a: [[-1.0929, -0.2, -1.0274], [-1.0929, 0.6, -1.0274], [-0.1106, 0.8, -1.4959], [0.93, 0.6, -1.1769], [0.93, -0.2, -1.1769]], b: [[-2.4754, -0.2, -1.6948], [-2.4754, 0.6, -1.6948], [-0.2212, 0.8, -2.9918], [2.1992, 0.6, -2.0404], [2.1992, -0.2, -2.0404]], collide: 1}
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, -9, 0], to: [0, 15, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: rod, from: [0, 1, 0.6], to: [0, 8, 0.6], radius: 0.18, color: "#6f6a60"}   # the feather
  - id: half
    shape: part
    pos: [0, 0, 0]
    mount: shaft
    density: 7800
    friction: 0.15
    color: "#e2d8bf"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.2, inner: 0.6, y: [1.6, 2.4]}
      - {kind: rod, from: [-0.1187, 1.3, 1.4953], to: [-0.2374, 1.3, 2.9906], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [-1.2356, 1.3, -0.8504], to: [-2.4712, 1.3, -1.7009], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [1.3543, 1.3, -0.6449], to: [2.7086, 1.3, -1.2897], radius: 0.4, collide: 2, capsule: true}
      - {kind: disc, center: [0, 0], radius: 1.4, inner: 0.6, y: [2.4, 6.4]}
      - {kind: disc, center: [0, 0], radius: 2.4, y: [4.0, 4.6], collide: 2}
      - {kind: disc, center: [0, 0], radius: 2.4, y: [5.8, 6.4], collide: 2}
  - id: lever
    shape: part
    pos: [0, 5.2, -13]
    density: 7800   # iron, with a heavy knob: a light lever chatters on the collar
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [0, 5.2, -13], to: [0, 5.2, -2.4], radius: 0.35}
      - {kind: poly, points: [[-0.9, -2.3], [0.9, -2.3], [0.9, -1.6], [-0.9, -1.6]], y: [4.75, 5.65], collide: 1}
      - {kind: rod, from: [0, 5.2, -13], to: [0, 9.9, -19], radius: 0.35}
      - {kind: disc, center: [0, -19], radius: 1.2, y: [8.7, 11.1]}   # the knob
      - {kind: disc, center: [0, -13], radius: 0.7, y: [4.7, 5.7]}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.2, -21], [1.2, -21], [0.8, -13], [-0.8, -13]], y: [3.4, 4.2]}
      - {kind: poly, points: [[-1.5, -21], [1.5, -21], [1.0, 22], [-1.0, 22]], y: [-8, -7]}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-8, -7]}
      - {kind: disc, center: [0, 22], radius: 1.3, y: [-8, -7]}
      - {kind: poly, points: [[-1.5, -21], [1.5, -21], [1.0, 0], [-1.0, 0]], y: [13, 14]}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [13, 14]}
      - {kind: poly, points: [[-4, -22], [4, -22], [4, -21], [-4, -21]], y: [-10, 16], color: "#b9b09c"}
joints:
  - {id: j_pinion, type: hinge, body: pinion, axis: [0, 1, 0], damping: 0.001}
  - {id: j_gear, type: hinge, body: gear, axis: [0, 1, 0], damping: 0.002}   # loose on the shaft
  - {id: j_shaft, type: hinge, body: shaft, axis: [0, 1, 0], damping: 0.1}   # the machinery it drives
  - {id: j_feather, type: slide, body: half, axis: [0, 1, 0], range: [-0.7, 0.3], damping: 2}
  - {id: j_lever, type: hinge, body: lever, axis: [1, 0, 0], range: [-0.04, 0.12], stiffness: 8, springref: 0, damping: 4}
spurs:
  - {id: pin_g, body: pinion, pos: [0, -2, 0], teeth: 12, module: 1, width: 2, backlash: 0.02, phase: 0}
  - {id: gear_g, body: gear, pos: [0, -2, 0], teeth: 32, module: 1, width: 2, backlash: 0.02, phase: 0.1}
hand:
  - {t: 2, springref: {j_lever: 0.1}}
  - {t: 5.5, springref: {j_lever: -0.04}}
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_pinion, kind: velocity, rpm: 40, kv: 0.3, max_torque: 5}
checks:
  # the gear runs loose at -12/32 the whole time
  - {type: ratio, out: j_gear, in: j_pinion, expect: -0.375, tol: 0.005, settle_s: 0.5, window_s: 7.5}
  # out of gear: the shaft stands
  - {type: ratio, out: j_shaft, in: j_pinion, expect: 0, tol: 0.01, settle_s: 0.5, window_s: 1.4}
  # thrust in at 2 s: jaw on jaw, the shaft turns with the gear
  - {type: ratio, out: j_shaft, in: j_pinion, expect: -0.375, tol: 0.005, settle_s: 3, window_s: 2.4}
  # out at 5.5 s: it stops again
  - {type: ratio, out: j_shaft, in: j_pinion, expect: 0, tol: 0.01, settle_s: 6.5, window_s: 1.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 3, 0], position: [95, 75, 30], fov: 30}
display:
  output: j_shaft
  labels: {j_pinion: "Pinion (driver)", j_gear: "Gear, loose on the shaft", j_shaft: "Shaft", j_lever: "Lever", j_feather: "Sliding half on the feather"}
  proof: {label: "Jaws out of contact", sub: "the lever thrusts the half in, but the pins pass through the gear's jaws: the shaft stands"}
