# No. 98 (Brown 1868): "Irregular vibrating motion is produced by the rotation of the circular disk, in which is fixed a
# crank-pin working in an endless groove cut in the vibrating arm."
#
# Model (cm): the disk (the one driven joint, 20 turns a minute, clockwise in the view) carries a crank-pin 4 cm from its
# centre. The vibrating arm hangs on a pivot 12 cm above the centre; it is cut with an endless (closed) groove, 1.0 cm wide,
# along its length, in which the pin works by real contact. The pin takes the arm round to the angle of the line from the pivot,
# swinging it 19.5 deg each way, quicker through the middle than at the ends. Generator: opencode-runs/batch9/gen098.py.
number: 98
slug: crank-pin-endless-groove
name: A crank-pin working in an endless groove of a vibrating arm
brown: "Irregular vibrating motion is produced by the rotation of the circular disk, in which is fixed a crank-pin working in an endless groove cut in the vibrating arm."
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: 6.2, y: [0.0, 0.5]}   # the circular disk, behind the arm
      - {kind: rod, from: [0, 0.0, 4.0], to: [0, -1.4, 4.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 arm's eye on its pivot
      - {kind: poly, points: [[-0.9, 11.0], [0.9, 11.0], [1.82, 7.3], [-1.82, 7.3]], y: [-1.0, 0.2]}   # the arm, above the groove
      - {kind: poly, points: [[0.52, 6.0], [1.82, 6.0], [1.82, -6.0], [0.52, -6.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-0.52, 6.0], [-1.82, 6.0], [-1.82, -6.0], [-0.52, -6.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, 7.3], [1.82, 7.3], [1.82, 6.0], [-1.82, 6.0]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, -6.0], [1.82, -6.0], [1.82, -7.3], [-1.82, -7.3]], y: [-1.0, 0.2], collide: 2}
      - {kind: poly, points: [[-1.82, -7.3], [1.82, -7.3], [0.8, -11.0], [-0.8, -11.0]], y: [-1.0, 0.2]}   # the arm's foot
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.6, -11], [1.6, -11], [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, -11], [1.0, -11], [1.0, 16.0], [-1.0, 16.0]], y: [1.8, 2.8]}   # the standard's post
      - {kind: poly, points: [[-9, -12], [9, -12], [9, -11], [-9, -11]], 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 vibrating arm on its pivot; + : tip to the left
driver: {joint: j_s, kind: velocity, rpm: 20.0, kv: 20.0, max_torque: 20}
checks:
  - {type: follow, out: j_a, in: j_s, expect: -0.4981, tol: 0.01494, min_r2: 0.995, settle_s: 2.9583, window_s: 0.0833}   # pin at its lowest-rate: through the middle
  - {type: follow, out: j_a, in: j_s, expect: 0.09963, tol: 0.00299, min_r2: 0.995, settle_s: 3.7083, window_s: 0.0833}
  - {type: follow, out: j_a, in: j_s, expect: 0.24988, tol: 0.0075, min_r2: 0.99, settle_s: 4.4583, window_s: 0.0833}
  - {type: follow, out: j_a, in: j_s, expect: 0.09963, tol: 0.00299, min_r2: 0.995, settle_s: 5.2083, window_s: 0.0833}
  - {type: position, joint: j_a, min: -0.3598, max: 0.3598, settle_s: 0.5, window_s: 9}
camera: {target: [0, 0, 1.0], position: [0, -85, 2.0], fov: 34}
display:
  output: j_a
  labels: {j_s: "Disk and crank-pin (driver)", j_a: "Vibrating arm"}
  proof: {label: "Crank-pin out of contact", sub: "the disk turns but the arm stands"}

