# No. 193 (Brown 1868): "Another kind of mangle-wheel with its pinion. ... although the pinion continues to revolve in one direction, the mangle-wheel will
#  make almost an entire revolution in one direction and the same in an opposite direction; but the revolution of the wheel will be slower in one direction than the other."
#
# Model (cm): the wheel turns on a shaft at the origin. On its face stand two circles of round pins (r 0.35, pitch 1.2566) over 252 deg with the gap at the bottom:
# 36 on radius 10 and 50 on radius 14, joined at each end by a half-round of pins (radius 2, 5 pitches), so they make one closed row like a ring with
# teeth on both edges. Behind the pins the guiding groove follows: a track 2 inside the inner circle, one 2 outside the outer, joined round the ends. A 10-tooth pinion
# (pitch radius 2) turns in a carriage that slides in the stationary upright slot (x = 0), its follower in the groove. Only the pinion is driven (30 rpm, one way).
# Inside the inner circle it drives the wheel the same way round at rp/10 = 0.200 of its speed; it walks round the end, and outside the outer circle drives it back
# at rp/14 = 0.1429: slower one way than the other. Generator: opencode-runs/batch11/gen193.py.
number: 193
slug: mangle-wheel-two-circles
name: A mangle-wheel with two circles of teeth
brown: "Another kind of mangle-wheel with its pinion. Although the pinion continues to revolve in one direction, the mangle-wheel will make almost an entire revolution in one direction and the same in an opposite direction; but the revolution of the wheel will be slower in one direction than the other."
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: [8.09017, -5.87785], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.76307, -4.81754], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.29776, -3.68125], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.68583, -2.4869], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.92115, -1.25333], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.0, 0.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.92115, 1.25333], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.68583, 2.4869], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.29776, 3.68125], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.76307, 4.81754], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.09017, 5.87785], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.28969, 6.84547], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [6.37424, 7.70513], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [5.35827, 8.44328], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [4.25779, 9.04827], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [3.09017, 9.51057], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [1.87381, 9.82287], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [0.62791, 9.98027], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-0.62791, 9.98027], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-1.87381, 9.82287], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-3.09017, 9.51057], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-4.25779, 9.04827], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-5.35827, 8.44328], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.37424, 7.70513], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.28969, 6.84547], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.09017, 5.87785], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.76307, 4.81754], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.29776, 3.68125], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.68583, 2.4869], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.92115, 1.25333], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.0, 0.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.92115, -1.25333], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.68583, -2.4869], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.29776, -3.68125], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.76307, -4.81754], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.09017, -5.87785], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.32624, -8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [12.01828, -7.18059], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [12.61356, -6.07437], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.10729, -4.91925], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.49548, -3.72452], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.77501, -2.4998], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.94364, -1.25495], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [14.0, 0.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.94364, 1.25495], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.77501, 2.4998], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.49548, 3.72452], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [13.10729, 4.91925], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [12.61356, 6.07437], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [12.01828, 7.18059], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [11.32624, 8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [10.543, 9.21114], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [9.67488, 10.11913], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.72886, 10.94564], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.71256, 11.68403], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [6.63416, 12.32834], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [5.50235, 12.87339], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [4.32624, 13.31479], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [3.11529, 13.64899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [1.87927, 13.8733], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [0.62811, 13.9859], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-0.62811, 13.9859], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-1.87927, 13.8733], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-3.11529, 13.64899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-4.32624, 13.31479], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-5.50235, 12.87339], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.63416, 12.32834], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.71256, 11.68403], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-8.72886, 10.94564], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-9.67488, 10.11913], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-10.543, 9.21114], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.32624, 8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-12.01828, 7.18059], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-12.61356, 6.07437], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.10729, 4.91925], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.49548, 3.72452], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.77501, 2.4998], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.94364, 1.25495], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-14.0, 0.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.94364, -1.25495], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.77501, -2.4998], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.49548, -3.72452], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-13.10729, -4.91925], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-12.61356, -6.07437], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-12.01828, -7.18059], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-11.32624, -8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.7082, -7.05342], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [-8.09017, -8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [-9.09017, -8.95554], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [-10.32624, -8.95554], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [7.7082, -7.05342], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [8.09017, -8.22899], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [9.09017, -8.95554], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: disc, center: [10.32624, -8.95554], radius: 0.35, y: [-1.0, -0.05], collide: 1}   # the half-round of pins
      - {kind: band, center: [0, 0], r: [6.87, 7.47], a: [-0.62832, 3.76991], y: [0.05, 0.8], collide: 1}   # the groove's inner wall
      - {kind: band, center: [0, 0], r: [8.53, 15.47], a: [-0.62832, 3.76991], y: [0.05, 0.8], collide: 1}   # the island between the tracks
      - {kind: band, center: [0, 0], r: [16.53, 17.13], a: [-0.62832, 3.76991], y: [0.05, 0.8], collide: 1}   # the outer wall
      - {kind: disc, center: [-9.7082, -7.05342], radius: 3.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [-9.7082, -7.05342], r: [4.53, 5.13], a: [3.76991, 6.9115], slices: 18, y: [0.05, 0.8], collide: 1}   # the groove round the end
      - {kind: disc, center: [9.7082, -7.05342], radius: 3.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [9.7082, -7.05342], r: [4.53, 5.13], a: [-3.76991, -0.62832], slices: 18, y: [0.05, 0.8], collide: 1}   # the groove round the end
  - id: carriage
    shape: part
    pos: [0, 0, 8.0]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 8.0], radius: 0.5, y: [0.05, 0.75], collide: 2}            # the follower in the groove
      - {kind: poly, points: [[-0.7, 7.3], [0.7, 7.3], [0.7, 8.7], [-0.7, 8.7]], y: [-3.4, -2.6], collide: 0}   # its block in the upright's slot
      - {kind: rod, from: [0, -2.6, 8.0], to: [0, -1.05, 8.0], radius: 0.3, collide: 0}
  - id: pinion
    shape: part
    mount: carriage
    pos: [0, 0, 8.0]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, 8.0], radius: 1.5, y: [-1.0, -0.05], collide: 0}
      - {kind: poly, points: [[0.4085, 9.45], [-0.4085, 9.45], [-0.05545, 10.42], [0.05545, 10.42]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.5218, 9.41319], [-1.18277, 8.93296], [-1.4673, 9.92523], [-1.37758, 9.99041]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.2528, 8.83658], [-1.50527, 8.05957], [-2.31869, 8.69508], [-2.28442, 8.80056]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.50527, 7.94043], [-1.2528, 7.16342], [-2.28442, 7.19944], [-2.31869, 7.30492]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.18277, 7.06704], [-0.5218, 6.58681], [-1.37758, 6.00959], [-1.4673, 6.07477]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.4085, 6.55], [0.4085, 6.55], [0.05545, 5.58], [-0.05545, 5.58]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.5218, 6.58681], [1.18277, 7.06704], [1.4673, 6.07477], [1.37758, 6.00959]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.2528, 7.16342], [1.50527, 7.94043], [2.31869, 7.30492], [2.28442, 7.19944]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.50527, 8.05957], [1.2528, 8.83658], [2.28442, 8.80056], [2.31869, 8.69508]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.18277, 8.93296], [0.5218, 9.41319], [1.37758, 9.99041], [1.4673, 9.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: [-1.5, 9.5]}
  - {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.2, tol: 0.006, settle_s: 0.5, window_s: 2.5}     # inside the inner circle: same way round
  - {type: ratio, out: j_wheel, in: j_pinion, expect: -0.14286, tol: 0.00429, settle_s: 6.0, window_s: 7.0}      # outside the outer circle: back, slower
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, 1], position: [0, -100, 2], fov: 34}
display:
  output: j_wheel
  labels: {j_pinion: "Pinion (driver, one way)", j_wheel: "Mangle-wheel (to and fro, slower back)", j_lift: "Pinion carriage"}
  proof: {label: "Pins out of contact", sub: "the pinion turns alone: the wheel stands still"}

