# No. 269 (Brown 1868): "Continued rectilinear movement of the frame with mutilated racks gives an alternate rotary motion to the spur-gear."
#
# Model (cm, plan view of the frame's face, gravity off): the frame is the one driven joint, drawn steadily to the right at 3 cm/s. Its top and bottom bars carry racks
# facing in, cut away but for groups of 4 teeth (module 0.8, No. 114's straight-flanked teeth), top and bottom in turn with a gap of 1.4 pitches between. A full
# spur-gear (16 teeth, pitch radius 6.4) turns free on a fixed shaft between them: a top group turns it forward 3 teeth (67.5 deg), it stands in the gap
# (a light drag on its shaft), and the next bottom group turns it back 3 teeth. Each group is set so its first tooth takes the gear where the last group left it.
# Generator: opencode-runs/batch12/gen269.py.
number: 269
slug: mutilated-racks-spur-gear
name: A frame with mutilated racks turning a spur-gear to and fro
brown: "Continued rectilinear movement of the frame with mutilated racks gives an alternate rotary motion to the spur-gear."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 22.2
  floor: false
  gravity: 0
bodies:
  - id: gear
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 0], radius: 5.62, inner: 0.6, y: [-0.8, 0.8]}
      - {kind: poly, points: [[-0.2646, 5.6571], [-1.9204, 5.3277], [-1.7002, 6.7582], [-1.0154, 6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-2.4094, 5.1252], [-3.813, 4.1873], [-4.157, 5.5931], [-3.5765, 5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-4.1873, 3.813], [-5.1252, 2.4094], [-5.981, 3.5765], [-5.5931, 4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.3277, 1.9204], [-5.6571, 0.2646], [-6.8944, 1.0154], [-6.7582, 1.7002]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.6571, -0.2646], [-5.3277, -1.9204], [-6.7582, -1.7002], [-6.8944, -1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.1252, -2.4094], [-4.1873, -3.813], [-5.5931, -4.157], [-5.981, -3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-3.813, -4.1873], [-2.4094, -5.1252], [-3.5765, -5.981], [-4.157, -5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.9204, -5.3277], [-0.2646, -5.6571], [-1.0154, -6.8944], [-1.7002, -6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[0.2646, -5.6571], [1.9204, -5.3277], [1.7002, -6.7582], [1.0154, -6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[2.4094, -5.1252], [3.813, -4.1873], [4.157, -5.5931], [3.5765, -5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[4.1873, -3.813], [5.1252, -2.4094], [5.981, -3.5765], [5.5931, -4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.3277, -1.9204], [5.6571, -0.2646], [6.8944, -1.0154], [6.7582, -1.7002]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.6571, 0.2646], [5.3277, 1.9204], [6.7582, 1.7002], [6.8944, 1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.1252, 2.4094], [4.1873, 3.813], [5.5931, 4.157], [5.981, 3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[3.813, 4.1873], [2.4094, 5.1252], [3.5765, 5.981], [4.157, 5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[1.9204, 5.3277], [0.2646, 5.6571], [1.0154, 6.8944], [1.7002, 6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-0.25, 0.6], [0.25, 0.6], [0.25, 5.2], [-0.25, 5.2]], y: [-0.9, -0.8], collide: 0, color: "#8f8a80"}   # a mark on its face
  - id: rackframe
    shape: part
    pos: [0, 0, 0]
    density: 2700
    friction: 0.1
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-65.0779, 7.2], [4.0, 7.2], [4.0, 8.4], [-65.0779, 8.4]], y: [-0.8, 0.8], collide: 2}   # the top bar
      - {kind: poly, points: [[-65.0779, -8.4], [4.0, -8.4], [4.0, -7.2], [-65.0779, -7.2]], y: [-0.8, 0.8], collide: 2}   # the bottom bar
      - {kind: poly, points: [[4.0, -8.4], [5.2, -8.4], [5.2, 8.4], [4.0, 8.4]], y: [-0.8, 0.8], collide: 0}   # the end
      - {kind: poly, points: [[5.2, -0.8], [19.2, -0.8], [19.2, 0.8], [5.2, 0.8]], y: [-0.6, 0.6], collide: 0, color: "#8f8a80"}   # its rod
      - {kind: poly, points: [[-0.819, 7.2], [0.819, 7.2], [0.3822, 6.0], [-0.3822, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-3.3322, 7.2], [-1.6943, 7.2], [-2.1311, 6.0], [-2.8955, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-5.8455, 7.2], [-4.2076, 7.2], [-4.6443, 6.0], [-5.4087, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-8.3588, 7.2], [-6.7209, 7.2], [-7.1576, 6.0], [-7.922, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-18.4119, -7.2], [-16.774, -7.2], [-17.2107, -6.0], [-17.9751, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-20.9252, -7.2], [-19.2872, -7.2], [-19.724, -6.0], [-20.4884, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-23.4384, -7.2], [-21.8005, -7.2], [-22.2373, -6.0], [-23.0017, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-25.9517, -7.2], [-24.3138, -7.2], [-24.7505, -6.0], [-25.5149, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-36.0048, 7.2], [-34.3669, 7.2], [-34.8036, 6.0], [-35.568, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-38.5181, 7.2], [-36.8801, 7.2], [-37.3169, 6.0], [-38.0813, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-41.0313, 7.2], [-39.3934, 7.2], [-39.8302, 6.0], [-40.5946, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-43.5446, 7.2], [-41.9067, 7.2], [-42.3435, 6.0], [-43.1079, 6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-53.5977, -7.2], [-51.9598, -7.2], [-52.3966, -6.0], [-53.161, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-56.111, -7.2], [-54.4731, -7.2], [-54.9098, -6.0], [-55.6742, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-58.6243, -7.2], [-56.9863, -7.2], [-57.4231, -6.0], [-58.1875, -6.0]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-61.1375, -7.2], [-59.4996, -7.2], [-59.9364, -6.0], [-60.7008, -6.0]], y: [-0.8, 0.8], collide: 2}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.2, 0], to: [0, 3.0, 0], radius: 0.6, color: "#8f8a80"}   # the gear's shaft
      - {kind: disc, center: [0, 0], radius: 2.0, y: [2.4, 3.0], collide: 0}   # its boss on the back plate
      - {kind: poly, points: [[-67.0779, -10.4], [22.0, -10.4], [22.0, 10.4], [-67.0779, 10.4]], y: [3.0, 3.6], collide: 0, color: "#b9b09c"}   # the back plate
      - {kind: poly, points: [[-67.0779, 8.45], [22.0, 8.45], [22.0, 9.2], [-67.0779, 9.2]], y: [-1.0, 3.0], collide: 0, color: "#a39a86"}   # the guides
      - {kind: poly, points: [[-67.0779, -9.2], [22.0, -9.2], [22.0, -8.45], [-67.0779, -8.45]], y: [-1.0, 3.0], collide: 0, color: "#a39a86"}
joints:
  - {id: j_f, type: slide, body: rackframe, axis: [1, 0, 0], damping: 1}   # the one driven joint; + : to the right
  - {id: j_g, type: hinge, body: gear, axis: [0, 1, 0], damping: 0.05}   # the spur-gear on its shaft; + : clockwise as seen
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_f, kind: velocity, speed: 3, kv: 2000.0, max_torque: 200.0}
checks:
  - {type: follow, out: j_g, in: j_f, expect: 15.625, tol: 0.625, min_r2: 0.99, settle_s: 0.168, window_s: 2.178}   # the top rack's teeth: the gear turns forward at 1/R
  - {type: follow, out: j_g, in: j_f, expect: -15.625, tol: 0.625, min_r2: 0.99, settle_s: 6.032, window_s: 2.178}   # the bottom rack's teeth: the gear turns back at 1/R
  - {type: follow, out: j_g, in: j_f, expect: 15.625, tol: 0.625, min_r2: 0.99, settle_s: 11.896, window_s: 2.178}   # the top rack's teeth: the gear turns forward at 1/R
  - {type: follow, out: j_g, in: j_f, expect: -15.625, tol: 0.625, min_r2: 0.99, settle_s: 17.760, window_s: 2.178}   # the bottom rack's teeth: the gear turns back at 1/R
  - {type: still, joint: j_g, max: 0.06, settle_s: 3.983, window_s: 0.411}   # between the groups the gear stands
  - {type: still, joint: j_g, max: 0.06, settle_s: 9.848, window_s: 0.411}   # between the groups the gear stands
  - {type: still, joint: j_g, max: 0.06, settle_s: 15.712, window_s: 0.411}   # between the groups the gear stands
  - {type: position, joint: j_g, min: -0.825, max: 2.0031, settle_s: 0.0, window_s: 22.2}   # it goes forward 3 teeth and back 3: 67.5 deg each way
camera: {target: [0.0, 0, -3.5], position: [0.0, -105.0, -1.0], fov: 34.0}
display:
  output: j_g
  labels: {j_f: "The frame (driver)", j_g: "The spur-gear"}
  proof: {label: "Mutilated racks", sub: "the frame goes on; the gear turns forward, stands, and turns back"}

