# No. 175 (Brown 1868): "A means of giving one complete revolution to the crank of an engine to each stroke of the piston."
#
# Reading of the figure (cm, no gravity; a plan): a crank turns in the standard on the left; a rod from its pin works a slider in the long vertical slot of the standard (the dashed circle is the crank-pin's path). The one driven joint is the crank. The figure's rod is shorter than the
# distance from the slot to the far side of the crank-pin circle, so as drawn the crank cannot go round; this build lengthens the rod (11 cm for a 3 cm crank, slot 6.4 cm to one side) so that it can: the pin goes once round the circle, and the slider makes one up and one down stroke (7.7 cm).
# No flywheel or piston-driven version is modelled; the crank is the input. Generator: opencode-runs/batch11/gen175.py.
number: 175
slug: one-revolution-per-stroke
name: One revolution of the crank to each stroke of the piston
brown: "A means of giving one complete revolution to the crank of an engine to each stroke of the piston."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 2.500
  floor: false
  gravity: 0
bodies:
  - id: crank
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-0.7, 0.0], [-0.7, 3.0], [0.7, 3.0], [0.7, -0.0]], y: [-1.6, -0.9], collide: 0, color: "#c9bda2"}
      - {kind: disc, center: [0, 0], radius: 1.35, y: [-1.8, -0.8], collide: 0, color: "#b9b09c"}
      - {kind: disc, center: [0, 0], radius: 0.8, y: [-1.9, -1.8], collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0.0, 3.0], radius: 0.95, y: [-1.6, -0.9], collide: 0, color: "#d9cfb6"}
  - id: rod
    shape: part
    pos: [0.0, 0, 3.0]
    mount: crank
    mass: 0.3
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[0.4067, 2.7091], [-5.9933, -6.2374], [-6.8067, -5.6556], [-0.4067, 3.2909]], y: [-0.8, -0.25], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [0.0, -1.0, 3.0], to: [0.0, -0.2, 3.0], radius: 0.55, collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-6.4, -1.0, -5.9465], to: [-6.4, 0.1, -5.9465], radius: 0.55, collide: 0, color: "#8f8a80"}
  - id: slider
    shape: part
    pos: [-6.4, 0, -5.9465]
    mass: 0.2
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[-7.1, -7.1465], [-5.7, -7.1465], [-5.7, -4.7465], [-7.1, -4.7465]], y: [-0.25, 0.4], collide: 0, color: "#8f8a80"}
  - id: standard
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-4.4, -17.4], [7.5, -17.4], [7.5, -16.0], [-4.4, -16.0]], y: [-3, 3], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[6.0, -16.0], [-3.6, -16.0], [-3.6, 4.6], [6.0, 4.6]], y: [0.4, 3], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-3.6, -16.0], [-10.2, -16.0], [-9.4, 9.5], [-4.6, 9.5], [-3.6, 3.0]], y: [0.4, 3], collide: 0, color: "#cfc6b4"}
      - {kind: poly, points: [[-7.3, -12.6], [-5.5, -12.6], [-5.5, 8.0], [-7.3, 8.0]], y: [0.3, 0.4], collide: 0, color: "#6e6452"}
      - {kind: poly, points: [[4.4, -13.0], [-1.4, -13.0], [-1.4, -4.6], [4.4, -4.6]], y: [0.3, 0.4], collide: 0, color: "#9d917a"}
joints:
  - {id: j_c, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.002}   # the one driven joint: the crank
  - {id: j_r, type: hinge, body: rod, axis: [0, -1, 0], damping: 0.002}
  - {id: j_sl, type: slide, body: slider, axis: [0, 0, 1], damping: 0.05}   # the slider in the slot
pins:
  - {"id": "pin_s", "a": "rod", "b": "slider", "at": [-6.4, 0, -5.9465]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_c, kind: velocity, rpm: 24, kv: 2.0, max_torque: 20}
checks:
  - {type: follow, out: j_sl, in: j_c, expect: -0.0303, tol: 0.0018, min_r2: 0.99, settle_s: 0.2188, window_s: 0.1989}
  - {type: follow, out: j_sl, in: j_c, expect: 0.0469, tol: 0.0026, min_r2: 0.99, settle_s: 1.4523, window_s: 0.1989}
  - {type: position, joint: j_sl, min: -6.805, max: 1.4465, settle_s: 0.0, window_s: 2.30}
  - {type: penetration, max: 0.003, settle_s: 0.5}
camera: {target: [-2.0, 0, -9.9], position: [-2.0, -79.0, -9.9], fov: 34}
display:
  output: j_sl
  labels: {j_c: "Crank (driver)", j_r: "Rod", j_sl: "Slider"}

