# No. 36, Mangle-wheel and pinion (Brown 1868).
#
# "Mangle-wheel and pinion—so called from their application to mangles—converts continuous rotary
#  motion of pinion into reciprocating rotary motion of wheel. The shaft of pinion has a vibratory
#  motion, and works in a straight slot cut in the upright stationary bar to allow the pinion to
#  rise and fall and work inside and outside of the gearing of the wheel. The slot cut in the face
#  of the mangle-wheel and following its contour is for the reception and guidance of the pinion-
#  shaft, and keeping the pinion in gear."
#
# Laid out as in the plate (1 unit = 1 cm; the drawing plane is x-z, depth is y): 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 at
# pitch 1.257, over 294 deg, with the gap at the bottom. Behind the pins' layer the face carries
# the guiding groove: a track 2 inside the pins, a track 2 outside them, 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); the carriage's follower (r 0.5) runs in the groove.
# Generator: opencode-runs/batch7/gen036.py.
#
# Fully physical. Only the pinion is motor-driven (30 rpm, one way). Inside the pins it drives the
# wheel the same way round at rp/R = 2/12 = 0.167 of its speed; at the end pin the groove carries
# it round to the outside and the wheel runs back at -0.167; and so on.
number: 36
slug: mangle-wheel-and-pinion
name: Mangle-wheel and pinion
brown: "Mangle-wheel and pinion—so called from their application to mangles—converts continuous rotary motion of pinion into reciprocating rotary motion of 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: 16.2, 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], 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], 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], 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
  - id: carriage
    shape: part
    pos: [0, 0, 10]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 10], radius: 0.5, y: [0.05, 0.75], collide: 2}            # the follower in the groove
      - {kind: poly, points: [[-0.7, 9.3], [0.7, 9.3], [0.7, 10.7], [-0.7, 10.7]], y: [-3.4, -2.6], collide: 0}   # its block in the upright's slot
      - {kind: rod, from: [0, -2.6, 10], to: [0, -1.05, 10], radius: 0.3, collide: 0}
  - id: pinion
    shape: part
    mount: carriage
    pos: [0, 0, 10]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, 10], 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: 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, 5.5]}
  - {id: j_pinion, type: hinge, body: pinion, axis: [0, 1, 0], damping: 0.001}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_pinion, kind: velocity, rpm: 30, kv: 4, max_torque: 6}
checks:
  - {type: ratio, out: j_wheel, in: j_pinion, expect: 0.16667, tol: 0.004, settle_s: 0.5, window_s: 4}     # inside the pins: same way round
  - {type: ratio, out: j_wheel, in: j_pinion, expect: -0.16667, tol: 0.004, settle_s: 7, window_s: 8}      # outside them, after the end pin: back
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, 1], position: [0, -95, 2], fov: 34}
display:
  output: j_wheel
  labels: {j_pinion: "Pinion (driver, one way)", j_wheel: "Mangle-wheel (to and fro)"}
  proof: {label: "Pins out of contact", sub: "the pinion turns alone: the wheel stands still"}
