# No. 223 (Brown 1868): "An arrangement for obtaining variable circular motion. The sectors are arranged on different planes, and the relative velocity changes according to the
# respective diameters of the sectors."
#
# Model (cm; drawing plane x-z, the shafts along y, 10.8 apart): each shaft carries three toothed sectors (module 0.6), one in each of three planes. The pairs are cut from wheels of
# 12 and 24, 18 and 18, 24 and 12 teeth, and have 4, 9 and 4 teeth, so the driver's sectors fill its circle (120, 180, 60 degrees)
# and the follower's fill its circle too (60, 180, 120 degrees). The pairs come into gear in turn, so the follower turns 0.5, 1 and 2 times as fast as the
# driver through each turn, once a turn on the mean (kinematics). Where a slower pair follows, the faster driving sector leaves out its last tooth and the slower its first
# (or the follower's faster teeth would have to pass the slow driver's first tooth inside the mesh), so the follower (a heavy one, 0.6 kg) runs on free for a moment and is checked by the next pair (at the other changes the faster pair simply takes over).
# Each shaft has a counterweight behind its sectors, so it balances (gravity is on). Only the driver is driven (10 rpm). Generator: opencode-runs/batch11/gen223.py.
number: 223
slug: sectors-different-planes
name: Variable circular motion by sectors on different planes
brown: "An arrangement for obtaining variable circular motion. The sectors are arranged on different planes, and the relative velocity changes according to the respective diameters of the sectors."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 13.0
bodies:
  - id: driver
    shape: part
    pos: [0, 0, 0]
    density: 2700
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[1.6581, -2.5421], [2.5421, -1.6581], [3.0414, -2.7286], [2.7286, -3.0414]], y: [-2.2, -1.2], collide: 1}
      - {kind: poly, points: [[0.1649, -3.0306], [1.3725, -2.707], [1.2696, -3.8837], [0.8424, -3.9982]], y: [-2.2, -1.2], collide: 1}
      - {kind: poly, points: [[-1.3725, -2.707], [-0.1649, -3.0306], [-0.8424, -3.9982], [-1.2696, -3.8837]], y: [-2.2, -1.2], collide: 1}
      - {kind: poly, points: [[-3.545, -3.2522], [-2.5872, -4.0559], [-3.6102, -4.6465], [-3.949, -4.3622]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.4435, -1.8436], [-3.8184, -2.9264], [-4.9817, -3.1315], [-5.2028, -2.7485]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.8061, -0.2127], [-4.589, -1.4439], [-5.7523, -1.2388], [-5.8291, -0.8033]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-4.589, 1.4439], [-4.8061, 0.2127], [-5.8291, 0.8033], [-5.7523, 1.2388]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-3.8184, 2.9264], [-4.4435, 1.8436], [-5.2028, 2.7485], [-4.9817, 3.1315]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-2.5872, 4.0559], [-3.545, 3.2522], [-3.949, 4.3622], [-3.6102, 4.6465]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[-1.044, 4.6961], [-2.2189, 4.2685], [-2.2189, 5.4498], [-1.8033, 5.601]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[0.6251, 4.77], [-0.6251, 4.77], [-0.2211, 5.88], [0.2211, 5.88]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[2.2189, 4.2685], [1.044, 4.6961], [1.8033, 5.601], [2.2189, 5.4498]], y: [-0.5, 0.5], collide: 1}
      - {kind: poly, points: [[4.4955, 4.8318], [3.5036, 5.5929], [4.4998, 6.2276], [4.8507, 5.9583]], y: [1.2, 2.2], collide: 1}
      - {kind: poly, points: [[5.5929, 3.5036], [4.8318, 4.4955], [5.9583, 4.8507], [6.2276, 4.4998]], y: [1.2, 2.2], collide: 1}
      - {kind: poly, points: [[6.3091, 1.9367], [5.8307, 3.0918], [7.0108, 3.1433], [7.18, 2.7347]], y: [1.2, 2.2], collide: 1}
      - {kind: poly, points: [[0.0, 0.0], [-1.46, -2.5288], [-1.1382, -2.689], [-0.7991, -2.8085], [-0.4479, -2.8854], [-0.0899, -2.9186], [0.2694, -2.9075], [0.6247, -2.8524], [0.9705, -2.754], [1.3016, -2.6139], [1.6129, -2.4341], [1.8998, -2.2175], [2.1579, -1.9672], [2.3833, -1.6871], [2.5726, -1.3814], [2.7228, -1.0548], [2.8318, -0.7122], [2.8979, -0.3588], [2.92, 0.0]], y: [-2.2, -1.2], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[0.0, 0.0], [2.36, 4.0876], [1.8501, 4.3423], [1.3132, 4.5336], [0.7571, 4.6589], [0.1901, 4.7162], [-0.3798, 4.7047], [-0.9441, 4.6246], [-1.4947, 4.4771], [-2.0234, 4.2643], [-2.5227, 3.9893], [-2.9851, 3.6561], [-3.4041, 3.2697], [-3.7734, 2.8355], [-4.0876, 2.36], [-4.3423, 1.8501], [-4.5336, 1.3132], [-4.6589, 0.7571], [-4.7162, 0.1901], [-4.7047, -0.3798], [-4.6246, -0.9441], [-4.4771, -1.4947], [-4.2643, -2.0234], [-3.9893, -2.5227], [-3.6561, -2.9851], [-3.2697, -3.4041], [-2.8355, -3.7734], [-2.36, -4.0876]], y: [-0.5, 0.5], collide: 0, color: "#c9b88f"}
      - {kind: poly, points: [[0.0, 0.0], [6.52, 0.0], [6.4642, 0.851], [6.2978, 1.6875], [6.0237, 2.4951], [5.6465, 3.26], [5.1727, 3.9691], [4.6103, 4.6103], [3.9691, 5.1727], [3.26, 5.6465]], y: [1.2, 2.2], collide: 0, color: "#b8ad97"}
      - {kind: disc, center: [-0.8001, -3.5334], radius: 2.2, y: [2.6, 4.2], collide: 0, color: "#a39d90"}   # the counterweight, behind
      - {kind: disc, center: [0.0, 0.0], radius: 1.0, y: [-2.4, 2.4], collide: 0, color: "#8f8a80"}   # the hub
      - {kind: disc, center: [0.0, 0.0], radius: 0.5, y: [2.4, 5.0], collide: 0, color: "#8f8a80"}   # the shaft
  - id: follower
    shape: part
    pos: [10.8, 0, 0]
    mass: 0.6
    friction: 0.1
    color: "#c2b694"
    pieces:
      - {kind: poly, points: [[4.23, 0.6251], [4.23, -0.6251], [3.12, -0.2211], [3.12, 0.2211]], y: [-2.2, -1.2], collide: 2}
      - {kind: poly, points: [[4.2921, -1.0966], [4.6157, -2.3043], [3.4389, -2.2013], [3.3245, -1.7741]], y: [-2.2, -1.2], collide: 2}
      - {kind: poly, points: [[4.7976, -2.7436], [5.4228, -3.8264], [4.2595, -4.0315], [4.0384, -3.6485]], y: [-2.2, -1.2], collide: 2}
      - {kind: poly, points: [[5.7123, -4.2036], [6.5964, -5.0877], [5.5258, -5.5869], [5.2131, -5.2742]], y: [-2.2, -1.2], collide: 2}
      - {kind: poly, points: [[7.8736, -3.8184], [8.9564, -4.4435], [8.0515, -5.2028], [7.6685, -4.9817]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[9.3561, -4.589], [10.5873, -4.8061], [9.9967, -5.8291], [9.5612, -5.7523]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[11.0127, -4.8061], [12.2439, -4.589], [12.0388, -5.7523], [11.6033, -5.8291]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[12.6436, -4.4435], [13.7264, -3.8184], [13.9315, -4.9817], [13.5485, -5.2028]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[14.0522, -3.545], [14.8559, -2.5872], [15.4465, -3.6102], [15.1622, -3.949]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[15.0685, -2.2189], [15.4961, -1.044], [16.401, -1.8033], [16.2498, -2.2189]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[15.57, -0.6251], [15.57, 0.6251], [16.68, 0.2211], [16.68, -0.2211]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[15.4961, 1.044], [15.0685, 2.2189], [16.2498, 2.2189], [16.401, 1.8033]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[14.8559, 2.5872], [14.0522, 3.545], [15.1622, 3.949], [15.4465, 3.6102]], y: [-0.5, 0.5], collide: 2}
      - {kind: poly, points: [[12.8264, 2.2595], [11.7436, 2.8847], [12.6485, 3.644], [13.0315, 3.4228]], y: [1.2, 2.2], collide: 2}
      - {kind: poly, points: [[11.4251, 2.97], [10.1749, 2.97], [10.5789, 4.08], [11.0211, 4.08]], y: [1.2, 2.2], collide: 2}
      - {kind: poly, points: [[9.8564, 2.8847], [8.7736, 2.2595], [8.5685, 3.4228], [8.9515, 3.644]], y: [1.2, 2.2], collide: 2}
      - {kind: poly, points: [[8.5405, 2.0264], [7.9153, 0.9436], [7.156, 1.8485], [7.3772, 2.2315]], y: [1.2, 2.2], collide: 2}
      - {kind: poly, points: [[10.8, 0.0], [4.28, 0.0], [4.3358, -0.851], [4.5022, -1.6875], [4.7763, -2.4951], [5.1535, -3.26], [5.6273, -3.9691], [6.1897, -4.6103], [6.8309, -5.1727], [7.54, -5.6465]], y: [-2.2, -1.2], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[10.8, 0.0], [8.44, -4.0876], [8.9499, -4.3423], [9.4868, -4.5336], [10.0429, -4.6589], [10.6099, -4.7162], [11.1798, -4.7047], [11.7441, -4.6246], [12.2947, -4.4771], [12.8234, -4.2643], [13.3227, -3.9893], [13.7851, -3.6561], [14.2041, -3.2697], [14.5734, -2.8355], [14.8876, -2.36], [15.1423, -1.8501], [15.3336, -1.3132], [15.4589, -0.7571], [15.5162, -0.1901], [15.5047, 0.3798], [15.4246, 0.9441], [15.2771, 1.4947], [15.0643, 2.0234], [14.7893, 2.5227], [14.4561, 2.9851], [14.0697, 3.4041], [13.6355, 3.7734], [13.16, 4.0876]], y: [-0.5, 0.5], collide: 0, color: "#c9b88f"}
      - {kind: poly, points: [[10.8, 0.0], [12.26, 2.5288], [11.9382, 2.689], [11.5991, 2.8085], [11.2479, 2.8854], [10.8899, 2.9186], [10.5306, 2.9075], [10.1753, 2.8524], [9.8295, 2.754], [9.4984, 2.6139], [9.1871, 2.4341], [8.9002, 2.2175], [8.6421, 1.9672], [8.4167, 1.6871], [8.2274, 1.3814], [8.0772, 1.0548], [7.9682, 0.7122], [7.9021, 0.3588], [7.88, 0.0]], y: [1.2, 2.2], collide: 0, color: "#b8ad97"}
      - {kind: disc, center: [12.0672, 3.5343], radius: 2.2, y: [2.6, 4.2], collide: 0, color: "#a39d90"}   # the counterweight, behind
      - {kind: disc, center: [10.8, 0.0], radius: 1.0, y: [-2.4, 2.4], collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [10.8, 0.0], radius: 0.5, y: [2.4, 5.0], collide: 0, color: "#8f8a80"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    density: 7800
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [0.0, 0.0], radius: 1.1, y: [5.0, 5.6], collide: 0}
      - {kind: disc, center: [10.8, 0.0], radius: 1.1, y: [5.0, 5.6], collide: 0}
      - {kind: poly, points: [[-0.8, -0.8], [0.8, 0.8], [11.6, 0.8], [10.0, -0.8]], y: [5.0, 5.6], collide: 0}
joints:
  - {id: j_d, type: hinge, body: driver, axis: [0, -1, 0], damping: 0.01}   # the one driven joint; +: counter-clockwise
  - {id: j_f, type: hinge, body: follower, axis: [0, 1, 0], damping: 0.0002, frictionloss: 0.0}   # +: clockwise
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_d, kind: velocity, rpm: 10, kv: 20, max_torque: 40}
checks:
  - {type: ratio, out: j_f, in: j_d, expect: 1.0, tol: 0.03, settle_s: 0.5, window_s: 12}   # once a turn on the mean
  - {type: ratio_range, out: j_f, in: j_d, min: 0.300, max: 2.300, min_swing: 0.900, settle_s: 0.5, window_s: 12, slices: 36}   # 0.5, 1, 2 in turn (the slow slices dip below 0.5 after the follower's free run, while the slow pair catches it up)
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [5.3999999999999995, 0, -1.0], position: [13.399999999999999, -50.0, 16.0], fov: 34}
display:
  output: j_f
  labels: {j_d: "Driving sectors", j_f: "Driven sectors"}
  proof: {label: "Teeth out of contact", sub: "the driver turns alone"}

