# No. 101 (Brown 1868): "Rectilinear motion of horizontal bar, by means of vibrating slotted bar hung from the top."
#
# Model (cm): a disk (20 turns a minute, the one driven joint) carries a crank-pin 3 cm out, which works by real contact in the
# slot of a bar hung from a pivot 12 cm above the disk's centre; the bar vibrates 14.5 deg each way. A horizontal bar, 20 cm below
# the pivot, carries a pin that works in the same slot, and so is drawn to and fro in its guides, 10.3 cm in all: its place is
# 20 tan (the slotted bar's angle). Generator: opencode-runs/batch9/gen101.py.
number: 101
slug: slotted-bar-horizontal-bar
name: A horizontal bar worked by a slotted bar hung from the top
brown: "Rectilinear motion of horizontal bar, by means of vibrating slotted bar hung from the top."
units: cm
sim:
  timestep: 0.0005
  integrator: implicitfast
  iterations: 50
  solver: PGS
  duration_s: 10
  floor: false
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 0]
    mass: 1.5
    friction: 0.05
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [0, 0.5, 0], to: [0, 3.0, 0], radius: 0.8, color: "#8f8a80"}   # the shaft
      - {kind: disc, center: [0, 0], radius: 5.2, y: [0.0, 0.5]}   # the crank-disk, behind the slotted bar
      - {kind: rod, from: [0, 0.0, 3.0], to: [0, -1.4, 3.0], radius: 0.5, collide: 1, capsule: true, color: "#8f8a80"}   # the crank-pin
  - id: arm
    shape: part
    pos: [0, 0, 12.0]
    mass: 0.6
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [0, 12.0], radius: 1.4, inner: 0.4, y: [-1.0, 0.2]}   # the bar's eye on its pivot
      - {kind: poly, points: [[-0.9, 11.0], [0.9, 11.0], [1.82, 6.3], [-1.82, 6.3]], y: [-1.0, 0.2]}   # the slotted bar, above the slot
      - {kind: poly, points: [[0.52, 5.0], [1.82, 5.0], [1.82, -11.0], [0.52, -11.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-0.52, 5.0], [-1.82, 5.0], [-1.82, -11.0], [-0.52, -11.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, 6.3], [1.82, 6.3], [1.82, 5.0], [-1.82, 5.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, -11.0], [1.82, -11.0], [1.82, -12.3], [-1.82, -12.3]], y: [-1.0, 0.2], collide: 2}
  - id: hbar
    shape: part
    pos: [0, 0, -8.0]
    mass: 0.5
    friction: 0.05
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [0, -2.0, -8.0], to: [0, 0.1, -8.0], radius: 0.5, collide: 1, capsule: true, color: "#8f8a80"}   # the pin, in the slot
      - {kind: poly, points: [[-1.0, -8.6], [16, -8.6], [16, -7.4], [-1.0, -7.4]], y: [-2.4, -1.5]}   # the horizontal bar
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.6, -13.5], [1.6, -13.5], [1.1, 0], [-1.1, 0]], y: [1.8, 2.8]}   # the disk's standard, behind
      - {kind: poly, points: [[-1.0, 12.0], [1.0, 12.0], [1.0, 16.0], [-1.0, 16.0]], y: [0.4, 1.4]}   # the pivot's bracket
      - {kind: poly, points: [[-3, 16.0], [3, 16.0], [3, 17.2], [-3, 17.2]], y: [0.4, 2.8]}   # its cross-piece
      - {kind: poly, points: [[-1.0, -13.5], [1.0, -13.5], [1.0, 16.0], [-1.0, 16.0]], y: [1.8, 2.8]}   # the standard's post
      - {kind: poly, points: [[-8.6638, -7.25], [27.1638, -7.25], [27.1638, -6.4], [-8.6638, -6.4]], y: [-2.6, -1.3]}   # the bar's upper guide
      - {kind: poly, points: [[-8.6638, -9.6], [27.1638, -9.6], [27.1638, -8.75], [-8.6638, -8.75]], y: [-2.6, -1.3]}   # the lower guide
      - {kind: poly, points: [[25.1638, -13.5], [27.1638, -13.5], [27.1638, -6.4], [25.1638, -6.4]], y: [-2.6, -1.3]}   # their post
      - {kind: poly, points: [[-10, -14.5], [30.1638, -14.5], [30.1638, -13.5], [-10, -13.5]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_s, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_a, type: hinge, body: arm, axis: [0, 1, 0], damping: 0.1}   # the slotted bar on its pivot
  - {id: j_x, type: slide, body: hbar, axis: [1, 0, 0], range: [-5.5638, 5.6638], stiffness: 5.0, springref: -40, damping: 0.05}   # the horizontal bar in its guides, a weak spring keeping the slot loaded; + : to the right
driver: {joint: j_s, kind: velocity, rpm: 20.0, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_x, in: j_s, expect: 0.06624, tol: 0.00199, min_r2: 0.995, settle_s: 2.9333, window_s: 0.1333}   # through the middle, to the right
  - {type: follow, out: j_x, in: j_s, expect: -0.03566, tol: 0.00107, min_r2: 0.995, settle_s: 4.0833, window_s: 0.1667}   # coming back
  - {type: follow, out: j_x, in: j_s, expect: -0.03992, tol: 0.0012, min_r2: 0.995, settle_s: 4.4167, window_s: 0.1667}   # quickest, at the bottom of the turn
  - {type: follow, out: j_x, in: j_s, expect: -0.03566, tol: 0.00107, min_r2: 0.995, settle_s: 4.75, window_s: 0.1667}   # and going out again
  - {type: position, joint: j_x, min: -5.2638, max: 5.2638, settle_s: 0.5, window_s: 9}   # the bar's throw
camera: {target: [8.25, 0, 2.0], position: [8.25, -95, 2.0], fov: 34}
display:
  output: j_x
  labels: {j_s: "Crank-disk (driver)", j_a: "Slotted bar", j_x: "Horizontal bar"}
  proof: {label: "Bar's pin out of the slot", sub: "the crank swings the slotted bar but the horizontal bar stands"}

