# No. 273 (Brown 1868): "Rectilinear into rectilinear motion. When the rods, A and B, are brought together, the rods, C and D, are thrust further apart, and vice versa."
#
# Model (cm, gravity on, upright as drawn): four rods in fixed guides, A and B on a level line, C and D on an upright one, their inner ends joined by four equal links
# (8 eye to eye) pinned at the rods' studs, a lozenge, square at the start. The rod A is the one driven joint, pushed in and drawn out 1.5 each way, 0.4 times a
# second. Nothing else is driven: the links carry B in as A goes in (B = -A), and thrust C up and D down, so C stands at sqrt(L^2 - x_A^2) from the centre:
# -2.082 .. +1.1784 from its start, rising 1.000 cm per cm of A at the square (1.0626 on the whole stroke, least squares). Generator: opencode-runs/batch12/gen273.py.
number: 273
slug: lozenge-of-links-four-rods
name: Four rods joined by a lozenge of links
brown: "Rectilinear into rectilinear motion. When the rods, A and B, are brought together, the rods, C and D, are thrust further apart, and vice versa."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 100
  solver: CG
  duration_s: 8
  floor: false
bodies:
  - id: rod_a
    shape: part
    pos: [-5.6569, 0, 0.0]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [-5.6569, 0, 0.0], to: [-11.6569, 0, 0.0], radius: 0.4, collide: 0}   # rod A
      - {kind: rod, from: [-5.6569, -0.85, 0.0], to: [-5.6569, 0.85, 0.0], radius: 0.25, collide: 0, color: "#8f8a80"}   # its stud
  - id: rod_b
    shape: part
    pos: [5.6569, 0, 0.0]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [5.6569, 0, 0.0], to: [11.6569, 0, 0.0], radius: 0.4, collide: 0}   # rod B
      - {kind: rod, from: [5.6569, -0.85, 0.0], to: [5.6569, 0.85, 0.0], radius: 0.25, collide: 0, color: "#8f8a80"}   # its stud
  - id: rod_c
    shape: part
    pos: [0.0, 0, 5.6569]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [0.0, 0, 5.6569], to: [0.0, 0, 11.6569], radius: 0.4, collide: 0}   # rod C
      - {kind: rod, from: [0.0, -0.85, 5.6569], to: [0.0, 0.85, 5.6569], radius: 0.25, collide: 0, color: "#8f8a80"}   # its stud
  - id: rod_d
    shape: part
    pos: [0.0, 0, -5.6569]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [0.0, 0, -5.6569], to: [0.0, 0, -11.6569], radius: 0.4, collide: 0}   # rod D
      - {kind: rod, from: [0.0, -0.85, -5.6569], to: [0.0, 0.85, -5.6569], radius: 0.25, collide: 0, color: "#8f8a80"}   # its stud
  - id: link_ac
    shape: part
    pos: [-5.6569, 0, 0.0]
    mount: rod_a
    density: 2700
    color: "#d9cdb0"
    pieces:
      - {kind: rod, from: [-5.6569, -0.6, 0.0], to: [0.0, -0.6, 5.6569], radius: 0.3, collide: 0}   # link AC
      - {kind: rod, from: [-5.6569, -0.85, 0.0], to: [-5.6569, -0.35, 0.0], radius: 0.55, collide: 0}   # its eyes
      - {kind: rod, from: [0.0, -0.85, 5.6569], to: [0.0, -0.35, 5.6569], radius: 0.55, collide: 0}
  - id: link_cb
    shape: part
    pos: [0.0, 0, 5.6569]
    mount: rod_c
    density: 2700
    color: "#d9cdb0"
    pieces:
      - {kind: rod, from: [0.0, 0.6, 5.6569], to: [5.6569, 0.6, 0.0], radius: 0.3, collide: 0}   # link CB
      - {kind: rod, from: [0.0, 0.35, 5.6569], to: [0.0, 0.85, 5.6569], radius: 0.55, collide: 0}   # its eyes
      - {kind: rod, from: [5.6569, 0.35, 0.0], to: [5.6569, 0.85, 0.0], radius: 0.55, collide: 0}
  - id: link_bd
    shape: part
    pos: [5.6569, 0, 0.0]
    mount: rod_b
    density: 2700
    color: "#d9cdb0"
    pieces:
      - {kind: rod, from: [5.6569, -0.6, 0.0], to: [0.0, -0.6, -5.6569], radius: 0.3, collide: 0}   # link BD
      - {kind: rod, from: [5.6569, -0.85, 0.0], to: [5.6569, -0.35, 0.0], radius: 0.55, collide: 0}   # its eyes
      - {kind: rod, from: [0.0, -0.85, -5.6569], to: [0.0, -0.35, -5.6569], radius: 0.55, collide: 0}
  - id: link_da
    shape: part
    pos: [0.0, 0, -5.6569]
    mount: rod_d
    density: 2700
    color: "#d9cdb0"
    pieces:
      - {kind: rod, from: [0.0, 0.6, -5.6569], to: [-5.6569, 0.6, 0.0], radius: 0.3, collide: 0}   # link DA
      - {kind: rod, from: [0.0, 0.35, -5.6569], to: [0.0, 0.85, -5.6569], radius: 0.55, collide: 0}   # its eyes
      - {kind: rod, from: [-5.6569, 0.35, 0.0], to: [-5.6569, 0.85, 0.0], radius: 0.55, collide: 0}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-7.6569, 0, 0.0], to: [-8.8569, 0, 0.0], radius: 0.8, collide: 0}
      - {kind: rod, from: [-9.8569, 0, 0.0], to: [-11.0569, 0, 0.0], radius: 0.8, collide: 0}
      - {kind: rod, from: [7.6569, 0, 0.0], to: [8.8569, 0, 0.0], radius: 0.8, collide: 0}
      - {kind: rod, from: [9.8569, 0, 0.0], to: [11.0569, 0, 0.0], radius: 0.8, collide: 0}
      - {kind: rod, from: [0.0, 0, 7.6569], to: [0.0, 0, 8.8569], radius: 0.8, collide: 0}
      - {kind: rod, from: [0.0, 0, 9.8569], to: [0.0, 0, 11.0569], radius: 0.8, collide: 0}
      - {kind: rod, from: [0.0, 0, -7.6569], to: [0.0, 0, -8.8569], radius: 0.8, collide: 0}
      - {kind: rod, from: [0.0, 0, -9.8569], to: [0.0, 0, -11.0569], radius: 0.8, collide: 0}
joints:
  - {id: j_a, type: slide, body: rod_a, axis: [1, 0, 0], range: [-3, 3], damping: 0.05}   # the one driven joint; + : in, toward the centre
  - {id: j_b, type: slide, body: rod_b, axis: [1, 0, 0], range: [-3, 3], damping: 0.05}   # + : out, to the right
  - {id: j_c, type: slide, body: rod_c, axis: [0, 0, 1], range: [-3, 3], damping: 0.05}   # + : up, out
  - {id: j_d, type: slide, body: rod_d, axis: [0, 0, 1], range: [-3, 3], damping: 0.05}   # + : up, in
  - {id: j_ac, type: hinge, body: link_ac, axis: [0, 1, 0], damping: 0.0005}
  - {id: j_cb, type: hinge, body: link_cb, axis: [0, 1, 0], damping: 0.0005}
  - {id: j_bd, type: hinge, body: link_bd, axis: [0, 1, 0], damping: 0.0005}
  - {id: j_da, type: hinge, body: link_da, axis: [0, 1, 0], damping: 0.0005}
pins:
  - {id: pin_c, a: link_ac, b: rod_c, at: [0.0, 0, 5.6569]}   # each link's far eye on the next rod's stud
  - {id: pin_b, a: link_cb, b: rod_b, at: [5.6569, 0, 0.0]}
  - {id: pin_d, a: link_bd, b: rod_d, at: [0.0, 0, -5.6569]}
  - {id: pin_a, a: link_da, b: rod_a, at: [-5.6569, 0, 0.0]}
driver: {joint: j_a, kind: velocity, rpm: 0, swing: {amplitude: 0.0150, hz: 0.4}, kv: 200.0, max_torque: 60.0}
checks:
  - {type: follow, out: j_b, in: j_a, expect: -1.0, tol: 0.02, min_r2: 0.999, settle_s: 0.5, window_s: 7.0}   # B comes in as A goes in
  - {type: follow, out: j_d, in: j_c, expect: -1.0, tol: 0.02, min_r2: 0.999, settle_s: 0.5, window_s: 7.0}   # D goes down as C goes up
  - {type: position, joint: j_c, min: -2.142, max: 1.2384, settle_s: 0.5, window_s: 7.0}   # C at sqrt(L^2 - x_A^2)
  - {type: amplitude, joint: j_c, min: 0.0158, max: 0.0168, sustain: 0.95, settle_s: 0.5, window_s: 7.0}
  - {type: follow, out: j_c, in: j_a, expect: 1.0626, tol: 0.0319, min_r2: 0.97, settle_s: 0.5, window_s: 7.0}   # thrust apart as A and B come together
camera: {target: [0, 0, -4.0], position: [0.0, -100.0, 0.0], fov: 34.0}
display:
  output: j_c
  labels: {j_a: "Rod A (driver)", j_b: "Rod B", j_c: "Rod C", j_d: "Rod D"}
  proof: {label: "A lozenge of links", sub: "A and B together, C and D apart"}

