# No. 100 (Brown 1868): "Quick return crank motion, applicable to shaping machines."
#
# Model (cm): the crank-disk (20 turns a minute, the one driven joint) carries a crank-pin 3 cm out, which works by real contact in
# the groove of a slotted lever hung from a pivot 9 cm above the disk's centre (the pivot lies outside the pin's circle). The lever's foot
# (21 cm from the pivot) drives the ram through a link (16 cm); the ram slides in fixed guides. The lever swings 19.5 deg each way;
# the pin takes 60.8% of the turn for the ram's cutting stroke and 39.2% for its return: the quick return. Ram stroke 14.00 cm.
# Generator: opencode-runs/batch9/gen100.py.
number: 100
slug: quick-return-crank
name: A quick-return crank motion for a shaping machine
brown: "Quick return crank motion, applicable to shaping machines."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 50
  solver: PGS
  duration_s: 10
  floor: false
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 0]
    mass: 1.5
    friction: 0.05
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, 0.5, 0], to: [0, 3.0, 0], radius: 0.8, color: "#8f8a80"}   # the shaft
      - {kind: disc, center: [0, 0], radius: 5.2, y: [0.0, 0.5]}   # the crank-disk, behind the lever
      - {kind: rod, from: [0, 0.0, 3.0], to: [0, -1.4, 3.0], radius: 0.5, collide: 1, capsule: true, color: "#8f8a80"}   # the crank-pin
  - id: lever
    shape: part
    pos: [0, 0, 9.0]
    mass: 0.6
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [0, 9.0], radius: 1.4, inner: 0.4, y: [-1.0, 0.2]}   # the lever's eye on its pivot
      - {kind: poly, points: [[-0.9, 8.0], [0.9, 8.0], [1.82, 6.3], [-1.82, 6.3]], y: [-1.0, 0.2]}   # the lever, above the groove
      - {kind: poly, points: [[0.52, 5.0], [1.82, 5.0], [1.82, -5.0], [0.52, -5.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-0.52, 5.0], [-1.82, 5.0], [-1.82, -5.0], [-0.52, -5.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, 6.3], [1.82, 6.3], [1.82, 5.0], [-1.82, 5.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, -5.0], [1.82, -5.0], [1.82, -6.3], [-1.82, -6.3]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, -6.3], [1.82, -6.3], [0.8, -11.2], [-0.8, -11.2]], y: [-1.0, 0.2]}   # the lever's foot
      - {kind: disc, center: [0, -12.0], radius: 0.8, y: [-1.0, 0.2]}   # its eye for the link
  - id: link
    shape: part
    pos: [0, 0, -12.0]
    mount: lever
    mass: 0.3
    friction: 0.05
    color: "#9a8c74"
    pieces:
      - {kind: disc, center: [0, -12.0], radius: 0.9, inner: 0.35, y: [-1.9, -1.3]}   # the link's eye on the lever's foot
      - {kind: poly, points: [[0.6, -12.45], [15.5, -12.35], [15.5, -11.65], [0.6, -11.55]], y: [-1.85, -1.35]}   # the link
      - {kind: disc, center: [16.0, -12.0], radius: 0.7, inner: 0.3, y: [-1.9, -1.3]}   # its eye on the ram
  - id: ram
    shape: part
    pos: [16.0, 0, -12.0]
    mass: 0.8
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[13.8, -13.5], [22.0, -13.5], [22.0, -10.5], [13.8, -10.5]], y: [-1.7, -0.3]}   # the ram
      - {kind: poly, points: [[22.0, -12.6], [25.0, -12.2], [25.0, -11.8], [22.0, -11.4]], y: [-1.5, -0.5], color: "#8f8a80"}   # the tool
      - {kind: disc, center: [16.0, -12.0], radius: 0.3, y: [-2.0, -1.7], color: "#8f8a80"}   # the pin
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.6, -17], [1.6, -17], [1.1, 0], [-1.1, 0]], y: [1.8, 2.8]}   # the disk's standard, behind
      - {kind: poly, points: [[-1.0, 9.0], [1.0, 9.0], [1.0, 13.0], [-1.0, 13.0]], y: [0.4, 1.4]}   # the pivot's bracket
      - {kind: poly, points: [[-3, 13.0], [3, 13.0], [3, 14.2], [-3, 14.2]], y: [0.4, 2.8]}   # its cross-piece
      - {kind: poly, points: [[-1.0, -17], [1.0, -17], [1.0, 13.0], [-1.0, 13.0]], y: [1.8, 2.8]}   # the standard's post
      - {kind: poly, points: [[5.4551, -10.45], [31.9546, -10.45], [31.9546, -9.6], [5.4551, -9.6]], y: [-1.7, 1.4]}   # the ram's upper guide
      - {kind: poly, points: [[5.4551, -14.4], [31.9546, -14.4], [31.9546, -13.55], [5.4551, -13.55]], y: [-1.7, 1.4]}   # the lower guide
      - {kind: poly, points: [[5.4551, -14.4], [31.9546, -14.4], [31.9546, -9.6], [5.4551, -9.6]], y: [1.4, 1.8]}   # their back plate
      - {kind: poly, points: [[29.9546, -17], [31.9546, -17], [31.9546, -14.4], [29.9546, -14.4]], y: [1.4, 2.4]}   # their post
      - {kind: poly, points: [[-10, -18], [34.9546, -18], [34.9546, -17], [-10, -17]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_s, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_a, type: hinge, body: lever, axis: [0, 1, 0], damping: 0.1}   # the slotted lever on its pivot
  - {id: j_l, type: hinge, body: link, axis: [0, 1, 0], damping: 0.001}   # the link on the lever's foot
  - {id: j_x, type: slide, body: ram, axis: [1, 0, 0], range: [-7.4449, 7.4546], stiffness: 5.0, springref: -40, damping: 0.05}   # the ram in its guides, a weak spring standing for the cut; + : forward (to the right)
pins:
  - {id: pin_x, a: link, b: ram, at: [16.0, 0, -12.0]}
driver: {joint: j_s, kind: velocity, rpm: 20.0, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_x, in: j_s, expect: -0.01941, tol: 0.00058, min_r2: 0.995, settle_s: 3.7083, window_s: 0.0833}
  - {type: follow, out: j_x, in: j_s, expect: -0.05247, tol: 0.00157, min_r2: 0.995, settle_s: 4.4583, window_s: 0.0833}
  - {type: follow, out: j_x, in: j_s, expect: -0.0203, tol: 0.00061, min_r2: 0.995, settle_s: 5.2083, window_s: 0.0833}
  - {type: follow, out: j_x, in: j_s, expect: 0.10457, tol: 0.00314, min_r2: 0.99, settle_s: 5.9583, window_s: 0.0833}
  - {type: position, joint: j_x, min: -7.1449, max: 7.0546, settle_s: 0.5, window_s: 9}   # the ram's stroke
camera: {target: [16.7049, 0, -4], position: [16.7049, -105, -2], fov: 34}
display:
  output: j_x
  labels: {j_s: "Crank-disk (driver)", j_a: "Slotted lever", j_l: "Link", j_x: "Ram"}
  proof: {label: "Link unpinned", sub: "the crank turns the lever but the ram stands"}

