# No. 395 (Brown 1868): "Four-way cock, used many years ago on steam engines to admit and exhaust steam from the cylinder. The two positions represented
# are produced by a quarter turn of the plug."
#
# Model (cm, Brown's section): the casing has four ports, top (steam), bottom (exhaust), left and right (the cylinder's two ends). The plug has two
# curved ways, each joining two neighbouring ports. A key in the plug's square socket is turned to and fro by the hand (the one driven joint: a torque
# of 1.5 N·m one way, then the other, 0.2 times a second), and turns the plug only through the socket's walls (real contact); a lug on the plug
# brings it up against one of two stops on the casing a quarter turn apart. In one position the steam (top) goes to the left port and the right port
# exhausts; a quarter turn later the steam goes to the right and the left exhausts. Generator: opencode-runs/batch13/gen395.py.
number: 395
slug: four-way-cock
name: Four-way cock
brown: "Four-way cock, used many years ago on steam engines to admit and exhaust steam from the cylinder. The two positions represented are produced by a quarter turn of the plug. Supposing the steam to enter at the top, in the upper figure the exhaust is from the right end of the cylinder, and in the lower figure the exhaust is from the left—the steam entering, of course, in the opposite port."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 60, solver: PGS, duration_s: 10, floor: false, gravity: 0}
bodies:
  - id: casing
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#b5a98f"
    pieces:
      - {kind: poly, points: [[10.0, 0.0], [9.8481, 1.7365], [11.8177, 2.0838], [12.0, 0.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[9.8481, 1.7365], [9.3969, 3.4202], [11.2763, 4.1042], [11.8177, 2.0838]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[9.3969, 3.4202], [8.6603, 5.0], [10.3923, 6.0], [11.2763, 4.1042]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[8.6603, 5.0], [7.6604, 6.4279], [9.1925, 7.7135], [10.3923, 6.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[7.6604, 6.4279], [6.4279, 7.6604], [7.7135, 9.1925], [9.1925, 7.7135]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[6.4279, 7.6604], [5.0, 8.6603], [6.0, 10.3923], [7.7135, 9.1925]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[5.0, 8.6603], [3.4202, 9.3969], [4.1042, 11.2763], [6.0, 10.3923]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[3.4202, 9.3969], [1.7365, 9.8481], [2.0838, 11.8177], [4.1042, 11.2763]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[1.7365, 9.8481], [0.0, 10.0], [0.0, 12.0], [2.0838, 11.8177]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[0.0, 10.0], [-1.7365, 9.8481], [-2.0838, 11.8177], [0.0, 12.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-1.7365, 9.8481], [-3.4202, 9.3969], [-4.1042, 11.2763], [-2.0838, 11.8177]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-3.4202, 9.3969], [-5.0, 8.6603], [-6.0, 10.3923], [-4.1042, 11.2763]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-5.0, 8.6603], [-6.4279, 7.6604], [-7.7135, 9.1925], [-6.0, 10.3923]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-6.4279, 7.6604], [-7.6604, 6.4279], [-9.1925, 7.7135], [-7.7135, 9.1925]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-7.6604, 6.4279], [-8.6603, 5.0], [-10.3923, 6.0], [-9.1925, 7.7135]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-8.6603, 5.0], [-9.3969, 3.4202], [-11.2763, 4.1042], [-10.3923, 6.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-9.3969, 3.4202], [-9.8481, 1.7365], [-11.8177, 2.0838], [-11.2763, 4.1042]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-9.8481, 1.7365], [-10.0, 0.0], [-12.0, 0.0], [-11.8177, 2.0838]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-10.0, 0.0], [-9.8481, -1.7365], [-11.8177, -2.0838], [-12.0, 0.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-9.8481, -1.7365], [-9.3969, -3.4202], [-11.2763, -4.1042], [-11.8177, -2.0838]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-9.3969, -3.4202], [-8.6603, -5.0], [-10.3923, -6.0], [-11.2763, -4.1042]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-8.6603, -5.0], [-7.6604, -6.4279], [-9.1925, -7.7135], [-10.3923, -6.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-7.6604, -6.4279], [-6.4279, -7.6604], [-7.7135, -9.1925], [-9.1925, -7.7135]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-6.4279, -7.6604], [-5.0, -8.6603], [-6.0, -10.3923], [-7.7135, -9.1925]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-5.0, -8.6603], [-3.4202, -9.3969], [-4.1042, -11.2763], [-6.0, -10.3923]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-3.4202, -9.3969], [-1.7365, -9.8481], [-2.0838, -11.8177], [-4.1042, -11.2763]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-1.7365, -9.8481], [-0.0, -10.0], [-0.0, -12.0], [-2.0838, -11.8177]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[-0.0, -10.0], [1.7365, -9.8481], [2.0838, -11.8177], [-0.0, -12.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[1.7365, -9.8481], [3.4202, -9.3969], [4.1042, -11.2763], [2.0838, -11.8177]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[3.4202, -9.3969], [5.0, -8.6603], [6.0, -10.3923], [4.1042, -11.2763]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[5.0, -8.6603], [6.4279, -7.6604], [7.7135, -9.1925], [6.0, -10.3923]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[6.4279, -7.6604], [7.6604, -6.4279], [9.1925, -7.7135], [7.7135, -9.1925]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[7.6604, -6.4279], [8.6603, -5.0], [10.3923, -6.0], [9.1925, -7.7135]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[8.6603, -5.0], [9.3969, -3.4202], [11.2763, -4.1042], [10.3923, -6.0]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[9.3969, -3.4202], [9.8481, -1.7365], [11.8177, -2.0838], [11.2763, -4.1042]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: poly, points: [[9.8481, -1.7365], [10.0, -0.0], [12.0, -0.0], [11.8177, -2.0838]], y: [-1.0, 1.0], collide: 0, color: "#b5a98f"}
      - {kind: rod, from: [11.6, 0, 2.2], to: [16.0, 0, 2.2], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [11.6, 0, -2.2], to: [16.0, 0, -2.2], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [-2.2, 0, 11.6], to: [-2.2, 0, 16.0], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [2.2, 0, 11.6], to: [2.2, 0, 16.0], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [-11.6, 0, -2.2], to: [-16.0, 0, -2.2], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [-11.6, 0, 2.2], to: [-16.0, 0, 2.2], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [2.2, 0, -11.6], to: [2.2, 0, -16.0], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [-2.2, 0, -11.6], to: [-2.2, 0, -16.0], radius: 0.45, color: "#8f8a80"}
      - {kind: rod, from: [10.1936, -2.6, 7.4061], to: [10.1936, -1.0, 7.4061], radius: 0.9, collide: 2, capsule: true, color: "#6f6a60"}   # stop A
      - {kind: rod, from: [-10.1936, -2.6, 7.4061], to: [-10.1936, -1.0, 7.4061], radius: 0.9, collide: 2, capsule: true, color: "#6f6a60"}   # stop B
  - id: plug
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 9.6, y: [-0.9, 0.9]}
      - {kind: poly, points: [[-8.3472, 2.1023], [-7.4297, 2.3146], [-6.8589, 0.3978], [-8.018, 0.1296]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-7.4297, 2.3146], [-6.5455, 2.6388], [-5.742, 0.8072], [-6.8589, 0.3978]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-6.5455, 2.6388], [-5.7081, 3.0698], [-4.6843, 1.3517], [-5.742, 0.8072]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-5.7081, 3.0698], [-4.9305, 3.6011], [-3.702, 2.0229], [-4.6843, 1.3517]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-4.9305, 3.6011], [-4.2245, 4.2245], [-2.8103, 2.8103], [-3.702, 2.0229]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-4.2245, 4.2245], [-3.6011, 4.9305], [-2.0229, 3.702], [-2.8103, 2.8103]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-3.6011, 4.9305], [-3.0698, 5.7081], [-1.3517, 4.6843], [-2.0229, 3.702]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-3.0698, 5.7081], [-2.6388, 6.5455], [-0.8072, 5.742], [-1.3517, 4.6843]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-2.6388, 6.5455], [-2.3146, 7.4297], [-0.3978, 6.8589], [-0.8072, 5.742]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[-2.3146, 7.4297], [-2.1023, 8.3472], [-0.1296, 8.018], [-0.3978, 6.8589]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[8.3472, -2.1023], [7.4297, -2.3146], [6.8589, -0.3978], [8.018, -0.1296]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[7.4297, -2.3146], [6.5455, -2.6388], [5.742, -0.8072], [6.8589, -0.3978]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[6.5455, -2.6388], [5.7081, -3.0698], [4.6843, -1.3517], [5.742, -0.8072]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[5.7081, -3.0698], [4.9305, -3.6011], [3.702, -2.0229], [4.6843, -1.3517]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[4.9305, -3.6011], [4.2245, -4.2245], [2.8103, -2.8103], [3.702, -2.0229]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[4.2245, -4.2245], [3.6011, -4.9305], [2.0229, -3.702], [2.8103, -2.8103]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[3.6011, -4.9305], [3.0698, -5.7081], [1.3517, -4.6843], [2.0229, -3.702]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[3.0698, -5.7081], [2.6388, -6.5455], [0.8072, -5.742], [1.3517, -4.6843]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[2.6388, -6.5455], [2.3146, -7.4297], [0.3978, -6.8589], [0.8072, -5.742]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[2.3146, -7.4297], [2.1023, -8.3472], [0.1296, -8.018], [0.3978, -6.8589]], y: [-0.95, -0.9], collide: 0, color: "#6f5a3e"}
      - {kind: poly, points: [[8.3439, 6.9296], [10.3238, 8.9095], [8.9095, 10.3238], [6.9296, 8.3439]], y: [-2.6, -1.0], collide: 1, color: "#a39d90"}   # the lug
      - {kind: poly, points: [[6.364, 4.9497], [8.4853, 7.0711], [7.0711, 8.4853], [4.9497, 6.364]], y: [-2.6, -0.9], color: "#a39d90"}   # its arm
      - {kind: poly, points: [[-2.0, -2.0], [2.0, -2.0], [2.0, -1.2], [-2.0, -1.2]], y: [-2.6, -0.9], collide: 2, color: "#a39d90"}   # the socket
      - {kind: poly, points: [[-2.0, 1.2], [2.0, 1.2], [2.0, 2.0], [-2.0, 2.0]], y: [-2.6, -0.9], collide: 2, color: "#a39d90"}   # the socket
      - {kind: poly, points: [[-2.0, -1.2], [-1.2, -1.2], [-1.2, 1.2], [-2.0, 1.2]], y: [-2.6, -0.9], collide: 2, color: "#a39d90"}   # the socket
      - {kind: poly, points: [[1.2, -1.2], [2.0, -1.2], [2.0, 1.2], [1.2, 1.2]], y: [-2.6, -0.9], collide: 2, color: "#a39d90"}   # the socket
  - id: key
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: poly, points: [[-1.15, -1.15], [1.15, -1.15], [1.15, 1.15], [-1.15, 1.15]], y: [-2.5, -0.95], collide: 1}   # its square shank
      - {kind: poly, points: [[-0.6, -0.6], [0.6, -0.6], [0.6, 7.0], [-0.6, 7.0]], y: [-3.4, -2.6]}   # its handle (a slim bar)
      - {kind: disc, center: [0, 0], radius: 1.4, y: [-3.4, -2.6]}
joints:
  - {id: j_k, type: hinge, body: key, axis: [0, 1, 0], damping: 0.05}   # the key: the one driven joint; + : clockwise in the view
  - {id: j_p, type: hinge, body: plug, axis: [0, 1, 0], damping: 0.3, frictionloss: 0.05}   # the plug in its casing (packing friction)
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.001], margin: 0}
driver: {joint: j_k, kind: feet, feet: {joints: [j_k, j_k], sign: [-1, 1], force: 1.5, hz: 0.2}, max_torque: 10}
checks:
  - {type: position, joint: j_p, min: -1.62, max: -1.53, settle_s: 1.3, window_s: 1.1}   # first rest: a quarter turn, against stop B
  - {type: position, joint: j_p, min: -0.05, max: 0.05, settle_s: 3.8, window_s: 1.1}   # turned back against stop A
  - {type: position, joint: j_p, min: -1.62, max: -1.53, settle_s: 6.3, window_s: 1.1}
  - {type: penetration, max: 0.002, settle_s: 0.5}
camera: {target: [0, 0, -5.5], position: [0, -78, -5.5], fov: 34}
display:
  output: j_p
  labels: {j_k: "Key (driver)", j_p: "Plug"}
