# No. 282 (Brown 1868): "By the revolution of the disk in which is fixed a pin working in a slot in the upright bar which turns on a center near the bottom, both ends of the bar are made to traverse, the toothed sector producing alternate rectilinear motion in the horizontal bar at the bottom, and also alternate perpendicular motion of the weight."
#
# Model (cm, gravity on): a disk of 8.6 cm radius turns on a shaft 16.0 cm above the centre of an upright bar (the one driven joint, 12 rpm). A crank-pin 6.0 cm from the disk's centre works in a slot in the bar (8.3 to 23.5 cm from its centre);
# the bar swings asin(6.0/16.0) = 0.384 rad each way. Below its centre it carries a toothed sector (module 0.8, pitch radius 7.2, as No. 131), which works the rack along the bottom (7.2 cm to the radian). Its top end, 30.0 cm up,
# draws a cord over a pulley at the right (1.5 cm, top level with the eye) from which a weight of 0.5 kg hangs: the bar's head swinging left raises the weight and swinging right lets it down. The weight keeps the cord taut and the pin on one wall of the slot.
# A curved guide spans the top of the frame as in the plate (drawn). Generator: opencode-runs/batch12/gen282.py.
number: 282
slug: slotted-bar-sector-rack-weight
name: A crank-pin in an upright slotted bar working a rack and a weight
brown: "By the revolution of the disk in which is fixed a pin working in a slot in the upright bar which turns on a center near the bottom, both ends of the bar are made to traverse, the toothed sector producing alternate rectilinear motion in the horizontal bar at the bottom, and also alternate perpendicular motion of the weight."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 12.0
  floor: false
bodies:
  - id: disk
    shape: part
    pos: [0, 0, 16.0]
    mass: 1.5
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 16.0], radius: 8.6, inner: 1.6, y: [0.4, 1.9], collide: 0}
      - {kind: rod, from: [0, -0.8, 10.0], to: [0, 0.8, 10.0], radius: 1.0, collide: 2, capsule: true, color: "#8f8a80"}   # the crank-pin
      - {kind: rod, from: [0, -0.1, 16.0], to: [0, 2.6, 16.0], radius: 0.9, collide: 0, color: "#8f8a80"}
  - id: arm
    shape: part
    pos: [0, 0, 0]
    mass: 0.6
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-2.5, 8.3], [-1.2, 8.3], [-1.2, 23.5], [-2.5, 23.5]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[1.2, 8.3], [2.5, 8.3], [2.5, 23.5], [1.2, 23.5]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[-2.5, 23.5], [2.5, 23.5], [2.5, 31.2], [-2.5, 31.2]], y: [-1.4, -0.2], collide: 0}   # the bar above the slot, to its top end
      - {kind: poly, points: [[-2.5, 7.0], [2.5, 7.0], [2.5, 8.3], [-2.5, 8.3]], y: [-1.4, -0.2], collide: 0}
      - {kind: poly, points: [[-2.2, 0.0], [2.2, 0.0], [2.2, 7.0], [-2.2, 7.0]], y: [-1.4, -0.2], collide: 0}
      - {kind: disc, center: [0, 0], radius: 2.6, inner: 0.9, y: [-1.7, 0.0], collide: 0}
      - {kind: rod, from: [0, -1.6, 30.0], to: [0, 0.0, 30.0], radius: 0.45, collide: 0, color: "#5f5a52"}   # the cord's eye
      - {kind: poly, points: [[0, 0], [-6.2535, -1.1027], [-5.967, -2.1718], [-5.4993, -3.175], [-4.8644, -4.0817], [-4.0817, -4.8644], [-3.175, -5.4993], [-2.1718, -5.967], [-1.1027, -6.2535], [0.0, -6.35], [1.1027, -6.2535], [2.1718, -5.967], [3.175, -5.4993], [4.0817, -4.8644], [4.8644, -4.0817], [5.4993, -3.175], [5.967, -2.1718], [6.2535, -1.1027]], y: [-1.4, -0.2], collide: 0}
      - {kind: poly, points: [[-6.4493, -0.2801], [-6.1562, -1.9426], [-7.5815, -1.6913], [-7.7027, -1.0037]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[-5.9646, -2.469], [-5.1205, -3.931], [-6.5458, -4.1823], [-6.8949, -3.5777]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[-4.7605, -4.3601], [-3.4672, -5.4453], [-4.7206, -6.1689], [-5.2555, -5.7201]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[-2.9821, -5.7253], [-1.3957, -6.3027], [-2.326, -7.4114], [-2.9821, -7.1726]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[-0.8441, -6.4], [0.8441, -6.4], [0.3491, -7.76], [-0.3491, -7.76]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[1.3957, -6.3027], [2.9821, -5.7253], [2.9821, -7.1726], [2.326, -7.4114]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[3.4672, -5.4453], [4.7605, -4.3601], [5.2555, -5.7201], [4.7206, -6.1689]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[5.1205, -3.931], [5.9646, -2.469], [6.8949, -3.5777], [6.5458, -4.1823]], y: [-1.4, -0.2], collide: 1}
      - {kind: poly, points: [[6.1562, -1.9426], [6.4493, -0.2801], [7.7027, -1.0037], [7.5815, -1.6913]], y: [-1.4, -0.2], collide: 1}
  - id: rack
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-12.5664, -9.0], [12.5664, -9.0], [12.5664, -8.0], [-12.5664, -8.0]], y: [-1.4, -0.2], collide: 0}   # the bar behind the teeth
      - {kind: rod, from: [-16.5664, -0.8, -8.5], to: [16.5664, -0.8, -8.5], radius: 0.5, collide: 0, color: "#a89a7e"}   # the rack's rod, running in bearings
      - {kind: poly, points: [[-12.1287, -8.0], [-10.4908, -8.0], [-10.9275, -6.8], [-11.6919, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[-9.6154, -8.0], [-7.9775, -8.0], [-8.4143, -6.8], [-9.1787, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[-7.1021, -8.0], [-5.4642, -8.0], [-5.901, -6.8], [-6.6654, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[-4.5889, -8.0], [-2.9509, -8.0], [-3.3877, -6.8], [-4.1521, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[-2.0756, -8.0], [-0.4377, -8.0], [-0.8744, -6.8], [-1.6388, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[0.4377, -8.0], [2.0756, -8.0], [1.6388, -6.8], [0.8744, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[2.9509, -8.0], [4.5889, -8.0], [4.1521, -6.8], [3.3877, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[5.4642, -8.0], [7.1021, -8.0], [6.6654, -6.8], [5.901, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[7.9775, -8.0], [9.6154, -8.0], [9.1787, -6.8], [8.4143, -6.8]], y: [-1.4, -0.2], collide: 2}
      - {kind: poly, points: [[10.4908, -8.0], [12.1287, -8.0], [11.6919, -6.8], [10.9275, -6.8]], y: [-1.4, -0.2], collide: 2}
  - id: weight
    shape: part
    pos: [0, 0, 0]
    mass: 0.5
    color: "#7d756a"
    pieces:
      - {kind: poly, points: [[19.9, 10.5], [23.1, 10.5], [23.1, 14.4], [19.9, 14.4]], y: [-2.0, 0.4], collide: 0}   # the weight
      - {kind: rod, from: [21.5, -0.8, 14.3], to: [21.5, -0.8, 15.0], radius: 0.25, collide: 0, color: "#5f5a52"}   # its eye
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.9, 0], to: [0, 2.6, 0], radius: 1.1, collide: 0, color: "#8f8a80"}   # the bar's centre
      - {kind: rod, from: [0, 1.9, 16.0], to: [0, 2.6, 16.0], radius: 1.4, collide: 0, color: "#8f8a80"}   # the disk's bearing
      - {kind: poly, points: [[-1.8, -14.0], [1.8, -14.0], [1.4, 0], [-1.4, 0]], y: [2.0, 3.2], collide: 0}   # its standard behind
      - {kind: poly, points: [[-16.720399999999998, -14.0], [-15.3204, -14.0], [-15.3204, 22.3003], [-16.720399999999998, 22.3003]], y: [1.4, 2.6], collide: 0}   # the uprights
      - {kind: poly, points: [[15.3204, -14.0], [16.720399999999998, -14.0], [16.720399999999998, 22.3003], [15.3204, 22.3003]], y: [1.4, 2.6], collide: 0}
      - {kind: poly, points: [[-15.3204, 15.2], [15.3204, 15.2], [15.3204, 16.8], [-15.3204, 16.8]], y: [2.6, 3.2], collide: 0}   # the cross-rail carrying the disk's bearing
      - {kind: poly, points: [[-15.9204, 22.3003], [-13.04, 24.0981], [-13.9918, 25.8571], [-17.0824, 23.928]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-13.04, 24.0981], [-9.9593, 25.5259], [-10.6863, 27.3891], [-13.9918, 25.8571]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-9.9593, 25.5259], [-6.7258, 26.5617], [-7.2167, 28.5005], [-10.6863, 27.3891]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-6.7258, 26.5617], [-3.3889, 27.1896], [-3.6363, 29.1743], [-7.2167, 28.5005]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-3.3889, 27.1896], [0.0, 27.4], [0.0, 29.4], [-3.6363, 29.1743]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[0.0, 27.4], [3.3889, 27.1896], [3.6363, 29.1743], [0.0, 29.4]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[3.3889, 27.1896], [6.7258, 26.5617], [7.2167, 28.5005], [3.6363, 29.1743]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[6.7258, 26.5617], [9.9593, 25.5259], [10.6863, 27.3891], [7.2167, 28.5005]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[9.9593, 25.5259], [13.04, 24.0981], [13.9918, 25.8571], [10.6863, 27.3891]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[13.04, 24.0981], [15.9204, 22.3003], [17.0824, 23.928], [13.9918, 25.8571]], y: [0.6, 1.4], collide: 0, color: "#b9b09c"}   # the curved guide
      - {kind: poly, points: [[15.3204, 25.5], [16.3204, 25.5], [20.6, 28.5], [19.4, 29.7]], y: [0.0, 0.8], collide: 0}   # the pulley's bracket
      - {kind: disc, center: [20.0, 29.1], radius: 1.5, y: [-1.3, -0.3], collide: 0, color: "#d9cfb6"}   # the pulley
      - {kind: rod, from: [20.0, -1.6, 29.1], to: [20.0, 0.8, 29.1], radius: 0.4, collide: 0, color: "#8f8a80"}
      - {kind: poly, points: [[-19.5664, -15.0], [25.5, -15.0], [25.5, -14.0], [-19.5664, -14.0]], y: [-3, 3], color: "#b9b09c", collide: 0}   # the bench
      - {kind: poly, points: [[-18.5664, -11.2], [-16.1664, -11.2], [-16.1664, -5.8], [-18.5664, -5.8]], y: [-1.6, 0.2], collide: 0}   # the rack's bearings, either end
      - {kind: poly, points: [[16.1664, -11.2], [18.5664, -11.2], [18.5664, -5.8], [16.1664, -5.8]], y: [-1.6, 0.2], collide: 0}
joints:
  - {id: j_d, type: hinge, body: disk, axis: [0, 1, 0], damping: 0.002}   # the one driven joint; + : clockwise
  - {id: j_arm, type: hinge, body: arm, axis: [0, 1, 0], damping: 0.01}   # + : clockwise, the head moving right and the sector's teeth left
  - {id: j_x, type: slide, body: rack, axis: [1, 0, 0], damping: 0.05}   # + : right
  - {id: j_w, type: slide, body: weight, axis: [0, 0, 1], damping: 0.3}   # the weight on its cord; + : up
ropes:
  - {id: cord, from: {body: arm, at: [0, -0.8, 30.0]}, over: {center: [20.0, -0.8, 29.1], radius: 1.5, axis: y, side: [20.0, -0.8, 33.1]}, to: {body: weight, at: [21.5, -0.8, 15.0]}, width: 0.4, thickness: 0.3}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_d, kind: velocity, rpm: 12.0, kv: 50.0, max_torque: 30}
checks:
  - {type: follow, out: j_x, in: j_arm, expect: -0.0762, tol: 0.0036, min_r2: 0.995, settle_s: 1.0, window_s: 8.0}   # the rack runs left as the sector turns clockwise; 7.6 cm to the radian measured (the straight flanks of No. 131 bear a little outside the 7.2 cm pitch circle)
  - {type: follow, out: j_w, in: j_arm, expect: -0.2925, tol: 0.018, min_r2: 0.99, settle_s: 1.0, window_s: 8.0}   # the weight falls as the head swings right (the cord's run ~ LT sin)
  - {type: amplitude, joint: j_arm, min: 0.3575, max: 0.4036, settle_s: 1, window_s: 10}   # the bar's swing: asin(pin radius over the shafts' distance)
  - {type: position, joint: j_x, min: -3.3677, max: 3.3677, settle_s: 0.0, window_s: 12}
camera: {target: [4.0, 0, -2.4], position: [4.0, -140.0, -0.4], fov: 34}
display:
  output: j_w
  labels: {j_d: "Disk (driver)", j_arm: "Slotted bar and sector", j_x: "Rack", j_w: "Weight"}
  proof: {label: "Bar out of contact", sub: "the disk turns but the rack stands"}

