# No. 194 (Brown 1868): "Another mangle-wheel. In this the speed is equal in both directions of motion, only one circle of teeth being provided on the wheel.
#  With all of these mangle-wheels the pinion-shaft is guided and the pinion kept in gear by a groove in the wheel. The said shaft is made with a universal joint,
#  which allows a portion of it to have the vibratory motion necessary to keep the pinion in gear."
#
# Model (cm): the wheel turns on a shaft at the origin; on its face stand 50 round pins (r 0.35) on one circle of radius 12, pitch 1.257, over 294 deg;
# behind them the guiding groove, 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 at the end of an arm 20 long pivoted on the frame to the left: the arm is the swinging part of the universal-jointed pinion shaft, and its follower
# in the groove swings it up and down 2 to keep the pinion in gear inside and outside the circle. Only the pinion is driven (30 rpm, one way, on the arm).
# Inside the pins the wheel turns the same way at rp/R = 0.1667 of the pinion's speed; round the end pin the pinion passes outside and the wheel runs back
# at the same speed, -rp/R. A weight behind the face plate balances the gap in the pins and groove. Generator: opencode-runs/batch11/gen194.py.
number: 194
slug: another-mangle-wheel
name: Another mangle-wheel
brown: "Another mangle-wheel. In this the speed is equal in both directions of motion, only one circle of teeth being provided on the wheel. The pinion-shaft is guided and the pinion kept in gear by a groove in the wheel; the shaft is made with a universal joint, which allows a portion of it the vibratory motion necessary to keep the pinion in gear."
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: 15.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, -10.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.55184, -9.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.48528, -8.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.32575, -7.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.06405, -6.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.69208, -5.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.20297, -4.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.59111, -3.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.85226, -1.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.98355, -0.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.98355, 0.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.85226, 1.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.59111, 3.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.20297, 4.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.69208, 5.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.06405, 6.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.32575, 7.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.48528, 8.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.55184, 9.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [6.53567, 10.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [5.44789, 10.69208], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [4.30042, 11.20297], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [3.10583, 11.59111], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [1.87721, 11.85226], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [0.62803, 11.98355], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-0.62803, 11.98355], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-1.87721, 11.85226], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-3.10583, 11.59111], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-4.30042, 11.20297], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-5.44789, 10.69208], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.53567, 10.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.55184, 9.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.48528, 8.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.32575, 7.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.06405, 6.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.69208, 5.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.20297, 4.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.59111, 3.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.85226, 1.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.98355, 0.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.98355, -0.62803], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.85226, -1.87721], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.59111, -3.10583], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.20297, -4.30042], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.69208, -5.44789], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.06405, -6.53567], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.32575, -7.55184], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.48528, -8.48528], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.55184, -9.32575], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.53567, -10.06405], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: band, center: [0.0, 0.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, 0.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, 0.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, -10.06405], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [-6.53567, -10.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, -10.06405], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [6.53567, -10.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, 2.18313], collide: 0, color: "#8f8a80"}   # the balance weight, behind the face plate
  - id: arm
    shape: part
    pos: [-20.0, 0, 10.0]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 10.0], radius: 0.5, y: [0.05, 0.75], collide: 2}            # the follower in the groove
      - {kind: poly, points: [[-20.0, 9.55], [0, 9.55], [0, 10.45], [-20.0, 10.45]], y: [-3.3, -2.7], collide: 0}   # the arm
      - {kind: disc, center: [0, 10.0], radius: 0.9, y: [-3.3, -2.7], collide: 0}   # its boss
      - {kind: disc, center: [-20.0, 10.0], radius: 0.9, y: [-3.3, -2.7], collide: 0}   # its eye on the pivot
      - {kind: rod, from: [0, -2.7, 10.0], to: [0, -1.05, 10.0], radius: 0.3, collide: 0}
  - id: pinion
    shape: part
    mount: arm
    pos: [0, 0, 10.0]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, 10.0], radius: 1.5, y: [-1.0, -0.05], collide: 0}
      - {kind: poly, points: [[0.4085, 11.45], [-0.4085, 11.45], [-0.05545, 12.42], [0.05545, 12.42]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.5218, 11.41319], [-1.18277, 10.93296], [-1.4673, 11.92523], [-1.37758, 11.99041]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.2528, 10.83658], [-1.50527, 10.05957], [-2.31869, 10.69508], [-2.28442, 10.80056]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.50527, 9.94043], [-1.2528, 9.16342], [-2.28442, 9.19944], [-2.31869, 9.30492]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.18277, 9.06704], [-0.5218, 8.58681], [-1.37758, 8.00959], [-1.4673, 8.07477]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.4085, 8.55], [0.4085, 8.55], [0.05545, 7.58], [-0.05545, 7.58]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.5218, 8.58681], [1.18277, 9.06704], [1.4673, 8.07477], [1.37758, 8.00959]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.2528, 9.16342], [1.50527, 9.94043], [2.31869, 9.30492], [2.28442, 9.19944]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.50527, 10.05957], [1.2528, 10.83658], [2.28442, 10.80056], [2.31869, 10.69508]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.18277, 10.93296], [0.5218, 11.41319], [1.37758, 11.99041], [1.4673, 11.92523]], y: [-1.0, -0.05], collide: 2}
  - id: frame
    shape: frame
    color: "#8f8a80"
    rods:
      - {from: [-20.0, -4.0, 10.0], to: [-20.0, 2.0, 10.0], radius: 0.5}   # the arm's pivot pin
      - {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_arm, type: hinge, body: arm, axis: [0, -1, 0], damping: 0.5, range: [-0.03, 0.23208]}   # +: the pinion end rises
  - {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, out: j_wheel, in: j_pinion, expect: 0.16667, tol: 0.005, settle_s: 0.5, window_s: 3.5}   # inside the pins: same way round, rp/R
  - {type: ratio, out: j_wheel, in: j_pinion, expect: -0.16667, tol: 0.005, settle_s: 6.5, window_s: 7.5}   # outside, after the end pin: back at the same speed
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [-7.0, 0, 1.5], position: [-7.0, -112, 2.5], fov: 34}
display:
  output: j_wheel
  labels: {j_pinion: "Pinion (driver, one way)", j_wheel: "Mangle-wheel (to and fro, equal speeds)", j_arm: "Swinging pinion shaft"}
  proof: {label: "Pins out of contact", sub: "the pinion turns alone: the wheel stands still"}

