# No. 232 (Brown 1868): "Intermittent circular motion is imparted to the toothed wheel by vibrating the arm, B. ..."
#
# Model (cm, gravity on): a 20-tooth wheel (tips 10, roots 8.6) on a fixed centre against a little bearing friction. On the same centre turn the arm A,
# held by its own friction, and the lever B, rocked by hand +-0.283 rad at 0.5 Hz (the one driven joint). A pin on A, 11.2 above the centre, carries the
# curved pawl C, whose tooth drops between the wheel's teeth; a link from B's pin (3 out) to C's lug (3 out from C's pin) makes a parallelogram, so B
# turning on A turns C on its pin. C has 0.2 rad of play on A. Lifting B first raises C out of the teeth, then carries A and C backward over a tooth; lowering
# B drops C between two teeth and then draws A, C and the wheel forward: one tooth clockwise to each to-and-fro. Generator: opencode-runs/batch11/gen232.py.
number: 232
slug: vibrating-arm-pawl-toothed-wheel
name: A toothed wheel turned by a vibrating arm and a lifted pawl
brown: "Intermittent circular motion is imparted to the toothed wheel by vibrating the arm, B. When the arm, B, is lifted, the pawl, C, is raised from between the teeth of the wheel, and, traveling backward over the circumference, again drops between two teeth on lowering the arm, and draws with it the wheel."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 12.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 8.6, inner: 0.6, y: [-0.5, 0.5]}
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.6, y: [-0.7, 0.8], color: "#cfc6b4"}
      - {kind: poly, points: [[4.9902, 6.881], [5.6784, 8.2314], [4.602, 8.8782], [3.7328, 7.6365]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.6196, 8.0863], [2.8569, 9.5832], [1.6333, 9.8657], [1.1903, 8.4162]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.0074, 8.5], [-0.2443, 9.997], [-1.4954, 9.8876], [-1.4687, 8.3722]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.6337, 8.0817], [-3.3216, 9.4322], [-4.4776, 8.9415], [-3.984, 7.5085]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-5.0022, 6.8723], [-6.0738, 7.9441], [-7.0215, 7.1203], [-6.1092, 5.9099]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.881, 4.9902], [-8.2314, 5.6784], [-8.8782, 4.602], [-7.6365, 3.7328]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-8.0863, 2.6196], [-9.5832, 2.8569], [-9.8657, 1.6333], [-8.4162, 1.1903]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-8.5, -0.0074], [-9.997, -0.2443], [-9.8876, -1.4954], [-8.3722, -1.4687]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-8.0817, -2.6337], [-9.4322, -3.3216], [-8.9415, -4.4776], [-7.5085, -3.984]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-6.8723, -5.0022], [-7.9441, -6.0738], [-7.1203, -7.0215], [-5.9099, -6.1092]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.9902, -6.881], [-5.6784, -8.2314], [-4.602, -8.8782], [-3.7328, -7.6365]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.6196, -8.0863], [-2.8569, -9.5832], [-1.6333, -9.8657], [-1.1903, -8.4162]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.0074, -8.5], [0.2443, -9.997], [1.4954, -9.8876], [1.4687, -8.3722]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.6337, -8.0817], [3.3216, -9.4322], [4.4776, -8.9415], [3.984, -7.5085]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[5.0022, -6.8723], [6.0738, -7.9441], [7.0215, -7.1203], [6.1092, -5.9099]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.881, -4.9902], [8.2314, -5.6784], [8.8782, -4.602], [7.6365, -3.7328]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[8.0863, -2.6196], [9.5832, -2.8569], [9.8657, -1.6333], [8.4162, -1.1903]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[8.5, 0.0074], [9.997, 0.2443], [9.8876, 1.4954], [8.3722, 1.4687]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[8.0817, 2.6337], [9.4322, 3.3216], [8.9415, 4.4776], [7.5085, 3.984]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[6.8723, 5.0022], [7.9441, 6.0738], [7.1203, 7.0215], [5.9099, 6.1092]], y: [-0.5, 0.5], collide: 1}
  - id: arm_a
    shape: part
    pos: [0, 0, 0]
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-1.6, -2.2], [1.6, -2.2], [1.0, 11.2], [-1.0, 11.2]], y: [-1.5, -0.9]}   # the arm A
      - {kind: disc, center: [0, 0], radius: 2.4, inner: 0.6, y: [-1.5, -0.9]}
      - {kind: disc, center: [0, 11.2], radius: 1.0, y: [-1.5, -0.9]}
      - {kind: disc, center: [0, -2.6], radius: 1.6, y: [-1.5, -0.9]}   # its foot, which nearly balances it
      - {kind: rod, from: [0, -1.0, 11.2], to: [0, 0.6, 11.2], radius: 0.2, color: "#8f8a80"}   # C's pin
      - {kind: disc, center: [-0.9, 1.3], radius: 0.25, y: [-1.6, -1.4], color: "#8f8a80"}   # screw heads
      - {kind: disc, center: [0.9, -2.9], radius: 0.25, y: [-1.6, -1.4], color: "#8f8a80"}
  - id: pawl_c
    shape: part
    pos: [0, 0, 11.2]
    mount: arm_a
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: disc, center: [0, 11.2], radius: 0.6, inner: 0.2, y: [-0.4, 0.4]}
      - {kind: poly, points: [[-0.0324, 10.651], [0.0324, 11.749], [1.3488, 11.6714], [1.284, 10.5733]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[1.2197, 10.5809], [1.4131, 11.6638], [2.7113, 11.432], [2.5179, 10.3491]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[2.4549, 10.3642], [2.7742, 11.4169], [4.0362, 11.0341], [3.7169, 9.9814]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[3.6561, 10.0038], [4.0969, 11.0116], [5.3051, 10.4832], [4.8643, 9.4754]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[4.8066, 9.5048], [5.3628, 10.4538], [6.5005, 9.787], [5.9443, 8.838]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[5.8904, 8.8739], [6.5543, 9.751], [7.6058, 8.9551], [6.9419, 8.078]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[6.8926, 8.1201], [7.655, 8.913], [8.6056, 7.999], [7.8432, 7.2061]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[7.7993, 7.2537], [8.6496, 7.9515], [9.4861, 6.9321], [8.6358, 6.2343]], y: [-0.4, 0.4]}
      - {kind: poly, points: [[5.9828, 6.6633], [7.2608, 7.8753], [6.4948, 8.5181], [5.5231, 7.0489]], y: [-0.4, 0.4], collide: 2}   # its tooth
      - {kind: poly, points: [[0.3, 10.85], [3.0, 10.75], [3.0, 11.65], [0.3, 11.55]], y: [-0.4, 0.4]}   # its lug
      - {kind: rod, from: [3.0, -0.4, 11.2], to: [3.0, -3.2, 11.2], radius: 0.2, color: "#8f8a80"}   # the link's pin
  - id: lever_b
    shape: part
    pos: [0, 0, 0]
    color: "#cfc3a8"
    pieces:
      - {kind: poly, points: [[0, -0.55], [0, 0.55], [17.0, 0.45], [17.0, -0.45]], y: [-2.3, -1.7]}   # the lever B
      - {kind: disc, center: [0, 0], radius: 1.3, inner: 0.6, y: [-2.3, -1.7]}
      - {kind: disc, center: [3.0, 0], radius: 0.7, y: [-2.3, -1.7]}
      - {kind: rod, from: [3.0, -1.7, 0], to: [3.0, -3.2, 0], radius: 0.2, color: "#8f8a80"}   # the link's pin
  - id: link
    shape: part
    pos: [3.0, 0, 0]
    mount: lever_b
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[2.65, 0], [3.35, 0], [3.35, 11.2], [2.65, 11.2]], y: [-3.0, -2.5]}   # the link
      - {kind: disc, center: [3.0, 0], radius: 0.6, inner: 0.2, y: [-3.0, -2.5]}
      - {kind: disc, center: [3.0, 11.2], radius: 0.6, inner: 0.2, y: [-3.0, -2.5]}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -2.6, 0], to: [0, 2.4, 0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: poly, points: [[-1.4, -13.2], [1.4, -13.2], [0.9, 0], [-0.9, 0]], y: [1.2, 2.4]}   # the standard
      - {kind: poly, points: [[-13, -14.4], [19, -14.4], [19, -13.2], [-13, -13.2]], y: [-4, 4], color: "#b9b09c"}
joints:
  - {id: j_b, type: hinge, body: lever_b, axis: [0, -1, 0], damping: 0.001}   # the one driven joint; +: counter-clockwise (lifting)
  - {id: j_a, type: hinge, body: arm_a, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.2}
  - {id: j_c, type: hinge, body: pawl_c, axis: [0, -1, 0], damping: 0.0005, range: [0, 0.2]}   # C's play on A; 0: down between the teeth
  - {id: j_link, type: hinge, body: link, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.2}   # +: counter-clockwise
pins:
  - {id: pin_c, a: link, b: pawl_c, at: [3.0, -2.75, 11.2]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_b, kind: velocity, rpm: 0, swing: {amplitude: 0.2830, hz: 0.5}, kv: 20, max_torque: 60}
checks:
  - {type: advance, joint: j_wheel, beat: j_b, expect: -0.15708, tol: 0.06, settle_s: 2.5, window_s: 9}   # one tooth (2 pi / 20) clockwise each to-and-fro, half of it a beat
  - {type: monotonic, joint: j_wheel, direction: -1, max_back: 0.03, settle_s: 1, window_s: 10.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [3.0, 0, -1.0], position: [3.0, -95.0, 3.0], fov: 34}
display:
  output: j_wheel
  labels: {j_b: "Arm B (driver)", j_a: "Arm A", j_c: "Pawl C", j_wheel: "Toothed wheel"}
  proof: {label: "Pawl's tooth out of contact", sub: "the arm vibrates, the pawl rises and falls, the wheel never moves"}

