# No. 140 (Brown 1868): "The toggle-joint arranged for a punching machine. Lever at the right is made to operate upon the joint of the toggle by means of the horizontal connecting-link."
#
# Model (cm, gravity on): as drawn in the plate. A toggle of two links (11.41 and 11.40 cm) hangs from a pin at the top of the column; the lower link pushes the punch down its guide. A horizontal link
# (10.5 cm) joins the knee of the toggle to a bent lever pivoted on the pillar; the lever is the one driven joint, swung by the hand 0.42 rad each way (0.2 swings a second) about the middle of its
# travel. As the lever turns clockwise the link pushes the knee towards the line of the toggle and the punch goes down 2.40 cm, faster at the start and slower as the toggle straightens. All joints are pins. Generator: opencode-runs/batch10/gen140.py.
number: 140
slug: toggle-punch
name: The toggle-joint of a punching machine
brown: "The toggle-joint arranged for a punching machine. Lever at the right is made to operate upon the joint of the toggle by means of the horizontal connecting-link."
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: [[-12.0, -38.0], [25.0, -38.0], [25.0, -35.0], [-12.0, -35.0]], y: [1.4, 4.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[4.0, -35], [4.0, -15.5], [8.0, -15.5], [11.5, -26], [21, -35]], y: [2.2, 3.4], collide: 0, color: "#c3baa6"}
      - {kind: poly, points: [[-1.2, -31.0], [3.2, -31.0], [3.2, 3.0], [-1.2, 3.0]], y: [2.2, 3.4], collide: 0}
      - {kind: poly, points: [[3.2, -7.5], [8.0, -7.5], [8.0, -2.5], [3.2, -2.5]], y: [2.2, 3.4], collide: 0}
      - {kind: poly, points: [[-2.6, -27.0], [4.4, -27.0], [4.4, -20.2], [-2.6, -20.2]], y: [1.6, 3.4], collide: 0, color: "#bdb4a0"}
      - {kind: disc, center: [0.0, 0.0], radius: 1.2, inner: 0.0, y: [0.0, 2.2], color: "#8f8a80"}
      - {kind: rod, from: [7.8, -1.8, -12.0], to: [7.8, 2.2, -12.0], radius: 0.55, collide: 0, color: "#8f8a80"}
  - id: lever
    shape: part
    pos: [7.8, 0, -12.0]
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[7.1672, -12.4026], [5.3203, -9.4993], [6.5859, -8.6942], [8.4328, -11.5974]], y: [-1.7, -1.0], collide: 0}
      - {kind: poly, points: [[7.7563, -11.1511], [26.7008, -10.1769], [26.7881, -11.8746], [7.8437, -12.8489]], y: [-1.7, -1.0], collide: 0}
      - {kind: disc, center: [7.8, -12.0], radius: 2.0, inner: 0.5, y: [-1.8, -0.9]}
      - {kind: disc, center: [5.9531, -9.0967], radius: 1.0, inner: 0.35, y: [-1.8, -0.9]}
  - id: hlink
    shape: part
    pos: [5.9531, 0, -9.0967]
    mount: lever
    color: "#c9bfa6"
    pieces:
      - {kind: poly, points: [[6.0271, -9.6417], [-4.3776, -11.0538], [-4.5255, -9.9638], [5.8791, -8.5517]], y: [-0.9, -0.2], collide: 0}
      - {kind: disc, center: [5.9531, -9.0967], radius: 0.9, inner: 0.35, y: [-0.9, -0.2]}
      - {kind: disc, center: [-4.4515, -10.5088], radius: 0.9, inner: 0.35, y: [-0.9, -0.2]}
  - id: link1
    shape: part
    pos: [0.0, 0, 0.0]
    color: "#d2c8ae"
    pieces:
      - {kind: poly, points: [[0.5064, -0.2145], [-3.9451, -10.7233], [-4.958, -10.2942], [-0.5064, 0.2145]], 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]}
      - {kind: disc, center: [-4.4515, -10.5088], radius: 0.9, inner: 0.35, y: [-0.1, 0.6]}
  - id: link2
    shape: part
    pos: [-4.4515, 0, -10.5088]
    mount: link1
    color: "#c4baa2"
    pieces:
      - {kind: poly, points: [[-3.9634, -10.2554], [1.2882, -20.3728], [0.3118, -20.8795], [-4.9397, -10.7621]], y: [0.7, 1.4], collide: 0}
      - {kind: disc, center: [-4.4515, -10.5088], radius: 0.9, inner: 0.35, y: [0.7, 1.4]}
      - {kind: disc, center: [0.8, -20.6261], radius: 0.9, inner: 0.35, y: [0.7, 1.4]}
  - id: punch
    shape: part
    pos: [0.8, 0, -20.6261]
    color: "#b3a88f"
    pieces:
      - {kind: poly, points: [[-0.4, -22.2261], [2.0, -22.2261], [2.0, -20.6261], [-0.4, -20.6261]], y: [0.6, 1.5], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[-1.0, -27.0261], [2.6, -27.0261], [2.6, -22.2261], [-1.0, -22.2261]], y: [0.3, 1.8], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[0.3, -31.4261], [1.3, -31.4261], [1.3, -27.0261], [0.3, -27.0261]], y: [0.6, 1.5], 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: [-4.4515, 0, -10.5088]}
  - {id: pin_s, a: link2, b: punch, at: [0.8, 0, -20.6261]}
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.42, hz: 0.2}, kv: 40.0, max_torque: 40}
checks:
  - {type: follow, out: j_p, in: j_l, expect: -0.0281, tol: 0.0017, 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.0277, tol: 0.0017, 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.0276, tol: 0.0017, 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.0302, tol: 0.0018, 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.026, tol: 0.0016, min_r2: 0.98, settle_s: 5.4, 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.0301, tol: 0.0018, 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.399, max: 0.4704, settle_s: 1, window_s: 10.5}
  - {type: position, joint: j_p, min: -1.3344, max: 1.3609, settle_s: 0.0, window_s: 11.5}
camera: {target: [6, 0, -17.0], position: [6, -100.0, -17.0], fov: 34}
display:
  output: j_p
  labels: {j_l: "Lever (driver)", j_p: "Punch", j_1: "Upper link", j_2: "Lower link", j_h: "Connecting link"}
  proof: {label: "Connecting link removed", sub: "the lever swings but the punch stays"}

