# No. 164 (Brown 1868): "A knee-lever, differing slightly from the toggle-joint shown in 140. It is often used for presses and stamps, as a great force can be obtained by it. The action is by raising or lowering the horizontal lever."
#
# Model (cm, gravity on): a knee of two links (14.00 and 14.00 cm) hangs from a pin at the top of the pillar; the lower link pushes the plunger down its guide. A short upright link (7.6 cm) joins the knee, from above, to the horizontal lever, pivoted on the left post;
# the lever is the one driven joint, swung by the hand 0.1 rad each way (0.2 swings a second) about the middle of its travel. As the lever swings the upright link above the knee pushes it down towards the line of the knee and the plunger goes down 4.10 cm, faster at the start and slower
# as the knee straightens (the force grows as it does). All joints are pins. Generator: opencode-runs/batch11/gen164.py.
number: 164
slug: knee-lever
name: The knee-lever
brown: "A knee-lever, differing slightly from the toggle-joint shown in 140. It is often used for presses and stamps, as a great force can be obtained by it. The action is by raising or lowering the horizontal lever."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 12.0
  floor: false
bodies:
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-34.0, -42.0], [14.0, -42.0], [14.0, -39.0], [-34.0, -39.0]], y: [1.4, 4.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[5.0, -40.0], [9.0, -40.0], [9.0, 5.0], [5.0, 5.0]], y: [2.2, 3.4], collide: 0}
      - {kind: poly, points: [[0.0, -1.8], [9.0, -1.8], [9.0, 1.8], [0.0, 1.8]], y: [2.2, 3.4], collide: 0}
      - {kind: poly, points: [[-18.0, -40.0], [-14.0, -40.0], [-14.0, -5.0], [-18.0, -5.0]], y: [2.2, 3.4], collide: 0}
      - {kind: poly, points: [[-2.8, -38.0], [2.8, -38.0], [2.8, -33.0], [-2.8, -33.0]], y: [1.6, 3.4], collide: 0, color: "#bdb4a0"}
      - {kind: poly, points: [[-2.8, -40.0], [2.8, -40.0], [2.8, -38.0], [-2.8, -38.0]], y: [2.2, 3.4], collide: 0}
      - {kind: disc, center: [0.0, 0.0], radius: 1.2, inner: 0.0, y: [0.0, 2.2], collide: 0, color: "#8f8a80"}
      - {kind: rod, from: [-16.0, -1.8, -5.0], to: [-16.0, 2.2, -5.0], radius: 0.55, collide: 0, color: "#8f8a80"}
  - id: lever
    shape: part
    pos: [-16.0, 0, -5.0]
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[-16.0, -4.25], [-6.0, -4.25], [-6.0, -5.75], [-16.0, -5.75]], y: [-1.7, -1.0], collide: 0}
      - {kind: poly, points: [[-16.0, -5.85], [-30.0, -5.85], [-30.0, -4.15], [-16.0, -4.15]], y: [-1.7, -1.0], collide: 0}
      - {kind: disc, center: [-16.0, -5.0], radius: 2.0, inner: 0.5, y: [-1.8, -0.9], collide: 0}
      - {kind: disc, center: [-6.0, -5.0], radius: 1.0, inner: 0.35, y: [-1.8, -0.9], collide: 0}
      - {kind: disc, center: [-30.0, -5.0], radius: 1.2, inner: 0.0, y: [-1.8, -0.9], collide: 0, color: "#8f8a80"}
  - id: hlink
    shape: part
    pos: [-6.0, 0, -5.0]
    mount: lever
    color: "#c9bfa6"
    pieces:
      - {kind: poly, points: [[-5.45, -5.0], [-5.45, -12.6491], [-6.55, -12.6491], [-6.55, -5.0]], y: [-0.9, -0.2], collide: 0}
      - {kind: disc, center: [-6.0, -5.0], radius: 0.9, inner: 0.35, y: [-0.9, -0.2], collide: 0}
      - {kind: disc, center: [-6.0, -12.6491], radius: 0.9, inner: 0.35, y: [-0.9, -0.2], collide: 0}
  - id: link1
    shape: part
    pos: [0.0, 0, 0.0]
    color: "#d2c8ae"
    pieces:
      - {kind: poly, points: [[0.4969, -0.2357], [-5.5031, -12.8848], [-6.4969, -12.4134], [-0.4969, 0.2357]], y: [-0.1, 0.6], collide: 0}
      - {kind: disc, center: [0.0, 0.0], radius: 0.9, inner: 0.35, y: [-0.1, 0.6], collide: 0}
      - {kind: disc, center: [-6.0, -12.6491], radius: 0.9, inner: 0.35, y: [-0.1, 0.6], collide: 0}
  - id: link2
    shape: part
    pos: [-6.0, 0, -12.6491]
    mount: link1
    color: "#c4baa2"
    pieces:
      - {kind: poly, points: [[-5.5031, -12.4134], [0.4969, -25.0625], [-0.4969, -25.5339], [-6.4969, -12.8848]], y: [0.7, 1.4], collide: 0}
      - {kind: disc, center: [-6.0, -12.6491], radius: 0.9, inner: 0.35, y: [0.7, 1.4], collide: 0}
      - {kind: disc, center: [0.0, -25.2982], radius: 0.9, inner: 0.35, y: [0.7, 1.4], collide: 0}
  - id: punch
    shape: part
    pos: [0.0, 0, -25.2982]
    color: "#b3a88f"
    pieces:
      - {kind: poly, points: [[-1.2, -26.8982], [1.2, -26.8982], [1.2, -25.2982], [-1.2, -25.2982]], y: [0.6, 1.5], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[-1.8, -29.8982], [1.8, -29.8982], [1.8, -26.8982], [-1.8, -26.8982]], y: [0.3, 1.8], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[-2.4, -33.4982], [2.4, -33.4982], [2.4, -29.8982], [-2.4, -29.8982]], y: [0.3, 1.8], collide: 0, color: "#8f8a80"}
joints:
  - {id: j_l, type: hinge, body: lever, axis: [0, 1, 0], damping: 0.01}   # the one driven joint; + : clockwise, the punch going down
  - {id: j_h, type: hinge, body: hlink, axis: [0, 1, 0], damping: 0.005}
  - {id: j_1, type: hinge, body: link1, axis: [0, 1, 0], damping: 0.005}
  - {id: j_2, type: hinge, body: link2, axis: [0, 1, 0], damping: 0.005}
  - {id: j_p, type: slide, body: punch, axis: [0, 0, 1], damping: 0.5}   # + : up
pins:
  - {id: pin_k, a: hlink, b: link1, at: [-6.0, 0, -12.6491]}
  - {id: pin_s, a: link2, b: punch, at: [0.0, 0, -25.2982]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_l, kind: velocity, rpm: 0, swing: {amplitude: 0.1, hz: 0.2}, kv: 400.0, max_torque: 400.0}
checks:
  - {type: follow, out: j_p, in: j_l, expect: -0.1428, tol: 0.0157, min_r2: 0.98, settle_s: 0.15, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: follow, out: j_p, in: j_l, expect: -0.1384, tol: 0.0152, min_r2: 0.98, settle_s: 1.6, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: follow, out: j_p, in: j_l, expect: -0.2843, tol: 0.0313, min_r2: 0.98, settle_s: 2.8, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: follow, out: j_p, in: j_l, expect: -0.2484, tol: 0.0273, min_r2: 0.98, settle_s: 4.3, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: follow, out: j_p, in: j_l, expect: -0.1475, tol: 0.0162, min_r2: 0.98, settle_s: 5.1, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: follow, out: j_p, in: j_l, expect: -0.1689, tol: 0.0186, min_r2: 0.98, settle_s: 6.9, window_s: 0.7}   # the punch's speed per radian of the lever (the toggle gains as it straightens)
  - {type: amplitude, joint: j_l, min: 0.095, max: 0.112, settle_s: 1, window_s: 10.5}
  - {type: position, joint: j_p, min: -1.8333, max: 2.7701, settle_s: 0.0, window_s: 11.5}
camera: {target: [-10.0, 0, -21.0], position: [-10.0, -125.0, -21.0], fov: 34}
display:
  output: j_p
  labels: {j_l: "Lever (driver)", j_p: "Plunger", j_1: "Upper link of the knee", j_2: "Lower link of the knee", j_h: "Upright link"}
  proof: {label: "Connecting link removed", sub: "the lever swings but the plunger stays"}

