# No. 252 (Brown 1868): "A and B are two rollers which require to be equally moved to and fro in the slot, C. This is accomplished by moving
# the piece, D, with oblique slotted arms, up and down."
#
# Model (cm, gravity on, front view): the slot C is fixed; the rollers A and B run in it (their slides) on pins that pass back through the
# oblique slots in D's two arms, sloped 0.55 across per unit of rise, each the mirror of the other, 0.03 cm clear each side of the pin. The hand
# moves D up and down 2 cm at 0.25 Hz (the one driven joint); the slots' sides alone move the pins, A and B equally and opposite, 0.55 cm
# per cm of D (apart as D rises). Generator: opencode-runs/batch11/gen252.py.
number: 252
slug: rollers-moved-by-oblique-slots
name: Rollers equally moved by an oblique slotted piece
brown: "A and B are two rollers which require to be equally moved to and fro in the slot, C. This is accomplished by moving the piece, D, with oblique slotted arms, up and down."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 50, duration_s: 8, floor: false}
bodies:
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#a39a88"
    pieces:
      - {kind: poly, points: [[-9.5, 10.6], [9.5, 10.6], [9.5, 11.6], [-9.5, 11.6]], y: [-1.3, 1.3], collide: 0}   # the slot C's upper bar
      - {kind: poly, points: [[-9.5, 8.4], [9.5, 8.4], [9.5, 9.4], [-9.5, 9.4]], y: [-1.3, 1.3], collide: 0}   # its lower bar
      - {kind: poly, points: [[-13, 6], [-9.5, 8.4], [-9.5, 11.6], [-13, 14]], y: [-1.3, 1.3], collide: 0}   # its stock
      - {kind: poly, points: [[-0.9, -12], [0.9, -12], [0.9, -4], [-0.9, -4]], y: [-1.2, -0.7], collide: 0}   # D's guide (behind its stem)
  - id: d
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-8.9839, 1.5687], [-8.4582, 1.2795], [-1.5832, 13.7795], [-2.1089, 14.0687]], y: [-0.6, 0.6], collide: 2}   # A's oblique slot, lower side
      - {kind: poly, points: [[-7.4418, 0.7205], [-6.9161, 0.4313], [-0.0411, 12.9313], [-0.5668, 13.2205]], y: [-0.6, 0.6], collide: 2}   # A's oblique slot, upper side
      - {kind: poly, points: [[8.4582, 1.2795], [8.9839, 1.5687], [2.1089, 14.0687], [1.5832, 13.7795]], y: [-0.6, 0.6], collide: 2}   # B's oblique slot, lower side
      - {kind: poly, points: [[6.9161, 0.4313], [7.4418, 0.7205], [0.5668, 13.2205], [0.0411, 12.9313]], y: [-0.6, 0.6], collide: 2}   # B's oblique slot, upper side
      - {kind: poly, points: [[-8.9839, 1.5687], [-2.1089, 14.0687], [-2.7399, 14.4157], [-9.6149, 1.9157]], y: [-0.6, 0.6], collide: 0}   # A's slotted arm, outer border (cosmetic, as Brown's loop)
      - {kind: poly, points: [[-6.2851, 0.0843], [0.5899, 12.5843], [-0.0411, 12.9313], [-6.9161, 0.4313]], y: [-0.6, 0.6], collide: 0}   # A's slotted arm, inner border (cosmetic, as Brown's loop)
      - {kind: poly, points: [[-2.1089, 14.0687], [-0.0411, 12.9313], [0.1998, 13.3695], [-1.868, 14.5069]], y: [-0.6, 0.6], collide: 0}   # A's slotted arm, closed end (cosmetic, as Brown's loop)
      - {kind: poly, points: [[9.6149, 1.9157], [2.7399, 14.4157], [2.1089, 14.0687], [8.9839, 1.5687]], y: [-0.6, 0.6], collide: 0}   # B's slotted arm, outer border (cosmetic, as Brown's loop)
      - {kind: poly, points: [[6.9161, 0.4313], [0.0411, 12.9313], [-0.5899, 12.5843], [6.2851, 0.0843]], y: [-0.6, 0.6], collide: 0}   # B's slotted arm, inner border (cosmetic, as Brown's loop)
      - {kind: poly, points: [[1.868, 14.5069], [-0.1998, 13.3695], [0.0411, 12.9313], [2.1089, 14.0687]], y: [-0.6, 0.6], collide: 0}   # B's slotted arm, closed end (cosmetic, as Brown's loop)
      - {kind: poly, points: [[-10, -0.8], [10, -0.8], [10, 1.0], [-10, 1.0]], y: [-0.6, 0.6], collide: 0}   # its cross-bar
      - {kind: poly, points: [[-1.2, -1.6], [1.2, -1.6], [1.2, 1.4], [-1.2, 1.4]], y: [-0.9, 0.9], collide: 0}   # its boss
      - {kind: rod, from: [0, 0, -1.6], to: [0, 0, -12], radius: 0.5, collide: 0}   # its stem
  - id: roller_a
    shape: part
    pos: [-3, 0, 10]
    mass: 0.1
    friction: 0.1
    color: "#c9bfa9"
    pieces:
      - {kind: rod, from: [-3, -1.3, 10], to: [-3, 1.3, 10], radius: 0.55, collide: 1, capsule: true}   # its pin, through C and D's slot
      - {kind: disc, center: [-3, 10], radius: 1.6, inner: 0.56, y: [1.3, 1.9], collide: 0}   # the roller, in front of C
      - {kind: disc, center: [-3, 10], radius: 1.6, inner: 0.56, y: [-1.9, -1.3], collide: 0}   # its washer behind D
  - id: roller_b
    shape: part
    pos: [3, 0, 10]
    mass: 0.1
    friction: 0.1
    color: "#c9bfa9"
    pieces:
      - {kind: rod, from: [3, -1.3, 10], to: [3, 1.3, 10], radius: 0.55, collide: 1, capsule: true}   # its pin, through C and D's slot
      - {kind: disc, center: [3, 10], radius: 1.6, inner: 0.56, y: [1.3, 1.9], collide: 0}   # the roller, in front of C
      - {kind: disc, center: [3, 10], radius: 1.6, inner: 0.56, y: [-1.9, -1.3], collide: 0}   # its washer behind D
joints:
  - {id: j_d, type: slide, body: d, axis: [0, 0, 1], damping: 0.2}   # D, moved up and down by hand: the one driven joint
  - {id: j_a, type: slide, body: roller_a, axis: [1, 0, 0], damping: 0.02}   # A in the slot C (+: right)
  - {id: j_b, type: slide, body: roller_b, axis: [1, 0, 0], damping: 0.02}   # B in the slot C
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_d, kind: velocity, swing: {amplitude: 0.02, hz: 0.25}, kv: 20000, max_torque: 50}
checks:
  - {type: follow, out: j_a, in: j_d, expect: -0.55, tol: 0.02, min_r2: 0.99, settle_s: 0.5, window_s: 7}   # A moves 0.55 cm per cm of D, left as D rises
  - {type: follow, out: j_b, in: j_d, expect: 0.55, tol: 0.02, min_r2: 0.99, settle_s: 0.5, window_s: 7}   # B the same, right
  - {type: follow, out: j_b, in: j_a, expect: -1, tol: 0.02, min_r2: 0.99, settle_s: 0.5, window_s: 7}   # equally, and opposite
  - {type: penetration, max: 0.002, settle_s: 0.3}
camera: {target: [-1.5, 0, -1.5], position: [-1.5, -68, 0.5], fov: 30}
display:
  output: j_a
  labels: {j_d: "D (driver)", j_a: "Roller A", j_b: "Roller B"}

