# No. 58 (Brown 1868): "For transmitting three different speeds by gearing."
#
# As drawn (cm; the shafts run along y): the wide driving drum (r 4.0) on its own shaft 22.0 above the
# shaft line, the one motor-driven shaft. On the shaft line, from right to left: a loose pulley; a
# pulley fast on the main shaft, whose far end carries the small spur-gear (12 teeth); a
# pulley on a hollow shaft running on the main shaft, carrying a larger gear (18); and a
# pulley on a second hollow shaft running on the first, carrying the largest (24), nearest
# the pulleys. The three gears are always in mesh with 36, 30 and 24 on
# the shaft below (one centre distance, 19.200000000000003, serves all three, module 0.8). The band is an elastic
# chain of links driving by friction; traversing it from pulley to pulley (the variants) gives the shaft
# below three speeds, 12/36, 18/30 and 24/24 of the drum's, reversed, or none
# on the loose pulley. The shafts not under the band are turned back idly by the shaft below.
# Generator: opencode-runs/batch7/gen058.py.
number: 58
slug: three-speeds-by-gearing
name: Three speeds by gearing
brown: "For transmitting three different speeds by gearing. The lower part of the band is shown on a loose pulley. The next pulley is fixed on the main shaft, on the other end of which is fixed a small spur-gear. The next pulley is fixed on a hollow shaft running on the main shaft, and there is secured to it a second spur-gear, larger than the first. The fourth and last pulley to the left is fixed on another hollow shaft running loosely on the last-named, on the other end of which is fixed the still larger spur-gear nearest to the pulley. As the band is made to traverse from one pulley to another, it transmits three different velocities to the shaft below."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 80
  solver: PGS
  multiccd: true
  duration_s: 6
  floor: false
bodies:
  - {id: drum, shape: pulley, radius: 4.0, width: 13.6, rim_width: 2.8, grooves: [[0, -4.8, 0], [0, -1.6, 0], [0, 1.6, 0], [0, 4.8, 0]], pos: [0, 4.8, 22.0], mass: 2.5, spokes: 4, hub: 1.0, flange: 0.3}
  - {id: p_loose, shape: pulley, radius: 4.0, width: 2.6, pos: [0, 9.6, 0], mass: 0.8, spokes: 0, hub: 1.0, flange: 0.3}
  - {id: main, shape: assembly, pos: [0, 0, 0], color: "#d9cfb6"}
  - {id: h1, shape: assembly, pos: [0, 0, 0], color: "#cfc4a8"}
  - {id: h2, shape: assembly, pos: [0, 0, 0], color: "#e2d8bf"}
  - {id: below, shape: assembly, pos: [0, 0, -19.2], color: "#e8dcc0"}
  - {id: stubs, shape: frame, rods: [{from: [0, 11.2, 0], to: [0, 12.6, 0], radius: 0.7}, {from: [0, -15, -19.2], to: [0, -0.5, -19.2], radius: 0.6}, {from: [0, -2.6, 22.0], to: [0, 12.6, 22.0], radius: 0.6}], color: "#8f8a80"}
joints:
  - {id: j_drum, type: hinge, body: drum, axis: [0, 1, 0], damping: 0.002}
  - {id: j_loose, type: hinge, body: p_loose, axis: [0, 1, 0], damping: 0.02}
  - {id: j_main, type: hinge, body: main, axis: [0, 1, 0], damping: 0.005}
  - {id: j_h1, type: hinge, body: h1, axis: [0, 1, 0], damping: 0.005}
  - {id: j_h2, type: hinge, body: h2, axis: [0, 1, 0], damping: 0.005}
  - {id: j_below, type: hinge, body: below, axis: [0, 1, 0], damping: 0.05}   # the load
wheels:
  - {id: p_main, body: main, pos: [0, 6.4, 0], radius: 4.0, width: 2.6, mass: 0.8, spokes: 0, hub: 0.6, flange: 0.3}
  - {id: p_h1, body: h1, pos: [0, 3.2, 0], radius: 4.0, width: 2.6, mass: 0.8, spokes: 0, hub: 1.0, flange: 0.3}
  - {id: p_h2, body: h2, pos: [0, 0.0, 0], radius: 4.0, width: 2.6, mass: 0.8, spokes: 0, hub: 1.4, flange: 0.3}
spurs:
  - {id: g_main, body: main, pos: [0, -12.0, 0], teeth: 12, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.5708}
  - {id: G_main, body: below, pos: [0, -12.0, 0], teeth: 36, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.6581}
  - {id: g_h1, body: h1, pos: [0, -8.0, 0], teeth: 18, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.5708}
  - {id: G_h1, body: below, pos: [0, -8.0, 0], teeth: 30, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.6755}
  - {id: g_h2, body: h2, pos: [0, -4.0, 0], teeth: 24, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.5708}
  - {id: G_h2, body: below, pos: [0, -4.0, 0], teeth: 24, module: 0.8, width: 2.4, backlash: 0.04, phase: 1.7017}
shafts:
  - {id: sh_main, body: main, from: [0, -13.6, 0], to: [0, 7.9, 0], radius: 0.5}
  - {id: sh_h1, body: h1, from: [0, -9.4, 0], to: [0, 4.6, 0], radius: 0.95, inner: 0.55}
  - {id: sh_h2, body: h2, from: [0, -5.4, 0], to: [0, 1.4, 0], radius: 1.4, inner: 1.0}
  - {id: sh_below, body: below, from: [0, -14.5, 0], to: [0, -1.0, 0], radius: 0.6}
belts:
  - id: belt
    around: [p_main, drum]
    links: 48
    thickness: 0.4
    width: 2.0
    density: 7800
    stiffness: 24000
    damping: 2
    pretension: 40
    friction: 0.7
contact: {solref: [0.0008, 1], solimp: [0.95, 0.99, 0.001], margin: 0}
driver: {joint: j_drum, kind: velocity, rpm: 30, kv: 2, max_torque: 5}
variants:
  - {id: slow, note: "band on the main shaft's pulley: the small gear drives, the shaft below turns 12/36 of the drum's speed", belt_around: {belt: [p_main, drum]}}
  - {id: middle, note: "band on the first hollow shaft's pulley: 18/30", belt_around: {belt: [p_h1, drum]}}
  - {id: fast, note: "band on the second hollow shaft's pulley: 24/24", belt_around: {belt: [p_h2, drum]}}
  - {id: loose, note: "band on the loose pulley, as drawn: nothing is driven", belt_around: {belt: [p_loose, drum]}}
variant: slow
checks:
  - {type: ratio, out: j_below, in: j_main, expect: -0.3333, tol: 0.004, settle_s: 1.5, window_s: 4}
  - {type: ratio, out: j_below, in: j_drum, expect: -0.3333, tol: 0.02, settle_s: 1.5, window_s: 4}
  - {type: ratio, out: j_h1, in: j_below, expect: -1.6667, tol: 0.01, settle_s: 1.5, window_s: 4}
  - {type: ratio, out: j_h2, in: j_below, expect: -1.0, tol: 0.01, settle_s: 1.5, window_s: 4}
  - {type: belt_on, belt: belt, max_radial_dev: 1.2, max_lateral: 0.6, duration_s: 2.5}
  - {type: penetration, max: 0.001, settle_s: 1.5}
camera: {target: [0, -1, -10], position: [130, -100, 18], fov: 34}
display:
  tiers:
    - {id: full, label: Full, ms: 1.3349}
    - {id: friction, label: Friction model, timestep: 0.001, integrator: implicitfast, model: capstan, ms: 0.0614}
  output: j_below
  labels: {j_drum: "Drum (driver)", j_loose: "Loose pulley", j_main: "Main shaft (small gear)", j_h1: "Hollow shaft (larger gear)", j_h2: "Second hollow shaft (largest gear)", j_below: "Shaft below"}
  expect: {default: -0.3333}
  proof: {label: "Shaft below out of mesh", sub: "the band turns the main shaft, but nothing reaches the shaft below"}
