# No. 53 (Brown 1868): "The vertical shaft is made to drive the horizontal one in either direction, as
# may be desired, by means of the double-clutch and bevel-gears. The gears on the horizontal shaft are
# loose, and are driven in opposite directions by the third gear; the double-clutch slides upon a key or
# feather fixed on the horizontal shaft, which is made to rotate either to the right or left, according
# to the side on which it is engaged."
#
# Model (cm): the horizontal shaft runs along y. Two 20-tooth miter bevels (pitch radius 6) turn loose
# on it, A at +y and B at -y; the upright shaft's bevel (the one motor-driven shaft, with its pulley)
# meshes both from above, so they turn opposite ways. Each loose bevel carries on its inner face three
# jaws with parallel-sided slots, their ends roofed (No. 48's clutch). The double clutch slides on the
# shaft's feather (a slide joint on the shaft's own body) between them and carries three round jaws
# (radial pins, collided as capsules) on each face. The iron lever's fork stands between the clutch's
# two discs; a spring holds it where the hand sets it: over to A at 2 s, across to B at 5.5 s, back to
# the middle at 9 s. The shaft is turned only by pin on jaw.
number: 53
slug: double-clutch-bevel-gears
name: Double clutch and bevel-gears
brown: "The vertical shaft is made to drive the horizontal one in either direction, as may be desired, by means of the double-clutch and bevel-gears. The gears on the horizontal shaft are loose, and are driven in opposite directions by the third gear; the double-clutch slides upon a key or feather fixed on the horizontal shaft, which is made to rotate either to the right or left, according to the side on which it is engaged."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS   # CG and Newton blow up on the bevel-and-jaw contacts (one step from calm); PGS as No. 49
  multiccd: true
  duration_s: 11
  floor: false
bodies:
  - id: gearA
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.15
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.6, inner: 0.7, y: [3.2, 4.6]}
      - {kind: disc, center: [0, 0], radius: 1.4, inner: 0.7, y: [4.6, 7.4]}
      - {kind: loft, a: [[1.4362, 3.4, -0.4328], [1.4362, 2.6, -0.4328], [1.3508, 2.4, 0.6522], [0.5543, 2.6, 1.3938], [0.5543, 3.4, 1.3938]], b: [[2.7055, 3.4, -1.2963], [2.7055, 2.6, -1.2963], [2.7016, 2.4, 1.3044], [0.6675, 2.6, 2.9248], [0.6675, 3.4, 2.9248]], collide: 1}
      - {kind: loft, a: [[-0.3433, 3.4, 1.4602], [-0.3433, 2.6, 1.4602], [-1.2402, 2.4, 0.8437], [-1.4842, 2.6, -0.2169], [-1.4842, 3.4, -0.2169]], b: [[-0.2301, 3.4, 2.9912], [-0.2301, 2.6, 2.9912], [-2.4804, 2.4, 1.6875], [-2.8667, 2.6, -0.8844], [-2.8667, 3.4, -0.8844]], collide: 1}
      - {kind: loft, a: [[-1.0929, 3.4, -1.0274], [-1.0929, 2.6, -1.0274], [-0.1106, 2.4, -1.4959], [0.93, 2.6, -1.1769], [0.93, 3.4, -1.1769]], b: [[-2.4754, 3.4, -1.6948], [-2.4754, 2.6, -1.6948], [-0.2212, 2.4, -2.9918], [2.1992, 2.6, -2.0404], [2.1992, 3.4, -2.0404]], collide: 1}
  - id: gearB
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.15
    color: "#e2d8bf"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.6, inner: 0.7, y: [-4.6, -3.2]}
      - {kind: disc, center: [0, 0], radius: 1.4, inner: 0.7, y: [-7.4, -4.6]}
      - {kind: loft, a: [[0.1215, -3.4, -1.4951], [0.1215, -2.6, -1.4951], [1.1004, -2.4, -1.0194], [1.5, -2.6, -0.007], [1.5, -3.4, -0.007]], b: [[-0.2189, -3.4, -2.992], [-0.2189, -2.6, -2.992], [2.2008, -2.4, -2.0388], [2.9666, -2.6, 0.4466], [2.9666, -3.4, 0.4466]], collide: 1}
      - {kind: loft, a: [[1.234, -3.4, 0.8528], [1.234, -2.6, 0.8528], [0.3326, -2.4, 1.4627], [-0.7439, -2.6, 1.3025], [-0.7439, -3.4, 1.3025]], b: [[2.7006, -3.4, 1.3064], [2.7006, -2.6, 1.3064], [0.6652, -2.4, 2.9253], [-1.8701, -2.6, 2.3458], [-1.8701, -3.4, 2.3458]], collide: 1}
      - {kind: loft, a: [[-1.3555, -3.4, 0.6423], [-1.3555, -2.6, 0.6423], [-1.433, -2.4, -0.4433], [-0.7561, -2.6, -1.2955], [-0.7561, -3.4, -1.2955]], b: [[-2.4817, -3.4, 1.6856], [-2.4817, -2.6, 1.6856], [-2.866, -2.4, -0.8866], [-1.0965, -2.6, -2.7924], [-1.0965, -3.4, -2.7924]], collide: 1}
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, -14, 0], to: [0, 14, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: rod, from: [0, -2.6, 0.6], to: [0, 2.6, 0.6], radius: 0.18, color: "#6f6a60"}   # the feather
  - id: clutch
    shape: part
    pos: [0, 0, 0]
    mount: shaft
    density: 7800
    friction: 0.15
    color: "#d8ccb0"
    pieces:
      - {kind: disc, center: [0, 0], radius: 3.2, inner: 0.6, y: [1.0, 1.8]}
      - {kind: disc, center: [0, 0], radius: 3.2, inner: 0.6, y: [-1.8, -1.0]}
      - {kind: disc, center: [0, 0], radius: 1.4, inner: 0.6, y: [-1.0, 1.0]}
      - {kind: disc, center: [0, 0], radius: 2.4, y: [0.8, 1.0], collide: 2}    # the groove's walls
      - {kind: disc, center: [0, 0], radius: 2.4, y: [-1.0, -0.8], collide: 2}
      - {kind: rod, from: [-0.1187, 1.7, 1.4953], to: [-0.2374, 1.7, 2.9906], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [-1.2356, 1.7, -0.8504], to: [-2.4712, 1.7, -1.7009], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [1.3543, 1.7, -0.6449], to: [2.7086, 1.7, -1.2897], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [-0.1187, -1.7, 1.4953], to: [-0.2374, -1.7, 2.9906], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [-1.2356, -1.7, -0.8504], to: [-2.4712, -1.7, -1.7009], radius: 0.4, collide: 2, capsule: true}
      - {kind: rod, from: [1.3543, -1.7, -0.6449], to: [2.7086, -1.7, -1.2897], radius: 0.4, collide: 2, capsule: true}
  - id: lever
    shape: part
    pos: [0, 0, -13]
    density: 7800   # iron, with a heavy knob (No. 48)
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [0, 0, -13], to: [0, 0, -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: [-0.7, 0.7], collide: 1}   # the fork's prong in the groove
      - {kind: rod, from: [0, 0, -13], to: [0, 0, -19], radius: 0.35}
      - {kind: disc, center: [0, -19], radius: 1.2, y: [-1.2, 1.2]}   # the knob
      - {kind: disc, center: [0, -13], radius: 0.7, y: [-0.5, 0.5]}
  - {id: upright, shape: assembly, pos: [0, 0, 0], color: "#e8dec6"}
  - 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: [-1.6, -0.9]}   # the lever's post
      - {kind: poly, points: [[-1.5, -21], [1.5, -21], [1.0, 0], [-1.0, 0]], y: [-12, -11]}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-12, -11]}
      - {kind: poly, points: [[-1.5, -21], [1.5, -21], [1.0, 0], [-1.0, 0]], y: [11, 12]}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [11, 12]}
      - {kind: poly, points: [[-9.5, -21], [-8, -21], [-8, 19], [-9.5, 19]], y: [-0.75, 0.75]}   # the upright's standard
      - {kind: poly, points: [[-9.5, 17.4], [0, 17.4], [0, 18.6], [-9.5, 18.6]], y: [-0.75, 0.75]}   # and its bearing arm
      - {kind: poly, points: [[-10, -22], [4, -22], [4, -21], [-10, -21]], y: [-14, 14], color: "#b9b09c"}
joints:
  - {id: j_up, type: hinge, body: upright, axis: [0, 0, 1], damping: 0.001}
  - {id: j_A, type: hinge, body: gearA, axis: [0, 1, 0], damping: 0.002}   # loose on the shaft
  - {id: j_B, type: hinge, body: gearB, 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: clutch, axis: [0, 1, 0], range: [-1.0, 1.0], damping: 2}
  - {id: j_lever, type: hinge, body: lever, axis: [1, 0, 0], range: [-0.14, 0.14], stiffness: 12, springref: 0, damping: 4}
bevels:
  - {id: gA, body: gearA, teeth: 20, pitch_radius: 6, cone_angle: 0.7853982, face_width: 2.4, backlash: 0.05, phase: 0.0}
  - {id: gB, body: gearB, teeth: 20, pitch_radius: 6, cone_angle: 0.7853982, face_width: 2.4, backlash: 0.05, phase: 0.0, quat: [0, 0, 0, 1]}
  - {id: gV, body: upright, teeth: 20, pitch_radius: 6, cone_angle: 0.7853982, face_width: 2.4, backlash: 0.05, phase: 0.1570796, quat: [0.7071068, 0.7071068, 0, 0]}
shafts:
  - {id: sh_up, body: upright, from: [0, 0, 6.5], to: [0, 0, 19], radius: 0.6}
  - {id: sh_pul, body: upright, from: [0, 0, 13.5], to: [0, 0, 14.9], radius: 4.5, inner: 0.6}   # the driving pulley
hand:
  - {t: 2, springref: {j_lever: -0.12}}
  - {t: 5.5, springref: {j_lever: 0.12}}
  - {t: 9, springref: {j_lever: 0}}
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_up, kind: velocity, rpm: 15, kv: 2, max_torque: 10}
checks:
  # the two loose bevels turn opposite ways, each at the upright's speed, the whole time
  - {type: ratio, out: j_A, in: j_up, expect: -1, tol: 0.005, settle_s: 0.5, window_s: 10}
  - {type: ratio, out: j_B, in: j_up, expect: 1, tol: 0.005, settle_s: 0.5, window_s: 10}
  # in the middle: the shaft stands
  - {type: ratio, out: j_shaft, in: j_up, expect: 0, tol: 0.01, settle_s: 0.5, window_s: 1.4}
  # over to A at 2 s: the shaft turns with A
  - {type: ratio, out: j_shaft, in: j_up, expect: -1, tol: 0.005, settle_s: 3.4, window_s: 2}
  # across to B at 5.5 s: it turns the other way, with B
  - {type: ratio, out: j_shaft, in: j_up, expect: 1, tol: 0.005, settle_s: 6.9, window_s: 2}
  # back to the middle at 9 s: it stops
  - {type: ratio, out: j_shaft, in: j_up, expect: 0, tol: 0.01, settle_s: 9.8, window_s: 1.2}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, -3], position: [120, 75, 45], fov: 32}
display:
  output: j_shaft
  labels: {j_up: "Upright shaft (driver)", j_A: "Bevel A, loose", j_B: "Bevel B, loose", j_shaft: "Horizontal shaft", j_lever: "Lever", j_feather: "Double clutch on the feather"}
  proof: {label: "Clutch jaws out of contact", sub: "the lever throws the clutch over, but its pins pass through the bevels' jaws: the shaft stands"}
