# No. 75 (Brown 1868): "Reciprocating rectilinear motion of the rod, C, transmits an intermittent
# circular motion to the wheel, A, by means of the pawl, B, at the end of the vibrating-bar, D."
#
# Model (cm): A, a 24-tooth ratchet, turns on a fixed centre. The vibrating bar D turns on the same
# centre; a pin on the rod C (slid up and down 1.6 cm either way by a crank and slotted yoke below,
# the crank being the one driven joint, 30 turns a minute) works in a slot at D's end, so D swings about 22 deg. The pawl B, on
# a pin near D's end, is held on A's teeth by its spring. Rising, D's pawl pushes a tooth's face; falling,
# it slides back over the next tooth and drops behind it, so every up-stroke carries A one tooth.
# A's bearing friction holds it while the pawl slides back. Generator: opencode-runs/batch8/gen075.py.
number: 75
slug: rod-pawl-ratchet
name: Intermittent circular motion from a reciprocating rod by a pawl
brown: "Reciprocating rectilinear motion of the rod, C, transmits an intermittent circular motion to the wheel, A, by means of the pawl, B, at the end of the vibrating-bar, D."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 13
  floor: false
bodies:
  - id: wheel_a
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 4.3, inner: 0.6, y: [-0.5, 0.5]}
      - {kind: poly, points: [[4.2, 0.0], [5.0, 0.0], [4.0569, 1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.0569, 1.087], [4.8296, 1.2941], [3.6373, 2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.6373, 2.1], [4.3301, 2.5], [2.9698, 2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9698, 2.9698], [3.5355, 3.5355], [2.1, 3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.1, 3.6373], [2.5, 4.3301], [1.087, 4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.087, 4.0569], [1.2941, 4.8296], [0.0, 4.2]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.0, 4.2], [0.0, 5.0], [-1.087, 4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.087, 4.0569], [-1.2941, 4.8296], [-2.1, 3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.1, 3.6373], [-2.5, 4.3301], [-2.9698, 2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9698, 2.9698], [-3.5355, 3.5355], [-3.6373, 2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6373, 2.1], [-4.3301, 2.5], [-4.0569, 1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.0569, 1.087], [-4.8296, 1.2941], [-4.2, 0.0]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.2, 0.0], [-5.0, 0.0], [-4.0569, -1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.0569, -1.087], [-4.8296, -1.2941], [-3.6373, -2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.6373, -2.1], [-4.3301, -2.5], [-2.9698, -2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.9698, -2.9698], [-3.5355, -3.5355], [-2.1, -3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.1, -3.6373], [-2.5, -4.3301], [-1.087, -4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.087, -4.0569], [-1.2941, -4.8296], [-0.0, -4.2]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-0.0, -4.2], [-0.0, -5.0], [1.087, -4.0569]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[1.087, -4.0569], [1.2941, -4.8296], [2.1, -3.6373]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.1, -3.6373], [2.5, -4.3301], [2.9698, -2.9698]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.9698, -2.9698], [3.5355, -3.5355], [3.6373, -2.1]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[3.6373, -2.1], [4.3301, -2.5], [4.0569, -1.087]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.0569, -1.087], [4.8296, -1.2941], [4.2, -0.0]], y: [-0.5, 0.5], collide: 1}
  - id: bar_d
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[0, -0.5], [7.3, -0.5], [7.3, 0.5], [0, 0.5]], y: [0.6, 1.2]}   # the bar, behind A
      - {kind: disc, center: [0, 0], radius: 1.0, inner: 0.6, y: [0.6, 1.2]}
      - {kind: poly, points: [[7.3, -0.67], [10.1, -0.67], [10.1, -0.27], [7.3, -0.27]], y: [-0.5, 1.2], collide: 2}   # the slot's lower cheek
      - {kind: poly, points: [[7.3, 0.27], [10.1, 0.27], [10.1, 0.67], [7.3, 0.67]], y: [-0.5, 1.2], collide: 2}   # and upper
      - {kind: rod, from: [6.5358, -0.5, -0.9185], to: [6.5358, 1.2, -0.9185], radius: 0.2, color: "#8f8a80"}   # B's pin
  - id: pawl_b
    shape: part
    pos: [6.5358, 0, -0.9185]
    mount: bar_d
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [6.5358, 0, -0.9185], to: [4.6462, 0, 0.9876], radius: 0.15, capsule: true, collide: 2}
  - id: rod_c
    shape: part
    pos: [8.5, 0, 0]
    friction: 0.1
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [8.5, -0.6, 0], to: [8.5, 0.5, 0], radius: 0.25, capsule: true, collide: 1}   # the pin in D's slot
      - {kind: rod, from: [8.5, -0.9, 0.4], to: [8.5, -0.9, -9.530000000000001], radius: 0.3}   # the rod
      - {kind: rod, from: [8.5, -0.9, 0], to: [8.5, -0.6, 0], radius: 0.3}
      - {kind: poly, points: [[6.1, -9.73], [10.9, -9.73], [10.9, -9.33], [6.1, -9.33]], y: [-1.2, -0.3], collide: 2}   # the yoke's upper cheek
      - {kind: poly, points: [[6.1, -10.67], [10.9, -10.67], [10.9, -10.27], [6.1, -10.27]], y: [-1.2, -0.3], collide: 2}   # and lower
      - {kind: poly, points: [[5.7, -10.67], [6.1, -10.67], [6.1, -9.33], [5.7, -9.33]], y: [-1.2, -0.3]}
      - {kind: poly, points: [[10.9, -10.67], [11.3, -10.67], [11.3, -9.33], [10.9, -9.33]], y: [-1.2, -0.3]}
  - id: crank
    shape: part
    pos: [8.5, 0, -10.0]
    color: "#a39d90"
    pieces:
      - {kind: disc, center: [8.5, -10.0], radius: 2.6, y: [-0.2, 0.8]}   # the crank disc, behind the yoke
      - {kind: rod, from: [10.1, -1.3, -10.0], to: [10.1, -0.2, -10.0], radius: 0.25, capsule: true, collide: 1}   # its pin, in the yoke
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -0.8, 0], to: [0, 2.2, 0], radius: 0.6, color: "#8f8a80"}
      - {kind: poly, points: [[-1, -13], [1, -13], [0.8, 0], [-0.8, 0]], y: [1.4, 2.2]}
      - {kind: poly, points: [[7.8, -6.0], [9.2, -6.0], [9.2, -5.0], [7.8, -5.0]], y: [-1.5, -1.25]}   # C's guide
      - {kind: poly, points: [[8.0, -13], [9.0, -13], [9.0, -10.0], [8.0, -10.0]], y: [0.8, 1.6]}   # the crank's standard
      - {kind: rod, from: [8.5, 0.8, -10.0], to: [8.5, -0.2, -10.0], radius: 0.35, color: "#8f8a80"}
      - {kind: poly, points: [[-6, -14], [12.0, -14], [12.0, -13], [-6, -13]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_k, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.0005}   # the one driven joint
  - {id: j_c, type: slide, body: rod_c, axis: [0, 0, 1], damping: 0.05}
  - {id: j_d, type: hinge, body: bar_d, axis: [0, -1, 0], damping: 0.0005}   # + : up at its end, against the clock
  - {id: j_bp, type: hinge, body: pawl_b, axis: [0, -1, 0], damping: 0.0002, range: [-0.6, 0.3], stiffness: 0.01, springref: 0.25}   # sprung onto the teeth
  - {id: j_a, type: hinge, body: wheel_a, axis: [0, -1, 0], damping: 0.002, frictionloss: 0.01}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_k, kind: velocity, rpm: 30.0, kv: 2, max_torque: 20}
checks:
  - {type: advance, joint: j_a, beat: j_c, expect: 0.1309, tol: 0.003, settle_s: 2.9, window_s: 8.2}   # a tooth a double stroke: half a pitch a beat
  - {type: clicks, joint: j_bp, lift: 0.08, min: 4, settle_s: 1.0, window_s: 10.0}   # the pawl rides over a tooth every down-stroke
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [4.25, 0, -4], position: [4.25, -48, 0], fov: 34}
display:
  output: j_a
  labels: {j_k: "Crank (driver)", j_c: "Rod C", j_d: "Vibrating bar D", j_bp: "Pawl B", j_a: "Ratchet-wheel A"}
  proof: {label: "Slot out of contact", sub: "the rod slides but D stays: A never moves"}

