# No. 198 (Brown 1868): "A modification of 197. In this the pinion revolves, but does not rise and fall as in the former figure. The portion of the frame
#  carrying the rack is jointed to the main portion of the frame by rods, so that when the pinion arrives at the end it lifts the rack by its own movement,
#  and follows on the other side."
#
# Model (cm): the main square frame slides along x on its guides. Within it hangs a rack plate carrying No. 197's rack: a row of 15 round pins (r 0.35) at
# pitch 1.257, and behind them a groove, tracks 2 above and 2 below the row joined by half-rounds about the end pins, between an island and guides.
# The plate hangs from the main frame on two equal parallel rods (22 long), so it stays level and can rise and fall 4 relative to the frame.
# A 10-tooth pinion (pitch radius 2) turns on a fixed shaft, its follower in the groove. Only the pinion is driven (10 rpm, one way). Above the pins
# it drives the frame one way at 2 cm a radian; at the end it lifts the plate 4 by its own movement round the end pin and drives the frame back
# from underneath; at the other end the plate drops back by its weight under the follower's guide. The plate draws the two rods pivoted at opposite ends;
# here both pivot at the same end (a parallelogram) so the rack stays level.
# Generator: opencode-runs/batch11/gen198.py.
number: 198
slug: mangle-rack-on-rods
name: A mangle-rack on rods
brown: "A modification of 197. In this the pinion revolves, but does not rise and fall as in the former figure. The portion of the frame carrying the rack is jointed to the main portion of the frame by rods, so that when the pinion arrives at the end it lifts the rack by its own movement, and follows on the other side."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 20.1
  floor: false
bodies:
  - id: frame
    shape: part
    pos: [0, 0, 0]
    density: 2700
    color: "#d9ccae"
    pieces:
      - {kind: poly, points: [[-17.79646, -10.0], [17.79646, -10.0], [17.79646, -9.2], [-17.79646, -9.2]], y: [1.8, 2.4], collide: 0}   # the main square frame
      - {kind: poly, points: [[-17.79646, 9.2], [17.79646, 9.2], [17.79646, 10.0], [-17.79646, 10.0]], y: [1.8, 2.4], collide: 0}
      - {kind: poly, points: [[-17.79646, -10.0], [-16.99646, -10.0], [-16.99646, 10.0], [-17.79646, 10.0]], y: [1.8, 2.4], collide: 0}
      - {kind: poly, points: [[16.99646, -10.0], [17.79646, -10.0], [17.79646, 10.0], [16.99646, 10.0]], y: [1.8, 2.4], collide: 0}
      - {kind: poly, points: [[-8.98244, 3.43], [-7.78244, 3.43], [-7.78244, 9.2], [-8.98244, 9.2]], y: [1.2, 2.4], collide: 0}   # the posts carrying the rods' pivots
      - {kind: poly, points: [[-8.98244, -9.2], [-7.78244, -9.2], [-7.78244, -3.43], [-8.98244, -3.43]], y: [1.2, 2.4], collide: 0}
      - {kind: rod, from: [-8.38244, -1.9, 4.03], to: [-8.38244, 2.4, 4.03], radius: 0.3, collide: 0}
      - {kind: rod, from: [-8.38244, -1.9, -4.03], to: [-8.38244, 2.4, -4.03], radius: 0.3, collide: 0}
  - id: rod_u
    shape: part
    mount: frame
    pos: [-8.38244, 0, 4.03]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-8.38244, -1.9, 4.03], to: [13.52646, -1.9, 2.03], radius: 0.35, collide: 0}
  - id: rod_l
    shape: part
    mount: frame
    pos: [-8.38244, 0, -4.03]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-8.38244, -1.9, -4.03], to: [13.52646, -1.9, -6.03], radius: 0.35, collide: 0}
  - id: rack
    shape: part
    mount: rod_u
    pos: [13.52646, 0, 2.03]
    density: 2700
    friction: 0.1
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [-8.79646, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-7.53982, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-6.28319, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-5.02655, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-3.76991, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-2.51327, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [-1.25664, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [0.0, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [1.25664, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [2.51327, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [3.76991, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [5.02655, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [6.28319, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [7.53982, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: disc, center: [8.79646, -2.0], radius: 0.35, y: [-1.0, -0.05], collide: 1}
      - {kind: poly, points: [[-8.79646, -3.47], [8.79646, -3.47], [8.79646, -0.53], [-8.79646, -0.53]], y: [0.05, 0.8], collide: 1}   # the island between the tracks
      - {kind: poly, points: [[-8.79646, 0.53], [8.79646, 0.53], [8.79646, 1.13], [-8.79646, 1.13]], y: [0.05, 0.8], collide: 1}   # the upper guide
      - {kind: poly, points: [[-8.79646, -4.53], [8.79646, -4.53], [8.79646, -5.13], [-8.79646, -5.13]], y: [0.05, 0.8], collide: 1}   # the lower guide
      - {kind: disc, center: [8.79646, -2.0], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [8.79646, -2.0], r: [2.53, 3.13], a: [-1.5708, 1.5708], slices: 18, y: [0.05, 0.8], collide: 1}   # the guide round the end
      - {kind: disc, center: [-8.79646, -2.0], radius: 1.47, y: [0.05, 0.8], collide: 1}   # the island's round end
      - {kind: band, center: [-8.79646, -2.0], r: [2.53, 3.13], a: [1.5708, 4.71239], slices: 18, y: [0.05, 0.8], collide: 1}   # the guide round the end
      - {kind: poly, points: [[-13.52646, 1.68], [13.52646, 1.68], [13.52646, 2.38], [-13.52646, 2.38]], y: [0.8, 1.4], collide: 0}
      - {kind: poly, points: [[-13.52646, -6.38], [13.52646, -6.38], [13.52646, -5.68], [-13.52646, -5.68]], y: [0.8, 1.4], collide: 0}
      - {kind: poly, points: [[13.17646, -6.03], [13.87646, -6.03], [13.87646, 2.03], [13.17646, 2.03]], y: [0.8, 1.4], collide: 0}
      - {kind: poly, points: [[-13.87646, -6.03], [-13.17646, -6.03], [-13.17646, 2.03], [-13.87646, 2.03]], y: [0.8, 1.4], collide: 0}
      - {kind: rod, from: [13.52646, -1.9, 2.03], to: [13.52646, 1.4, 2.03], radius: 0.3, collide: 0}
      - {kind: rod, from: [13.52646, -1.9, -6.03], to: [13.52646, 1.4, -6.03], radius: 0.3, collide: 0}
  - id: pinion
    shape: part
    pos: [0, 0, 0.0]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, 0.0], radius: 1.5, y: [-1.0, -0.05], collide: 0}
      - {kind: disc, center: [0, 0.0], radius: 0.5, y: [0.05, 0.75], collide: 2}            # the follower in the groove
      - {kind: rod, from: [0, 0.75, 0.0], to: [0, 3.4, 0.0], radius: 0.3, collide: 0}   # the fixed shaft, to its standard behind
      - {kind: poly, points: [[-0.05957, 1.50527], [-0.83658, 1.2528], [-0.80056, 2.28442], [-0.69508, 2.31869]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.93296, 1.18277], [-1.41319, 0.5218], [-1.99041, 1.37758], [-1.92523, 1.4673]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.45, 0.4085], [-1.45, -0.4085], [-2.42, -0.05545], [-2.42, 0.05545]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-1.41319, -0.5218], [-0.93296, -1.18277], [-1.92523, -1.4673], [-1.99041, -1.37758]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[-0.83658, -1.2528], [-0.05957, -1.50527], [-0.69508, -2.31869], [-0.80056, -2.28442]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.05957, -1.50527], [0.83658, -1.2528], [0.80056, -2.28442], [0.69508, -2.31869]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.93296, -1.18277], [1.41319, -0.5218], [1.99041, -1.37758], [1.92523, -1.4673]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.45, -0.4085], [1.45, 0.4085], [2.42, 0.05545], [2.42, -0.05545]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[1.41319, 0.5218], [0.93296, 1.18277], [1.92523, 1.4673], [1.99041, 1.37758]], y: [-1.0, -0.05], collide: 2}
      - {kind: poly, points: [[0.83658, 1.2528], [0.05957, 1.50527], [0.69508, 2.31869], [0.80056, 2.28442]], y: [-1.0, -0.05], collide: 2}
  - id: standard
    shape: frame
    color: "#8f8a80"
    rods:
      - {from: [0, 3.6, 0.0], to: [0, 3.6, -14.0], radius: 0.5}   # the pinion shaft's standard
      - {from: [-27.79646, 2.6, 10.7], to: [27.79646, 2.6, 10.7], radius: 0.3}   # the main frame's guides
      - {from: [-27.79646, 2.6, -10.7], to: [27.79646, 2.6, -10.7], radius: 0.3}
pins:
  - {id: p_rod_l, a: rod_l, b: rack, at: [13.52646, 0, -6.03]}   # the lower rod's pin in the rack plate
joints:
  - {id: j_frame, type: slide, body: frame, axis: [1, 0, 0], damping: 0.5, range: [-11.79646, 11.79646]}
  - {id: j_rod_u, type: hinge, body: rod_u, axis: [0, -1, 0], damping: 0.05, range: [-0.21103, 0.30207]}   # 0 at the start (rack down); +: rising
  - {id: j_rod_l, type: hinge, body: rod_l, axis: [0, -1, 0], damping: 0.05}
  - {id: j_rack, type: hinge, body: rack, axis: [0, -1, 0], damping: 0.05}   # the rack plate's pin in the upper rod
  - {id: j_pinion, type: hinge, body: pinion, axis: [0, -1, 0], damping: 0.001}   # the one driven joint; +: counter-clockwise
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_pinion, kind: velocity, rpm: 10.0, kv: 1.5, max_torque: 6}
checks:
  - {type: ratio, out: j_frame, in: j_pinion, expect: 0.02, tol: 0.0006, settle_s: 0.5, window_s: 3.2}   # above the pins: the frame goes right at rp a radian
  - {type: ratio, out: j_frame, in: j_pinion, expect: -0.02, tol: 0.0006, settle_s: 8.2, window_s: 6.4}   # under them, the plate lifted: back at the same speed
  - {type: amplitude, joint: j_rod_u, min: 0.08466, max: 0.09741, settle_s: 0.5, window_s: 19.1}   # the rods swing through 2 asin(rp/L): the plate lifts 2 rp
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, 0], position: [0, -105, 1], fov: 34}
display:
  output: j_frame
  labels: {j_pinion: "Pinion (driver, one way)", j_frame: "Main frame (to and fro)", j_rod_u: "Rods (rack plate lifts)"}
  proof: {label: "Pins out of contact", sub: "the pinion turns alone: the frame stands still"}

