# No. 136 (Brown 1868): "A cam-wheel--of which a side view is shown--has its rim formed into teeth, or made of any profile form desired. The rod to the right is made to press constantly against the teeth or edge of the rim. On turning the wheel, alternate rectilinear motion is communicated to the rod. The character of this motion may be varied by altering the shape of the teeth or profile of the edge of the rim of the wheel."
#
# Model (cm, gravity on): the wheel (the one driven joint, 10 turns a minute) turns on a horizontal shaft and has 6 saw-teeth, 1.6 cm high, on its face. The rod to the right, parallel to the shaft, is pressed
# against them by a spring (a joint spring: the plate's coil) and rides on them at 7 cm from the axis by real contact: it is pushed out the slope of each tooth
# (1.528 cm per radian of the wheel) and thrown back by the spring at the wall of the tooth. Generator: opencode-runs/batch10/gen136.py.
number: 136
slug: cam-wheel-toothed-face
name: A toothed cam-wheel working a spring-pressed rod
brown: "A cam-wheel--of which a side view is shown--has its rim formed into teeth, or made of any profile form desired. The rod to the right is made to press constantly against the teeth or edge of the rim. On turning the wheel, alternate rectilinear motion is communicated to the rod. The character of this motion may be varied by altering the shape of the teeth or profile of the edge of the rim of the wheel."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 14.0
  floor: false
bodies:
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    mass: 8.0
    friction: 0.05
    color: "#d9cfb6"
    pieces:
      - {kind: rod, from: [-13, 0, 0], to: [-1, 0, 0], radius: 1.5, color: "#8f8a80"}   # the shaft
      - {kind: loft, a: [[-2.6, 10.0, 0.0], [-2.6, 9.6593, 2.5882], [-2.6, 8.6603, 5.0], [-2.6, 7.0711, 7.0711], [-2.6, 5.0, 8.6603], [-2.6, 2.5882, 9.6593], [-2.6, 0.0, 10.0], [-2.6, -2.5882, 9.6593], [-2.6, -5.0, 8.6603], [-2.6, -7.0711, 7.0711], [-2.6, -8.6603, 5.0], [-2.6, -9.6593, 2.5882], [-2.6, -10.0, 0.0], [-2.6, -9.6593, -2.5882], [-2.6, -8.6603, -5.0], [-2.6, -7.0711, -7.0711], [-2.6, -5.0, -8.6603], [-2.6, -2.5882, -9.6593], [-2.6, -0.0, -10.0], [-2.6, 2.5882, -9.6593], [-2.6, 5.0, -8.6603], [-2.6, 7.0711, -7.0711], [-2.6, 8.6603, -5.0], [-2.6, 9.6593, -2.5882]], b: [[-0.6, 10.0, 0.0], [-0.6, 9.6593, 2.5882], [-0.6, 8.6603, 5.0], [-0.6, 7.0711, 7.0711], [-0.6, 5.0, 8.6603], [-0.6, 2.5882, 9.6593], [-0.6, 0.0, 10.0], [-0.6, -2.5882, 9.6593], [-0.6, -5.0, 8.6603], [-0.6, -7.0711, 7.0711], [-0.6, -8.6603, 5.0], [-0.6, -9.6593, 2.5882], [-0.6, -10.0, 0.0], [-0.6, -9.6593, -2.5882], [-0.6, -8.6603, -5.0], [-0.6, -7.0711, -7.0711], [-0.6, -5.0, -8.6603], [-0.6, -2.5882, -9.6593], [-0.6, -0.0, -10.0], [-0.6, 2.5882, -9.6593], [-0.6, 5.0, -8.6603], [-0.6, 7.0711, -7.0711], [-0.6, 8.6603, -5.0], [-0.6, 9.6593, -2.5882]], collide: 0}   # the wheel
      - {kind: loft, a: [[-5.0, 3.2, 0.0], [-5.0, 3.091, 0.8282], [-5.0, 2.7713, 1.6], [-5.0, 2.2627, 2.2627], [-5.0, 1.6, 2.7713], [-5.0, 0.8282, 3.091], [-5.0, 0.0, 3.2], [-5.0, -0.8282, 3.091], [-5.0, -1.6, 2.7713], [-5.0, -2.2627, 2.2627], [-5.0, -2.7713, 1.6], [-5.0, -3.091, 0.8282], [-5.0, -3.2, 0.0], [-5.0, -3.091, -0.8282], [-5.0, -2.7713, -1.6], [-5.0, -2.2627, -2.2627], [-5.0, -1.6, -2.7713], [-5.0, -0.8282, -3.091], [-5.0, -0.0, -3.2], [-5.0, 0.8282, -3.091], [-5.0, 1.6, -2.7713], [-5.0, 2.2627, -2.2627], [-5.0, 2.7713, -1.6], [-5.0, 3.091, -0.8282]], b: [[-2.6, 3.2, 0.0], [-2.6, 3.091, 0.8282], [-2.6, 2.7713, 1.6], [-2.6, 2.2627, 2.2627], [-2.6, 1.6, 2.7713], [-2.6, 0.8282, 3.091], [-2.6, 0.0, 3.2], [-2.6, -0.8282, 3.091], [-2.6, -1.6, 2.7713], [-2.6, -2.2627, 2.2627], [-2.6, -2.7713, 1.6], [-2.6, -3.091, 0.8282], [-2.6, -3.2, 0.0], [-2.6, -3.091, -0.8282], [-2.6, -2.7713, -1.6], [-2.6, -2.2627, -2.2627], [-2.6, -1.6, -2.7713], [-2.6, -0.8282, -3.091], [-2.6, -0.0, -3.2], [-2.6, 0.8282, -3.091], [-2.6, 1.6, -2.7713], [-2.6, 2.2627, -2.2627], [-2.6, 2.7713, -1.6], [-2.6, 3.091, -0.8282]], collide: 0, color: "#b8ad97"}   # its hub
      - {kind: loft, a: [[-0.6, 3.5, 0.0], [-0.6, 9.5, 0.0], [-0.6, 9.1763, 2.4588], [-0.6, 3.3807, 0.9059]], b: [[1.6, 3.5, 0.0], [1.6, 9.5, 0.0], [1.2, 9.1763, 2.4588], [1.2, 3.3807, 0.9059]], collide: 1}
      - {kind: loft, a: [[-0.6, 3.3807, 0.9059], [-0.6, 9.1763, 2.4588], [-0.6, 8.2272, 4.75], [-0.6, 3.0311, 1.75]], b: [[1.2, 3.3807, 0.9059], [1.2, 9.1763, 2.4588], [0.8, 8.2272, 4.75], [0.8, 3.0311, 1.75]], collide: 1}
      - {kind: loft, a: [[-0.6, 3.0311, 1.75], [-0.6, 8.2272, 4.75], [-0.6, 6.7175, 6.7175], [-0.6, 2.4749, 2.4749]], b: [[0.8, 3.0311, 1.75], [0.8, 8.2272, 4.75], [0.4, 6.7175, 6.7175], [0.4, 2.4749, 2.4749]], collide: 1}
      - {kind: loft, a: [[-0.6, 2.4749, 2.4749], [-0.6, 6.7175, 6.7175], [-0.6, 4.75, 8.2272], [-0.6, 1.75, 3.0311]], b: [[0.4, 2.4749, 2.4749], [0.4, 6.7175, 6.7175], [0.0, 4.75, 8.2272], [0.0, 1.75, 3.0311]], collide: 1}
      - {kind: loft, a: [[-0.6, 1.75, 3.0311], [-0.6, 4.75, 8.2272], [-0.6, 2.4588, 9.1763], [-0.6, 0.9059, 3.3807]], b: [[1.6, 1.75, 3.0311], [1.6, 4.75, 8.2272], [1.2, 2.4588, 9.1763], [1.2, 0.9059, 3.3807]], collide: 1}
      - {kind: loft, a: [[-0.6, 0.9059, 3.3807], [-0.6, 2.4588, 9.1763], [-0.6, 0.0, 9.5], [-0.6, 0.0, 3.5]], b: [[1.2, 0.9059, 3.3807], [1.2, 2.4588, 9.1763], [0.8, 0.0, 9.5], [0.8, 0.0, 3.5]], collide: 1}
      - {kind: loft, a: [[-0.6, 0.0, 3.5], [-0.6, 0.0, 9.5], [-0.6, -2.4588, 9.1763], [-0.6, -0.9059, 3.3807]], b: [[0.8, 0.0, 3.5], [0.8, 0.0, 9.5], [0.4, -2.4588, 9.1763], [0.4, -0.9059, 3.3807]], collide: 1}
      - {kind: loft, a: [[-0.6, -0.9059, 3.3807], [-0.6, -2.4588, 9.1763], [-0.6, -4.75, 8.2272], [-0.6, -1.75, 3.0311]], b: [[0.4, -0.9059, 3.3807], [0.4, -2.4588, 9.1763], [0.0, -4.75, 8.2272], [0.0, -1.75, 3.0311]], collide: 1}
      - {kind: loft, a: [[-0.6, -1.75, 3.0311], [-0.6, -4.75, 8.2272], [-0.6, -6.7175, 6.7175], [-0.6, -2.4749, 2.4749]], b: [[1.6, -1.75, 3.0311], [1.6, -4.75, 8.2272], [1.2, -6.7175, 6.7175], [1.2, -2.4749, 2.4749]], collide: 1}
      - {kind: loft, a: [[-0.6, -2.4749, 2.4749], [-0.6, -6.7175, 6.7175], [-0.6, -8.2272, 4.75], [-0.6, -3.0311, 1.75]], b: [[1.2, -2.4749, 2.4749], [1.2, -6.7175, 6.7175], [0.8, -8.2272, 4.75], [0.8, -3.0311, 1.75]], collide: 1}
      - {kind: loft, a: [[-0.6, -3.0311, 1.75], [-0.6, -8.2272, 4.75], [-0.6, -9.1763, 2.4588], [-0.6, -3.3807, 0.9059]], b: [[0.8, -3.0311, 1.75], [0.8, -8.2272, 4.75], [0.4, -9.1763, 2.4588], [0.4, -3.3807, 0.9059]], collide: 1}
      - {kind: loft, a: [[-0.6, -3.3807, 0.9059], [-0.6, -9.1763, 2.4588], [-0.6, -9.5, 0.0], [-0.6, -3.5, 0.0]], b: [[0.4, -3.3807, 0.9059], [0.4, -9.1763, 2.4588], [-0.0, -9.5, 0.0], [-0.0, -3.5, 0.0]], collide: 1}
      - {kind: loft, a: [[-0.6, -3.5, 0.0], [-0.6, -9.5, 0.0], [-0.6, -9.1763, -2.4588], [-0.6, -3.3807, -0.9059]], b: [[1.6, -3.5, 0.0], [1.6, -9.5, 0.0], [1.2, -9.1763, -2.4588], [1.2, -3.3807, -0.9059]], collide: 1}
      - {kind: loft, a: [[-0.6, -3.3807, -0.9059], [-0.6, -9.1763, -2.4588], [-0.6, -8.2272, -4.75], [-0.6, -3.0311, -1.75]], b: [[1.2, -3.3807, -0.9059], [1.2, -9.1763, -2.4588], [0.8, -8.2272, -4.75], [0.8, -3.0311, -1.75]], collide: 1}
      - {kind: loft, a: [[-0.6, -3.0311, -1.75], [-0.6, -8.2272, -4.75], [-0.6, -6.7175, -6.7175], [-0.6, -2.4749, -2.4749]], b: [[0.8, -3.0311, -1.75], [0.8, -8.2272, -4.75], [0.4, -6.7175, -6.7175], [0.4, -2.4749, -2.4749]], collide: 1}
      - {kind: loft, a: [[-0.6, -2.4749, -2.4749], [-0.6, -6.7175, -6.7175], [-0.6, -4.75, -8.2272], [-0.6, -1.75, -3.0311]], b: [[0.4, -2.4749, -2.4749], [0.4, -6.7175, -6.7175], [0.0, -4.75, -8.2272], [0.0, -1.75, -3.0311]], collide: 1}
      - {kind: loft, a: [[-0.6, -1.75, -3.0311], [-0.6, -4.75, -8.2272], [-0.6, -2.4588, -9.1763], [-0.6, -0.9059, -3.3807]], b: [[1.6, -1.75, -3.0311], [1.6, -4.75, -8.2272], [1.2, -2.4588, -9.1763], [1.2, -0.9059, -3.3807]], collide: 1}
      - {kind: loft, a: [[-0.6, -0.9059, -3.3807], [-0.6, -2.4588, -9.1763], [-0.6, -0.0, -9.5], [-0.6, -0.0, -3.5]], b: [[1.2, -0.9059, -3.3807], [1.2, -2.4588, -9.1763], [0.8, -0.0, -9.5], [0.8, -0.0, -3.5]], collide: 1}
      - {kind: loft, a: [[-0.6, -0.0, -3.5], [-0.6, -0.0, -9.5], [-0.6, 2.4588, -9.1763], [-0.6, 0.9059, -3.3807]], b: [[0.8, -0.0, -3.5], [0.8, -0.0, -9.5], [0.4, 2.4588, -9.1763], [0.4, 0.9059, -3.3807]], collide: 1}
      - {kind: loft, a: [[-0.6, 0.9059, -3.3807], [-0.6, 2.4588, -9.1763], [-0.6, 4.75, -8.2272], [-0.6, 1.75, -3.0311]], b: [[0.4, 0.9059, -3.3807], [0.4, 2.4588, -9.1763], [0.0, 4.75, -8.2272], [0.0, 1.75, -3.0311]], collide: 1}
      - {kind: loft, a: [[-0.6, 1.75, -3.0311], [-0.6, 4.75, -8.2272], [-0.6, 6.7175, -6.7175], [-0.6, 2.4749, -2.4749]], b: [[1.6, 1.75, -3.0311], [1.6, 4.75, -8.2272], [1.2, 6.7175, -6.7175], [1.2, 2.4749, -2.4749]], collide: 1}
      - {kind: loft, a: [[-0.6, 2.4749, -2.4749], [-0.6, 6.7175, -6.7175], [-0.6, 8.2272, -4.75], [-0.6, 3.0311, -1.75]], b: [[1.2, 2.4749, -2.4749], [1.2, 6.7175, -6.7175], [0.8, 8.2272, -4.75], [0.8, 3.0311, -1.75]], collide: 1}
      - {kind: loft, a: [[-0.6, 3.0311, -1.75], [-0.6, 8.2272, -4.75], [-0.6, 9.1763, -2.4588], [-0.6, 3.3807, -0.9059]], b: [[0.8, 3.0311, -1.75], [0.8, 8.2272, -4.75], [0.4, 9.1763, -2.4588], [0.4, 3.3807, -0.9059]], collide: 1}
      - {kind: loft, a: [[-0.6, 3.3807, -0.9059], [-0.6, 9.1763, -2.4588], [-0.6, 9.5, -0.0], [-0.6, 3.5, -0.0]], b: [[0.4, 3.3807, -0.9059], [0.4, 9.1763, -2.4588], [0.0, 9.5, -0.0], [0.0, 3.5, -0.0]], collide: 1}
  - id: rod
    shape: part
    pos: [1.85, 0, 7.0]
    mass: 0.1
    friction: 0.05
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [1.85, 0, 7.0], to: [2.85, 0, 7.0], radius: 0.25, collide: 2, capsule: true}   # the rod's end, on the teeth
      - {kind: rod, from: [2.85, 0, 7.0], to: [31.85, 0, 7.0], radius: 0.5}   # the rod
      - {kind: rod, from: [14.85, 0, 7.0], to: [16.35, 0, 7.0], radius: 1.1, color: "#b8ad97"}   # the collar the spring bears on
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-9.5, -12], [-7, -12], [-7, -1.7], [-9.5, -1.7]], y: [-1.4, 1.4]}   # the shaft's bearing
      - {kind: poly, points: [[23.85, -12], [25.25, -12], [25.25, 14], [23.85, 14]], y: [-1.6, 1.6]}   # the plate the rod slides through
      - {kind: poly, points: [[-15, -13], [26.85, -13], [26.85, -12], [-15, -12]], y: [-3, 3], color: "#b9b09c"}
joints:
  - {id: j_w, type: hinge, body: wheel, axis: [1, 0, 0], damping: 0.002}   # the one driven joint
  - {id: j_x, type: slide, body: rod, axis: [1, 0, 0], range: [-2.2, 0.6], stiffness: 40.0, springref: -3.6, damping: 3.0}   # the rod, pressed to the wheel by its spring; + : away from the wheel
contact: {solref: [0.001, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_w, kind: velocity, rpm: 10.0, kv: 3000.0, max_torque: 3000.0}
checks:
  - {type: follow, out: j_x, in: j_w, expect: 0.0153, tol: 0.0006, min_r2: 0.98, settle_s: 3.5, window_s: 0.6}   # on a ramp
  - {type: follow, out: j_x, in: j_w, expect: 0.0153, tol: 0.0006, min_r2: 0.98, settle_s: 5.5, window_s: 0.6}   # on a ramp
  - {type: follow, out: j_x, in: j_w, expect: 0.0153, tol: 0.0006, min_r2: 0.98, settle_s: 8.5, window_s: 0.6}   # on a ramp
  - {type: follow, out: j_x, in: j_w, expect: 0.0153, tol: 0.0006, min_r2: 0.98, settle_s: 11.5, window_s: 0.6}   # on a ramp
  - {type: position, joint: j_x, min: -1.68, max: 0.08, settle_s: 1.0, window_s: 12.5}   # the stroke, one tooth deep
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [9.0, 0, -4.0], position: [9.0, -76.0, -4.0], fov: 34}
display:
  output: j_x
  labels: {j_w: "Cam-wheel (driver)", j_x: "Rod"}
  proof: {label: "Wheel teeth removed", sub: "the spring holds the rod against the wheel's face; no motion"}

