number: 325
slug: parallel-ruler-swinging-arms
name: Parallel Ruler with Swinging Arms
brown: "Parallel ruler composed of two simple rulers, A, B, connected by two pivoted swinging arms, C, C."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 50, duration_s: 8, floor: false, gravity: 0}
bodies:
  # the paper, and the ruler A held down on it (the frame)
  - id: A
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#c9b68c"
    pieces:
      - {kind: poly, points: [[-4, -4], [32, -4], [32, 13.6603], [-4, 13.6603]], y: [0.7, 0.8], color: "#f4efe2"}
      - {kind: poly, points: [[-1.0, -1.2], [25.0, -1.2], [25.0, 1.2], [-1.0, 1.2]], y: [0.2, 0.6], collide: 0}
      - {kind: disc, center: [3.0, 0], radius: 0.45, y: [-0.45, 0.2], collide: 0, color: "#6f6a60"}
      - {kind: disc, center: [19.0, 0], radius: 0.45, y: [-0.45, 0.2], collide: 0, color: "#6f6a60"}
  # the first swinging arm C, pivoted on A; the ruler B is pivoted on its upper end
  - id: C1
    shape: part
    pos: [3.0, 0, 0]
    mount: A
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.0, -0.25, 0], to: [8.0000, -0.25, 8.6603], radius: 0.35, collide: 0}
  - id: B
    shape: part
    pos: [8.0000, 0, 8.6603]
    mount: C1
    friction: 0.1
    density: 700
    color: "#d8c9a3"
    pieces:
      - {kind: poly, points: [[4.0000, 7.4603], [23.0000, 7.4603], [23.0000, 9.8603], [4.0000, 9.8603]], y: [-1.0, -0.6], collide: 0}
      - {kind: poly, points: [[25.0000, 7.4603], [30.0000, 7.4603], [30.0000, 9.8603], [25.0000, 9.8603]], y: [-1.0, -0.6], collide: 0}
      - {kind: band, center: [24.0000, 8.6603], r: [0.32, 1.2], a: [0, 6.2832], y: [-1.0, -0.6], slices: 20, collide: 1}
      - {kind: disc, center: [8.0000, 8.6603], radius: 0.45, y: [-1.1, -0.5], collide: 0, color: "#6f6a60"}
  # the second arm C, pivoted on A; the pin at its upper end turns in a hole in B
  - id: C2
    shape: part
    pos: [19.0, 0, 0]
    mount: A
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [19.0, -0.25, 0], to: [24.0000, -0.25, 8.6603], radius: 0.35, collide: 0}
      - {kind: disc, center: [24.0000, 8.6603], radius: 0.3, y: [-1.05, -0.2], collide: 2, color: "#6f6a60"}
joints:
  # the hand swings the ruler B on its arms (the one driven joint)
  - {id: j_C1, type: hinge, body: C1, axis: [0, -1, 0], damping: 0.001}
  - {id: j_B, type: hinge, body: B, axis: [0, -1, 0], damping: 0.05}
  - {id: j_C2, type: hinge, body: C2, axis: [0, -1, 0], damping: 0.05}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_C1, kind: velocity, rpm: 0, swing: {amplitude: 0.25, hz: 0.25}, kv: 50, max_torque: 20}
checks:
  # A, B and the two arms C, C make a parallelogram: the second arm swings with the first ...
  - {type: ratio, out: j_C2, in: j_C1, expect: 1.0, tol: 0.03, settle_s: 0.5, window_s: 7.0}
  # ... and B turns back on its arm as much as the arm swings, so it stays parallel to A while it moves
  # across and along the paper
  - {type: ratio, out: j_B, in: j_C1, expect: -1.0, tol: 0.02, settle_s: 0.5, window_s: 7.0}
  - {type: penetration, max: 0.0003, settle_s: 0.2}
camera: {target: [14, 0, 4.3301], position: [14, -110, 4.3301], fov: 30}
display:
  output: j_B
  labels: {j_C1: "First arm C, swung by the hand (driver)", j_B: Ruler B on its arm, j_C2: Second arm C}

