number: 329
slug: piston-rod-guide-cog-wheel-internal-gear
name: A piston-rod guide
brown: "A piston-rod guide. The piston-rod, A, is connected with a wrist attached to a cog-wheel, B, which turns on a crank-pin, carried by a plate, C, which is fast on the shaft. The wheel, B, revolves around a stationary internally toothed gear, D, of double the diameter of B, and so motion is given to the crank-pin, and the piston-rod is kept upright."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 100, solver: CG, multiccd: true, duration_s: 8, floor: false}
bodies:
  # the frame: the stationary internally toothed gear D (32 teeth), the shaft's bearing behind, and the
  # gland the piston-rod passes through
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    density: 7800
    friction: 0.1
    color: "#9a9284"
    pieces:
      - {kind: band, center: [0, 0], r: [10.1800, 11.4000], a: [0, 6.2831853], y: [-0.8, 0.8], collide: 0, color: "#b9ab8e"}
      - {kind: poly, points: [[-11.8000, -13.2000], [-11.2000, -13.2000], [-11.2000, 12.2000], [-11.8000, 12.2000]], y: [-2.4, 0.8], collide: 0}
      - {kind: poly, points: [[11.2000, -13.2000], [11.8000, -13.2000], [11.8000, 12.2000], [11.2000, 12.2000]], y: [-2.4, 0.8], collide: 0}
      - {kind: poly, points: [[-11.3000, -0.8000], [-10.1000, -0.8000], [-10.1000, 0.8000], [-11.3000, 0.8000]], y: [-0.8, 0.8], collide: 0}
      - {kind: poly, points: [[10.1000, -0.8000], [11.3000, -0.8000], [11.3000, 0.8000], [10.1000, 0.8000]], y: [-0.8, 0.8], collide: 0}
      - {kind: poly, points: [[-13.2000, -14.2000], [13.2000, -14.2000], [13.2000, -13.2000], [-13.2000, -13.2000]], y: [-2.4, 6.0], collide: 0}
      - {kind: poly, points: [[-1.0000, -13.2000], [1.0000, -13.2000], [1.0000, 0.0000], [-1.0000, 0.0000]], y: [5.0, 6.0], collide: 0}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [5.0, 6.0], collide: 0}
      - {kind: poly, points: [[-11.2000, 10.6000], [-0.4200, 10.6000], [-0.4200, 12.2000], [-11.2000, 12.2000]], y: [-2.4, -0.9], collide: 0}
      - {kind: poly, points: [[0.4200, 10.6000], [11.2000, 10.6000], [11.2000, 12.2000], [0.4200, 12.2000]], y: [-2.4, -0.9], collide: 0}
      - {kind: poly, points: [[-21.4, -29.0], [-19.4, -29.0], [0.8, -0.6], [-0.8, 0.6]], y: [8.6, 9.6], collide: 0}   # the fly-wheel's splayed legs, behind it (Brown's A-frame)
      - {kind: poly, points: [[19.4, -29.0], [21.4, -29.0], [0.8, 0.6], [-0.8, -0.6]], y: [8.6, 9.6], collide: 0}
      - {kind: disc, center: [0, 0], radius: 1.4, y: [8.6, 9.8], collide: 0}   # its bearing
      - {kind: poly, points: [[-28.0, -30.0], [28.0, -30.0], [28.0, -29.0], [-28.0, -29.0]], y: [-2.4, 10.0], collide: 0}   # the floor
      - {kind: poly, points: [[-1.0, -29.0], [1.0, -29.0], [1.0, -14.2], [-1.0, -14.2]], y: [-1.6, 0.6], collide: 0}   # the frame's stand, down to the floor
      - {kind: poly, points: [[-1.2000, 10.6000], [-0.4200, 10.6000], [-0.4200, 12.2000], [-1.2000, 12.2000]], y: [-2.4, -0.9], collide: 1, color: "#7d776c"}
      - {kind: poly, points: [[0.4200, 10.6000], [1.2000, 10.6000], [1.2000, 12.2000], [0.4200, 12.2000]], y: [-2.4, -0.9], collide: 1, color: "#7d776c"}
      - {kind: poly, points: [[9.1615, 0.6392], [9.1101, 1.1604], [10.0888, 1.6298], [10.2129, 0.3698]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[8.8607, 2.4143], [8.7087, 2.9154], [9.577, 3.5667], [9.9446, 2.3551]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[8.2195, 4.0965], [7.9726, 4.5583], [8.6972, 5.3666], [9.294, 4.2499]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[7.2623, 5.6213], [6.9301, 6.0261], [7.4831, 6.9602], [8.2863, 5.9814]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[6.0261, 6.9301], [5.6213, 7.2623], [5.9814, 8.2863], [6.9602, 7.4831]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[4.5583, 7.9726], [4.0965, 8.2195], [4.2499, 9.294], [5.3666, 8.6972]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[2.9154, 8.7087], [2.4143, 8.8607], [2.3551, 9.9446], [3.5667, 9.577]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[1.1604, 9.1101], [0.6392, 9.1615], [0.3698, 10.2129], [1.6298, 10.0888]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-0.6392, 9.1615], [-1.1604, 9.1101], [-1.6298, 10.0888], [-0.3698, 10.2129]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-2.4143, 8.8607], [-2.9154, 8.7087], [-3.5667, 9.577], [-2.3551, 9.9446]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-4.0965, 8.2195], [-4.5583, 7.9726], [-5.3666, 8.6972], [-4.2499, 9.294]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.6213, 7.2623], [-6.0261, 6.9301], [-6.9602, 7.4831], [-5.9814, 8.2863]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-6.9301, 6.0261], [-7.2623, 5.6213], [-8.2863, 5.9814], [-7.4831, 6.9602]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-7.9726, 4.5583], [-8.2195, 4.0965], [-9.294, 4.2499], [-8.6972, 5.3666]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-8.7087, 2.9154], [-8.8607, 2.4143], [-9.9446, 2.3551], [-9.577, 3.5667]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-9.1101, 1.1604], [-9.1615, 0.6392], [-10.2129, 0.3698], [-10.0888, 1.6298]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-9.1615, -0.6392], [-9.1101, -1.1604], [-10.0888, -1.6298], [-10.2129, -0.3698]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-8.8607, -2.4143], [-8.7087, -2.9154], [-9.577, -3.5667], [-9.9446, -2.3551]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-8.2195, -4.0965], [-7.9726, -4.5583], [-8.6972, -5.3666], [-9.294, -4.2499]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-7.2623, -5.6213], [-6.9301, -6.0261], [-7.4831, -6.9602], [-8.2863, -5.9814]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-6.0261, -6.9301], [-5.6213, -7.2623], [-5.9814, -8.2863], [-6.9602, -7.4831]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-4.5583, -7.9726], [-4.0965, -8.2195], [-4.2499, -9.294], [-5.3666, -8.6972]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-2.9154, -8.7087], [-2.4143, -8.8607], [-2.3551, -9.9446], [-3.5667, -9.577]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.1604, -9.1101], [-0.6392, -9.1615], [-0.3698, -10.2129], [-1.6298, -10.0888]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[0.6392, -9.1615], [1.1604, -9.1101], [1.6298, -10.0888], [0.3698, -10.2129]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[2.4143, -8.8607], [2.9154, -8.7087], [3.5667, -9.577], [2.3551, -9.9446]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[4.0965, -8.2195], [4.5583, -7.9726], [5.3666, -8.6972], [4.2499, -9.294]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.6213, -7.2623], [6.0261, -6.9301], [6.9602, -7.4831], [5.9814, -8.2863]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[6.9301, -6.0261], [7.2623, -5.6213], [8.2863, -5.9814], [7.4831, -6.9602]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[7.9726, -4.5583], [8.2195, -4.0965], [9.294, -4.2499], [8.6972, -5.3666]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[8.7087, -2.9154], [8.8607, -2.4143], [9.9446, -2.3551], [9.577, -3.5667]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[9.1101, -1.1604], [9.1615, -0.6392], [10.2129, -0.3698], [10.0888, -1.6298]], y: [-0.8, 0.8], collide: 1}
  # plate C, fast on the shaft, with a fly-wheel behind; its crank-pin carries B
  - id: C
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#a39d90"
    pieces:
      - {kind: disc, center: [0, 0], radius: 6.1000, y: [1.0, 1.6], collide: 0}
      - {kind: rod, from: [0, 1.0, 0], to: [0, 5.0, 0], radius: 0.7, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0, 0], radius: 26.0, inner: 24.4, y: [6.6, 8.0], collide: 0, density: 490, color: "#7d776c"}   # the fly-wheel, as large as Brown's (density cut so its inertia is unchanged)
      - {kind: rod, from: [0, 5.0, 0], to: [0, 9.6, 0], radius: 0.7, collide: 0, color: "#8f8a80"}   # the shaft, through to the fly-wheel and its bearing
      - {kind: rod, from: [-24.6, 7.3, 0], to: [24.6, 7.3, 0], radius: 0.5, collide: 0, density: 490, color: "#7d776c"}
      - {kind: rod, from: [0, 7.3, -24.6], to: [0, 7.3, 24.6], radius: 0.5, collide: 0, density: 490, color: "#7d776c"}
      - {kind: disc, center: [4.8000, 0], radius: 0.6, y: [-0.9, 1.0], collide: 2, color: "#6f6a60"}
  # cog-wheel B (16 teeth), free on the crank-pin: its hub is a bearing ring round the pin. It is free to
  # move across, up and down and to turn; only the pin and the teeth hold it
  - {id: Bx, shape: part, pos: [4.8000, 0, 0], mount: frame, mass: 0.01, color: "#8f8a80", pieces: [{kind: disc, center: [4.8000, 0], radius: 0.1, y: [0.0, 0.05], collide: 0}]}
  - {id: Bz, shape: part, pos: [4.8000, 0, 0], mount: Bx, mass: 0.01, color: "#8f8a80", pieces: [{kind: disc, center: [4.8000, 0], radius: 0.1, y: [0.0, 0.05], collide: 0}]}
  - id: B
    shape: part
    pos: [4.8000, 0, 0]
    mount: Bz
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [4.8000, 0], radius: 4.1800, inner: 1.45, y: [-0.8, 0.8], collide: 0}
      - {kind: band, center: [4.8000, 0], r: [0.62, 1.45], a: [0, 6.2832], y: [-0.8, 0.8], slices: 36, collide: 1}
      - {kind: poly, points: [[4.6000, -0.9], [5.7000, -0.9], [5.7000, 0.9], [4.6000, 0.9]], y: [-1.2, -0.8], collide: 0}
      - {kind: poly, points: [[4.8000, -0.7], [4.8000, 0.7], [0, 0.6], [0, -0.6]], y: [-1.2, -0.8], collide: 0}
      - {kind: disc, center: [0, 0], radius: 0.7, y: [-1.2, -0.8], collide: 0}
      - {kind: rod, from: [0, -2.3, 0], to: [0, -0.8, 0], radius: 0.3, collide: 0, color: "#6f6a60"}
      - {kind: poly, points: [[9.0, -0.6331], [9.0, 0.6331], [10.02, 0.2618], [10.02, -0.2618]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[8.9226, 1.0224], [8.438, 2.1922], [9.5225, 2.2395], [9.7228, 1.7557]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[8.2175, 2.5222], [7.3222, 3.4175], [8.306, 3.8762], [8.6762, 3.506]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[6.9922, 3.638], [5.8224, 4.1226], [6.5557, 4.9228], [7.0395, 4.7225]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[5.4331, 4.2], [4.1669, 4.2], [4.5382, 5.22], [5.0618, 5.22]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[3.7776, 4.1226], [2.6078, 3.638], [2.5605, 4.7225], [3.0443, 4.9228]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[2.2778, 3.4175], [1.3825, 2.5222], [0.9238, 3.506], [1.294, 3.8762]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[1.162, 2.1922], [0.6774, 1.0224], [-0.1228, 1.7557], [0.0775, 2.2395]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[0.6, 0.6331], [0.6, -0.6331], [-0.42, -0.2618], [-0.42, 0.2618]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[0.6774, -1.0224], [1.162, -2.1922], [0.0775, -2.2395], [-0.1228, -1.7557]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[1.3825, -2.5222], [2.2778, -3.4175], [1.294, -3.8762], [0.9238, -3.506]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[2.6078, -3.638], [3.7776, -4.1226], [3.0443, -4.9228], [2.5605, -4.7225]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[4.1669, -4.2], [5.4331, -4.2], [5.0618, -5.22], [4.5382, -5.22]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[5.8224, -4.1226], [6.9922, -3.638], [7.0395, -4.7225], [6.5557, -4.9228]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[7.3222, -3.4175], [8.2175, -2.5222], [8.6762, -3.506], [8.306, -3.8762]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[8.438, -2.1922], [8.9226, -1.0224], [9.7228, -1.7557], [9.5225, -2.2395]], y: [-0.8, 0.8], collide: 2}
  # the piston-rod A, on the wrist; free to move across, up and down and to turn. It passes through the
  # gland; the wrist's straight path is the wheels' doing
  - {id: Px, shape: part, pos: [0, 0, 0], mount: frame, mass: 0.01, color: "#8f8a80", pieces: [{kind: disc, center: [0, 0], radius: 0.1, y: [-1.5, -1.45], collide: 0}]}
  - {id: Pz, shape: part, pos: [0, 0, 0], mount: Px, mass: 0.01, color: "#8f8a80", pieces: [{kind: disc, center: [0, 0], radius: 0.1, y: [-1.5, -1.45], collide: 0}]}
  - id: P
    shape: part
    pos: [0, 0, 0]
    mount: Pz
    density: 7800
    color: "#b8ad96"
    pieces:
      - {kind: disc, center: [0, 0], radius: 0.75, y: [-2.1, -1.3], collide: 0}
      - {kind: rod, from: [0, -1.65, 0.7], to: [0, -1.65, 23.0000], radius: 0.4, collide: 2, capsule: true, color: "#8f8a80"}
joints:
  - {id: j_C, type: hinge, body: C, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_bx, type: slide, body: Bx, axis: [1, 0, 0], damping: 0.2, range: [-10.6000, 1]}
  - {id: j_bz, type: slide, body: Bz, axis: [0, 0, 1], damping: 0.2, range: [-5.8000, 5.8000]}
  - {id: j_B, type: hinge, body: B, axis: [0, -1, 0], damping: 0.003}
  - {id: j_x, type: slide, body: Px, axis: [1, 0, 0], damping: 0.2, range: [-1, 1]}
  - {id: j_z, type: slide, body: Pz, axis: [0, 0, 1], damping: 0.2, range: [-10.4000, 10.4000]}
  - {id: j_rot, type: hinge, body: P, axis: [0, -1, 0], damping: 0.02}
pins:
  - {id: wrist, a: B, b: P, at: [0, 0, 0]}
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_C, kind: velocity, rpm: 30, kv: 0.5, max_torque: 5}
checks:
  - {type: turning, joint: j_C, direction: 1, min_mean: 2.8, min_fraction: 0.95, settle_s: 0.5, window_s: 7.0}
  # B rolls inside D, of twice its size, so it turns backwards once for each turn of the plate ...
  - {type: ratio, out: j_B, in: j_C, expect: -1.0, tol: 0.01, settle_s: 0.5, window_s: 7.0}
  # ... and the wrist on its pitch circle runs up and down a diameter of D (four times the crank) ...
  - {type: amplitude, joint: j_z, min: 0.095, max: 0.0965, settle_s: 0.5, window_s: 7.0}
  # ... without leaving its line: the piston-rod stays upright in its gland
  - {type: position, joint: j_x, min: -0.08, max: 0.08, settle_s: 0.5, window_s: 7.0}
  - {type: position, joint: j_rot, min: -0.03, max: 0.03, settle_s: 0.5, window_s: 7.0}
  - {type: penetration, max: 0.0003, settle_s: 0.5}
camera: {target: [0, 0, -6], position: [0, -160, -2], fov: 30}
display:
  output: j_z
  labels: {j_C: Plate C and crank-pin (driver), j_B: Cog-wheel B, j_x: Wrist across, j_z: Piston-rod A, j_rot: Turn of piston-rod}

