# No. 268 (Brown 1868): "Circular into reciprocating motion by means of a crank and oscillating rod."
#
# Model (cm, gravity on, the shafts level): the disc's crank (radius 3) is the one driven joint, 20 turns a minute. The rod (32 long) is pinned
# to the crank-pin and lies by its own weight on a free roller (radius 2) 18 away; it slides to and fro over the roller and rocks on it, so its
# far end goes to and fro 6.00 along its length and rises and falls 4.80. The rod rocks through 19.1 deg;
# the roller, turned by the rod's sliding, rocks -3.01..0.02 rad. Only the rod's contact on the roller supports it. Generator: opencode-runs/batch12/gen268.py.
number: 268
slug: crank-and-oscillating-rod
name: Circular into reciprocating motion by a crank and oscillating rod
brown: "Circular into reciprocating motion by means of a crank and oscillating rod."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 7.5
  floor: false
bodies:
  - id: crank
    shape: part
    pos: [0, 0, 0]
    density: 2700
    color: "#d9c9a3"
    pieces:
      - {kind: disc, center: [0, 0], radius: 6.0, y: [1.4, 2.0], collide: 0}   # the disc
      - {kind: poly, points: [[-0.5, -0.5], [3.0, -0.5], [3.0, 0.5], [-0.5, 0.5]], y: [0.8, 1.4], collide: 0, color: "#8f8a80"}   # the crank
      - {kind: rod, from: [0, 2.0, 0], to: [0, 3.0, 0], radius: 0.6, collide: 0, color: "#8f8a80"}   # its shaft
  - id: rod
    shape: part
    pos: [3.0, 0, -0.0]
    mount: crank
    density: 2700
    friction: 0.5
    color: "#e4d9bf"
    pieces:
      - {kind: poly, points: [[3.911, -0.3742], [-28.9756, -1.3123], [-28.9984, -0.5126], [3.8882, 0.4255]], y: [-0.25, 0.55], collide: 1}   # the rod
      - {kind: rod, from: [3.0, -0.5, -0.0], to: [3.0, 1.0, -0.0], radius: 0.35, collide: 0, color: "#6f675a"}   # the crank-pin
  - id: roller
    shape: part
    pos: [-18.0, 0, -3.0]
    density: 2700
    friction: 0.5
    color: "#cfc2a6"
    pieces:
      - {kind: disc, center: [-18.0, -3.0], radius: 2.0, y: [-0.45, 0.75], collide: 2}   # the roller
      - {kind: poly, points: [[-18.12, -2.5], [-17.88, -2.5], [-17.88, -1.2], [-18.12, -1.2]], y: [-0.5, -0.45], collide: 0, color: "#6f675a"}   # a mark on its face
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-21.0, -9], [9, -9], [9, -8], [-21.0, -8]], y: [-2.5, 4.5], collide: 0, color: "#b9b09c"}   # the bed
      - {kind: poly, points: [[-1, -8], [1, -8], [1, 0], [-1, 0]], y: [3.0, 4.0], collide: 0}   # the disc's standard
      - {kind: poly, points: [[-18.6, -8], [-17.4, -8], [-17.4, -3.0], [-18.6, -3.0]], y: [1.6, 2.4], collide: 0}   # the roller's stud
      - {kind: rod, from: [-18.0, 0.75, -3.0], to: [-18.0, 1.6, -3.0], radius: 0.35, collide: 0, color: "#8f8a80"}
joints:
  - {id: j_c, type: hinge, body: crank, axis: [0, 1, 0], damping: 0.01}   # the one driven joint
  - {id: j_p, type: hinge, body: rod, axis: [0, 1, 0], damping: 0.0001}   # the rod on the crank-pin
  - {id: j_w, type: hinge, body: roller, axis: [0, 1, 0], damping: 1e-05}   # the roller on its stud
contact: {solref: [0.001, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_c, kind: velocity, rpm: 20, kv: 20.0, max_torque: 6.0}
checks:
  - {type: follow, out: j_p, in: j_c, expect: -0.85864, tol: 0.04293, min_r2: 0.98, settle_s: 2.845, window_s: 0.3}   # the rod's fastest swing up (with the crank's turn)
  - {type: follow, out: j_p, in: j_c, expect: -1.19542, tol: 0.05977, min_r2: 0.98, settle_s: 4.325, window_s: 0.3}   # its fastest swing down
  - {type: position, joint: j_w, min: -3.3603, max: 0.0694, settle_s: 0.0, window_s: 7.5}   # the roller rocks to and fro as the rod slides over it (-3.009..0.018 rad)
  - {type: ratio, out: j_p, in: j_c, expect: -1.0, tol: 0.02, settle_s: 0.5, window_s: 6.5}   # the rod never turns over: it falls back a turn on its pin each turn of the crank
camera: {target: [-10.0, 0, -5.0], position: [-4.0, -70.0, 8.0], fov: 34.0}
display:
  output: j_p
  labels: {j_c: "The crank (driver)", j_p: "The rod on its pin", j_w: "The roller"}
  proof: {label: "Crank and oscillating rod", sub: "the rod slides and rocks on its roller; its far end goes to and fro"}

