# No. 83 (Brown 1868): "A nearly continuous rotary motion is given to the wheel, D, by two ratchet-toothed
# arcs, C, one operating on each side of the ratchet-wheel, D. These arcs (only one of which is shown) are fast
# on the same rock-shaft, B, and have their teeth set opposite ways. The rock-shaft is worked by giving a
# reciprocating rectilinear motion to the rod, A. The arcs should have springs applied to them, so that each may
# be capable of rising to allow its teeth to slide over those of the wheel in moving one way."
#
# Model (cm): D, a 24-tooth ratchet-wheel (tips r 5.0), turns clockwise on a fixed centre, held by its bearing
# friction. The rock-shaft B stands 10.0 cm to its left. Both arcs are fast on B, about circles round B: one in front
# of D, between B and D's centre (teeth at r 5.40 from B), the other behind D, reaching round it to D's far
# side (r 14.60). Rocking B moves both arcs the same way, up or down, which turns D one way at its near side and
# the other at its far side; so with their teeth set opposite ways the near arc drives D on the up stroke and the
# far arc on the down stroke. Each arc is carried on B by a slide with a spring pressing it onto D's teeth, so it
# can rise and let its teeth slip over D's on its idle stroke. B swings 9.7 deg, worked through a lever
# by the rod A, which slides 1.35 cm to and fro, driven by a crank and connecting-rod (the crank is the one
# driven joint, 30 turns a minute). The strokes of the arcs together come to 2.8 teeth, so D goes 2 teeth a
# crank turn. Generator: opencode-runs/batch8/gen083.py.
number: 83
slug: two-ratchet-arcs-rock-shaft
name: Nearly continuous rotation by two ratchet arcs on a rock-shaft
brown: "A nearly continuous rotary motion is given to the wheel, D, by two ratchet-toothed arcs, C, one operating on each side of the ratchet-wheel, D. These arcs (only one of which is shown) are fast on the same rock-shaft, B, and have their teeth set opposite ways. The rock-shaft Is worked by giving a reciprocating rectilinear motion to the rod, A. The arcs should have springs applied to them, so that each may be capable of rising to allow its teeth to slide over those of the wheel in moving one way."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: false
  duration_s: 13
  floor: false
bodies:
  - id: wheel_d
    shape: part
    pos: [0, 0, 0]
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 4.2, inner: 0.6, y: [-1.2, 1.2]}
      - {kind: poly, points: [[-4.1, 0.0], [-5.0, 0.0], [-3.9603, 1.0612]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-3.9603, 1.0612], [-4.8296, 1.2941], [-3.5507, 2.05]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-3.5507, 2.05], [-4.3301, 2.5], [-2.8991, 2.8991]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-2.8991, 2.8991], [-3.5355, 3.5355], [-2.05, 3.5507]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-2.05, 3.5507], [-2.5, 4.3301], [-1.0612, 3.9603]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-1.0612, 3.9603], [-1.2941, 4.8296], [0.0, 4.1]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[0.0, 4.1], [0.0, 5.0], [1.0612, 3.9603]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[1.0612, 3.9603], [1.2941, 4.8296], [2.05, 3.5507]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[2.05, 3.5507], [2.5, 4.3301], [2.8991, 2.8991]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[2.8991, 2.8991], [3.5355, 3.5355], [3.5507, 2.05]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[3.5507, 2.05], [4.3301, 2.5], [3.9603, 1.0612]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[3.9603, 1.0612], [4.8296, 1.2941], [4.1, -0.0]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[4.1, -0.0], [5.0, -0.0], [3.9603, -1.0612]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[3.9603, -1.0612], [4.8296, -1.2941], [3.5507, -2.05]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[3.5507, -2.05], [4.3301, -2.5], [2.8991, -2.8991]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[2.8991, -2.8991], [3.5355, -3.5355], [2.05, -3.5507]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[2.05, -3.5507], [2.5, -4.3301], [1.0612, -3.9603]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[1.0612, -3.9603], [1.2941, -4.8296], [0.0, -4.1]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[0.0, -4.1], [0.0, -5.0], [-1.0612, -3.9603]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-1.0612, -3.9603], [-1.2941, -4.8296], [-2.05, -3.5507]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-2.05, -3.5507], [-2.5, -4.3301], [-2.8991, -2.8991]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-2.8991, -2.8991], [-3.5355, -3.5355], [-3.5507, -2.05]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-3.5507, -2.05], [-4.3301, -2.5], [-3.9603, -1.0612]], y: [-1.2, 1.2], collide: 1}
      - {kind: poly, points: [[-3.9603, -1.0612], [-4.8296, -1.2941], [-4.1, -0.0]], y: [-1.2, 1.2], collide: 1}
  - id: rock_b
    shape: part
    pos: [-10.0, 0, 0]
    color: "#b8ad97"
    pieces:
      - {kind: disc, center: [-10.0, 0], radius: 0.9, inner: 0.4, y: [-2.6, 2.0]}   # the rock-shaft's boss
      - {kind: rod, from: [-10.0, -2.4, 0], to: [-10.0, -2.4, 8.0], radius: 0.35}   # its lever, up to the link
      - {kind: disc, center: [-10.0, 8.0], radius: 0.5, y: [-2.7, -2.1]}
      - {kind: rod, from: [-10.0, -1.4, 0], to: [-6.04, -1.4, 0], radius: 0.35}   # the near arc's arm, in front
      - {kind: rod, from: [-10.0, 1.6, 0], to: [-7.0, 1.6, 6.3], radius: 0.3}   # the far arc's arm, behind, over D
      - {kind: rod, from: [-7.0, 1.6, 6.3], to: [5.65, 1.6, 6.3], radius: 0.3}
      - {kind: rod, from: [5.65, 1.6, 6.3], to: [5.65, 1.6, -2.5], radius: 0.3}
  - id: arc_1
    shape: part
    pos: [-5.05, 0, 0]
    mount: rock_b
    mass: 0.005
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: band, center: [-10.0, 0], r: [4.35, 4.96], a: [-0.6735, 0.6646], y: [-1.1, -0.15]}   # the near arc
      - {kind: poly, points: [[-6.1309, -3.0875], [-4.8237, -2.5036], [-5.5438, -2.1553]], y: [-1.1, -0.15], collide: 2}
      - {kind: poly, points: [[-5.5438, -2.1553], [-4.3981, -1.2967], [-5.1775, -1.1163]], y: [-1.1, -0.15], collide: 2}
      - {kind: poly, points: [[-5.1775, -1.1163], [-4.2501, -0.0256], [-5.05, -0.0221]], y: [-1.1, -0.15], collide: 2}
      - {kind: poly, points: [[-5.05, -0.0221], [-4.3868, 1.2467], [-5.1678, 1.0733]], y: [-1.1, -0.15], collide: 2}
      - {kind: poly, points: [[-5.1678, 1.0733], [-4.8015, 2.4573], [-5.5248, 2.1154]], y: [-1.1, -0.15], collide: 2}
  - id: arc_2
    shape: part
    pos: [5.05, 0, 0]
    mount: rock_b
    mass: 0.005
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: band, center: [-10.0, 0], r: [15.04, 15.65], a: [-0.1798, 0.2656], y: [0.15, 1.1]}   # the far arc
      - {kind: poly, points: [[4.8497, -2.4471], [4.0604, -2.317], [5.0009, -1.2152]], y: [0.15, 1.1], collide: 2}
      - {kind: poly, points: [[5.0009, -1.2152], [4.2035, -1.1506], [5.05, 0.0248]], y: [0.15, 1.1], collide: 2}
      - {kind: poly, points: [[5.05, 0.0248], [4.25, 0.0235], [4.9968, 1.2647]], y: [0.15, 1.1], collide: 2}
      - {kind: poly, points: [[4.9968, 1.2647], [4.1996, 1.1975], [4.8416, 2.496]], y: [0.15, 1.1], collide: 2}
      - {kind: poly, points: [[4.8416, 2.496], [4.0527, 2.3634], [4.5855, 3.7104]], y: [0.15, 1.1], collide: 2}
  - id: link_a
    shape: part
    pos: [-10.0, 0, 8.0]
    mount: rock_b
    color: "#a39d90"
    pieces:
      - {kind: rod, from: [-10.0, -2.9, 8.0], to: [-7.0, -2.9, 8.0], radius: 0.25}
  - id: rod_a
    shape: part
    pos: [-7.0, 0, 8.0]
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-7.0, -3.3, 8.0], to: [9.5, -3.3, 8.0], radius: 0.3}
      - {kind: disc, center: [-7.0, 8.0], radius: 0.45, y: [-3.6, -2.7]}
  - id: crank
    shape: part
    pos: [14.9618, 0, 8.0]
    color: "#a39d90"
    pieces:
      - {kind: disc, center: [14.9618, 8.0], radius: 1.476, y: [-2.6, -2.0]}   # the crank, behind the connecting-rod
      - {kind: rod, from: [14.9618, -3.7, 8.676], to: [14.9618, -2.0, 8.676], radius: 0.2, color: "#8f8a80"}
  - id: conrod
    shape: part
    pos: [14.9618, 0, 8.676]
    mount: crank
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [14.9618, -3.7, 8.676], to: [9.0, -3.7, 8.0], radius: 0.22}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.6, 0], to: [0, 3.2, 0], radius: 0.6, color: "#8f8a80"}   # D's axle
      - {kind: poly, points: [[-1.2, -9], [1.2, -9], [0.9, 0], [-0.9, 0]], y: [2.4, 3.2]}   # its standard, behind
      - {kind: rod, from: [-10.0, -3.0, 0], to: [-10.0, 3.2, 0], radius: 0.4, color: "#8f8a80"}   # the rock-shaft's pin
      - {kind: poly, points: [[-11.0, -9], [-9.0, -9], [-9.3, 0], [-10.7, 0]], y: [2.4, 3.2]}
      - {kind: poly, points: [[5.0, 8.4], [6.5, 8.4], [6.5, 9.0], [5.0, 9.0]], y: [-3.8, -2.8]}   # A's guides
      - {kind: poly, points: [[5.0, 7.0], [6.5, 7.0], [6.5, 7.6], [5.0, 7.6]], y: [-3.8, -2.8]}
      - {kind: poly, points: [[5.4, -9], [6.1, -9], [6.1, 7.0], [5.4, 7.0]], y: [-3.8, -2.8]}
      - {kind: poly, points: [[14.4618, -9], [15.4618, -9], [15.4618, 8.0], [14.4618, 8.0]], y: [-1.8, -1.2]}   # the crank's standard
      - {kind: rod, from: [14.9618, -2.0, 8.0], to: [14.9618, -1.2, 8.0], radius: 0.35, color: "#8f8a80"}
      - {kind: poly, points: [[-14.0, -10], [17.9618, -10], [17.9618, -9], [-14.0, -9]], y: [-4.5, 3.5], color: "#b9b09c"}
joints:
  - {id: j_k, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.0005}   # the one driven joint
  - {id: j_cr, type: hinge, body: conrod, axis: [0, 1, 0], damping: 0.0002}
  - {id: j_ra, type: slide, body: rod_a, axis: [1, 0, 0], damping: 0.05}
  - {id: j_b, type: hinge, body: rock_b, axis: [0, -1, 0], damping: 0.0005}   # + : counter-clockwise (arcs up)
  - {id: j_la, type: hinge, body: link_a, axis: [0, 1, 0], damping: 0.0002}
  - {id: j_c1, type: slide, body: arc_1, axis: [1, 0, 0], damping: 0.05, range: [-1.2, 0], stiffness: 6.0, springref: 1.6}   # sprung onto D
  - {id: j_c2, type: slide, body: arc_2, axis: [-1, 0, 0], damping: 0.05, range: [-1.2, 0], stiffness: 6.0, springref: 1.6}
  - {id: j_d, type: hinge, body: wheel_d, axis: [0, 1, 0], damping: 0.002, frictionloss: 0.01}   # + : clockwise
pins:
  - {"id": "pin_l", "a": "link_a", "b": "rod_a", "at": [-7.0, -2.9, 8.0]}
  - {"id": "pin_r", "a": "conrod", "b": "rod_a", "at": [9.0, -3.7, 8.0]}
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.0, max_torque: 20}
checks:
  - {type: ratio, out: j_d, in: j_k, expect: 0.0833, tol: 0.0015, settle_s: 3, window_s: 10}   # 2 teeth a crank turn
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [2.4809, 0, 0], position: [2.4809, -62, 3], fov: 34}
display:
  output: j_d
  labels: {j_k: "Crank (driver)", j_ra: "Rod A", j_b: "Rock-shaft B", j_c1: "Near arc C", j_c2: "Far arc C", j_d: "Ratchet-wheel D"}
  proof: {label: "Arcs out of contact", sub: "B rocks but D never moves"}

