# No. 192 (Brown 1868): "A variety of what is known as the mangle-wheel. One variety of this was illustrated by 36. In this one the speed varies in every part
#  of a revolution, the groove, b, d, in which the pinion-shaft is guided, as well as the series of teeth, being eccentric to the axis of the wheel."
#
# Model (cm): No. 36 with its circle of teeth made eccentric. The wheel turns on a shaft at the origin; on its face stand 50 round pins (r 0.35) on a circle of
# radius 12 whose centre stands 2 from the shaft, at pitch 1.257, over 294 deg; behind them the guiding groove follows the same eccentric
# circle, a track 2 inside the pins and one 2 outside, joined by half-rounds about the two end pins. A 10-tooth pinion (pitch radius 2) turns in a carriage
# that slides in the stationary upright slot (x = 0), its follower running in the groove, so the pinion rises and falls as the eccentric circle comes round.
# Only the pinion is driven (30 rpm, one way). Its pitch circle always touches the circle of pins, but the pins' distance from the shaft changes, so the wheel's speed
# varies all round: inside the pins about rp/(R + e) to rp/(R - e) = 0.143 to 0.200 of the pinion's, the same way round; at the end pin the groove carries it
# outside and the wheel runs back. A weight behind the face plate balances the eccentric pins and groove on the shaft. Generator: opencode-runs/batch11/gen192.py.
number: 192
slug: eccentric-mangle-wheel
name: An eccentric mangle-wheel
brown: "A variety of the mangle-wheel. In this one the speed varies in every part of a revolution, the groove in which the pinion-shaft is guided, as well as the series of teeth, being eccentric to the axis of the wheel."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 19
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 17.73, inner: 2.0, y: [0.8, 1.5], collide: 0}   # the face plate
      - {kind: disc, center: [0, 0], radius: 2.2, y: [0.0, 2.4], collide: 0}               # hub
      - {kind: disc, center: [6.53567, -8.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.55184, -7.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.48528, -6.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.32575, -5.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.06405, -4.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.69208, -3.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.20297, -2.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.59111, -1.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.85226, 0.12279], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.98355, 1.37197], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.98355, 2.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.85226, 3.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.59111, 5.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.20297, 6.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.69208, 7.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.06405, 8.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.32575, 9.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.48528, 10.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.55184, 11.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [6.53567, 12.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [5.44789, 12.69208], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [4.30042, 13.20297], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [3.10583, 13.59111], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [1.87721, 13.85226], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [0.62803, 13.98355], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-0.62803, 13.98355], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-1.87721, 13.85226], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-3.10583, 13.59111], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-4.30042, 13.20297], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-5.44789, 12.69208], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.53567, 12.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.55184, 11.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.48528, 10.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.32575, 9.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.06405, 8.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.69208, 7.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.20297, 6.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.59111, 5.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.85226, 3.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.98355, 2.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.98355, 1.37197], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.85226, 0.12279], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.59111, -1.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.20297, -2.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.69208, -3.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.06405, -4.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.32575, -5.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.48528, -6.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.55184, -7.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.53567, -8.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: band, center: [0.0, 2.0], r: [8.87, 9.47], a: [-0.99484, 4.13643], y: [0.05, 0.8], collide: 1}   # the groove's inner wall
      - {kind: band, center: [0.0, 2.0], r: [10.53, 13.47], a: [-0.99484, 4.13643], y: [0.05, 0.8], collide: 1}   # the island between the tracks
      - {kind: band, center: [0.0, 2.0], r: [14.53, 15.13], a: [-0.99484, 4.13643], y: [0.05, 0.8], collide: 1}   # the outer wall
      - {kind: disc, center: [-6.53567, -8.06405], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [-6.53567, -8.06405], r: [2.53, 3.13], a: [4.13643, 7.27802], slices: 18, y: [0.05, 0.8], collide: 1}   # the groove round the end pin
      - {kind: disc, center: [6.53567, -8.06405], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [6.53567, -8.06405], r: [2.53, 3.13], a: [-4.13643, -0.99484], slices: 18, y: [0.05, 0.8], collide: 1}   # the groove round the end pin
      - {kind: disc, center: [-1e-05, -8.0], radius: 4.5, y: [1.5, 3.07776], collide: 0, color: "#8f8a80"}   # the balance weight, behind the face plate
  - id: carriage
    shape: part
    pos: [0, 0, 12.0]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 12.0], radius: 0.5, y: [0.05, 0.75], collide: 2}            # the follower in the groove
      - {kind: poly, points: [[-0.7, 11.3], [0.7, 11.3], [0.7, 12.7], [-0.7, 12.7]], y: [-3.4, -2.6], collide: 0}   # its block in the upright's slot
      - {kind: rod, from: [0, -2.6, 12.0], to: [0, -1.05, 12.0], radius: 0.3, collide: 0}
  - id: pinion
    shape: part
    mount: carriage
    pos: [0, 0, 12.0]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, 12.0], radius: 1.5, y: [-1.0, -0.05], collide: 0}
      - {kind: poly, points: [[0.4085, 13.45], [-0.4085, 13.45], [-0.05545, 14.42], [0.05545, 14.42]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.5218, 13.41319], [-1.18277, 12.93296], [-1.4673, 13.92523], [-1.37758, 13.99041]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.2528, 12.83658], [-1.50527, 12.05957], [-2.31869, 12.69508], [-2.28442, 12.80056]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.50527, 11.94043], [-1.2528, 11.16342], [-2.28442, 11.19944], [-2.31869, 11.30492]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.18277, 11.06704], [-0.5218, 10.58681], [-1.37758, 10.00959], [-1.4673, 10.07477]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.4085, 10.55], [0.4085, 10.55], [0.05545, 9.58], [-0.05545, 9.58]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.5218, 10.58681], [1.18277, 11.06704], [1.4673, 10.07477], [1.37758, 10.00959]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.2528, 11.16342], [1.50527, 11.94043], [2.31869, 11.30492], [2.28442, 11.19944]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.50527, 12.05957], [1.2528, 12.83658], [2.28442, 12.80056], [2.31869, 12.69508]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.18277, 12.93296], [0.5218, 13.41319], [1.37758, 13.99041], [1.4673, 13.92523]], y: [-1.0, -0.05], collide: 2}
  - id: upright
    shape: frame
    color: "#8f8a80"
    rods:
      - {from: [-1.1, -3.0, 6.5], to: [-1.1, -3.0, 17.5], radius: 0.35}   # the upright stationary bar's two cheeks
      - {from: [1.1, -3.0, 6.5], to: [1.1, -3.0, 17.5], radius: 0.35}
      - {from: [0, -3.0, 0], to: [0, 3.2, 0], radius: 0.6}               # the wheel's shaft
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.02}
  - {id: j_lift, type: slide, body: carriage, axis: [0, 0, 1], damping: 0.5, range: [-4.6, 4.6]}
  - {id: j_pinion, type: hinge, body: pinion, axis: [0, 1, 0], damping: 0.001}   # the one driven joint
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_pinion, kind: velocity, rpm: 30, kv: 1.5, max_torque: 6}   # gain kept so kv x speed is under the torque cap: the light unloaded pinion stays stable so the light unloaded pinion stays stable
checks:
  - {type: ratio_range, out: j_wheel, in: j_pinion, min: 0.12857, max: 0.22, min_swing: 0.02857, settle_s: 0.5, window_s: 4, slices: 8}   # inside the pins: same way round, speed varying
  - {type: ratio_range, out: j_wheel, in: j_pinion, min: -0.22, max: -0.12857, min_swing: 0.02857, settle_s: 7, window_s: 8, slices: 12}   # outside, after the end pin: back
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, 2.0], position: [0, -102, 3.0], fov: 34}
display:
  output: j_wheel
  labels: {j_pinion: "Pinion (driver, one way)", j_wheel: "Mangle-wheel (to and fro, speed varying)", j_lift: "Pinion carriage"}
  proof: {label: "Pins out of contact", sub: "the pinion turns alone: the wheel stands still"}

