# No. 276 (Brown 1868): "Continuous rotary motion of the cam gives a reciprocating rectilinear motion to the bar. The cam is of equal diameter in every direction measured across its center."
#
# Model (cm): a three-lobed cam on a shaft along y (the one driven joint, 30 rpm). Its profile lies 0.9 inside the rollers' path r(t) = 6 + 0.55 sin 3t (polar), so
# r(t) + r(t + pi) = 12: measured across its centre, the path is 12 cm in every direction. A bar slides along x in two guides; it carries a roller
# (radius 0.9) each side of the cam, their centres 12.04 apart (0.02 play each side). The cam holds both rollers at once, driving the bar both ways with no spring:
# x = 0.55 sin 3(phi) cm, three double strokes a turn. Only the cam's contact with the rollers moves the bar. Generator: opencode-runs/batch12/gen276.py.
number: 276
slug: cam-of-equal-diameter
name: A cam of equal diameter driving a bar
brown: "Continuous rotary motion of the cam gives a reciprocating rectilinear motion to the bar. The cam is of equal diameter in every direction measured across its center."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 6
  floor: false
bodies:
  - id: cam
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.2
    color: "#e4d9bf"
    pieces:
      - {kind: poly, points: [[5.1322, 0.2386], [5.1774, 0.4163], [5.2154, 0.595], [5.2455, 0.7744], [5.2675, 0.9542], [5.2808, 1.1341], [5.2851, 1.3134], [5.2802, 1.4919], [5.2658, 1.6689], [5.2417, 1.844], [5.2079, 2.0166], [5.1643, 2.1862], [5.1109, 2.3523], [5.0478, 2.5145], [4.9751, 2.6722], [4.893, 2.825], [4.8017, 2.9725], [4.7015, 3.1143], [4.5926, 3.25], [4.4754, 3.3793], [4.3503, 3.5019], [4.2178, 3.6175], [4.0782, 3.7258], [3.9321, 3.8268], [3.78, 3.9203], [3.6225, 4.0062], [3.4601, 4.0846], [3.2934, 4.1556], [3.1229, 4.2192], [2.9492, 4.2756], [2.7728, 4.3253], [2.5941, 4.3685], [2.4135, 4.4055], [2.2315, 4.4369], [2.0483, 4.4631], [1.8642, 4.4846], [1.6794, 4.502], [1.494, 4.5157], [1.3082, 4.5263], [1.122, 4.5343], [0.9355, 4.5401], [0.7488, 4.5442], [0.5618, 4.547], [0.3746, 4.5487], [0.1873, 4.5497], [0.0, 4.55], [-0.1873, 4.5497], [-0.3746, 4.5487], [-0.5618, 4.547], [-0.7488, 4.5442], [-0.9355, 4.5401], [-1.122, 4.5343], [-1.3082, 4.5263], [-1.494, 4.5157], [-1.6794, 4.502], [-1.8642, 4.4846], [-2.0483, 4.4631], [-2.2315, 4.4369], [-2.4135, 4.4055], [-2.5941, 4.3685], [-2.7728, 4.3253], [-2.9492, 4.2756], [-3.1229, 4.2192], [-3.2934, 4.1556], [-3.4601, 4.0846], [-3.6225, 4.0062], [-3.78, 3.9203], [-3.9321, 3.8268], [-4.0782, 3.7258], [-4.2178, 3.6175], [-4.3503, 3.5019], [-4.4754, 3.3793], [-4.5926, 3.25], [-4.7015, 3.1143], [-4.8017, 2.9725], [-4.893, 2.825], [-4.9751, 2.6722], [-5.0478, 2.5145], [-5.1109, 2.3523], [-5.1643, 2.1862], [-5.2079, 2.0166], [-5.2417, 1.844], [-5.2658, 1.6689], [-5.2802, 1.4919], [-5.2851, 1.3134], [-5.2808, 1.1341], [-5.2675, 0.9542], [-5.2455, 0.7744], [-5.2154, 0.595], [-5.1774, 0.4163], [-5.1322, 0.2386], [-5.0802, 0.0623], [-5.0221, -0.1126], [-4.9582, -0.2859], [-4.8893, -0.4577], [-4.8159, -0.6279], [-4.7385, -0.7966], [-4.6577, -0.964], [-4.574, -1.1302], [-4.4878, -1.2954], [-4.3996, -1.4598], [-4.3098, -1.6236], [-4.2187, -1.787], [-4.1266, -1.9499], [-4.0338, -2.1126], [-3.9404, -2.275], [-3.8465, -2.4371], [-3.752, -2.5988], [-3.6569, -2.76], [-3.561, -2.9206], [-3.4641, -3.0802], [-3.3658, -3.2388], [-3.2658, -3.3961], [-3.1637, -3.5517], [-3.0591, -3.7054], [-2.9517, -3.8568], [-2.841, -4.0055], [-2.7267, -4.151], [-2.6085, -4.2929], [-2.4862, -4.4308], [-2.3594, -4.5639], [-2.2282, -4.6919], [-2.0924, -4.8141], [-1.9521, -4.9299], [-1.8073, -5.0389], [-1.6583, -5.1403], [-1.5051, -5.2338], [-1.3481, -5.3187], [-1.1876, -5.3947], [-1.0239, -5.4614], [-0.8576, -5.5185], [-0.6889, -5.5655], [-0.5183, -5.6023], [-0.3463, -5.6288], [-0.1734, -5.6447], [-0.0, -5.65], [0.1734, -5.6447], [0.3463, -5.6288], [0.5183, -5.6023], [0.6889, -5.5655], [0.8576, -5.5185], [1.0239, -5.4614], [1.1876, -5.3947], [1.3481, -5.3187], [1.5051, -5.2338], [1.6583, -5.1403], [1.8073, -5.0389], [1.9521, -4.9299], [2.0924, -4.8141], [2.2282, -4.6919], [2.3594, -4.5639], [2.4862, -4.4308], [2.6085, -4.2929], [2.7267, -4.151], [2.841, -4.0055], [2.9517, -3.8568], [3.0591, -3.7054], [3.1637, -3.5517], [3.2658, -3.3961], [3.3658, -3.2388], [3.4641, -3.0802], [3.561, -2.9206], [3.6569, -2.76], [3.752, -2.5988], [3.8465, -2.4371], [3.9404, -2.275], [4.0338, -2.1126], [4.1266, -1.9499], [4.2187, -1.787], [4.3098, -1.6236], [4.3996, -1.4598], [4.4878, -1.2954], [4.574, -1.1302], [4.6577, -0.964], [4.7385, -0.7966], [4.8159, -0.6279], [4.8893, -0.4577], [4.9582, -0.2859], [5.0221, -0.1126], [5.0802, 0.0623]], y: [-0.5, 0.5], collide: 1}   # the cam
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.6, y: [-0.75, 0.75], collide: 0, color: "#cfc4aa"}   # its boss
      - {kind: rod, from: [0, -1.5, 0], to: [0, 3.5, 0], radius: 0.6, collide: 0, color: "#8f8a80"}   # its shaft
  - id: bar
    shape: part
    pos: [0, 0, 0]
    density: 7800
    color: "#d9cdb0"
    pieces:
      - {kind: poly, points: [[-17, -0.6], [9.02, -0.6], [9.02, 0.6], [-17, 0.6]], y: [1.3, 2.3], collide: 0}   # the bar
      - {kind: rod, from: [-6.02, 0.5, 0], to: [-6.02, 1.3, 0], radius: 0.35, collide: 0}   # the rollers' studs
      - {kind: rod, from: [6.02, 0.5, 0], to: [6.02, 1.3, 0], radius: 0.35, collide: 0}
  - id: roller_r
    shape: part
    pos: [6.02, 0, 0]
    mount: bar
    mass: 0.03
    friction: 0.2
    color: "#efe6d2"
    pieces:
      - {kind: disc, center: [6.02, 0], radius: 0.9, y: [-0.45, 0.45], collide: 2}   # the roller
      - {kind: disc, center: [6.02, 0], radius: 0.4, inner: 0.15, y: [-0.5, -0.45], collide: 0, color: "#8f8a80"}
      - {kind: poly, points: [[5.96, 0.45], [6.08, 0.45], [6.08, 0.8], [5.96, 0.8]], y: [-0.52, -0.45], collide: 0, color: "#6f675a"}
  - id: roller_l
    shape: part
    pos: [-6.02, 0, 0]
    mount: bar
    mass: 0.03
    friction: 0.2
    color: "#efe6d2"
    pieces:
      - {kind: disc, center: [-6.02, 0], radius: 0.9, y: [-0.45, 0.45], collide: 2}   # the roller
      - {kind: disc, center: [-6.02, 0], radius: 0.4, inner: 0.15, y: [-0.5, -0.45], collide: 0, color: "#8f8a80"}
      - {kind: poly, points: [[-6.08, 0.45], [-5.96, 0.45], [-5.96, 0.8], [-6.08, 0.8]], y: [-0.52, -0.45], collide: 0, color: "#6f675a"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#8f8a80"
    pieces:
      - {kind: poly, points: [[-15, -1.4], [-12, -1.4], [-12, -0.7], [-15, -0.7]], y: [1.1, 2.5], collide: 0}   # the bar's guides
      - {kind: poly, points: [[-15, 0.7], [-12, 0.7], [-12, 1.4], [-15, 1.4]], y: [1.1, 2.5], collide: 0}
      - {kind: poly, points: [[6.52, -1.4], [8.52, -1.4], [8.52, -0.7], [6.52, -0.7]], y: [1.1, 2.5], collide: 0}
      - {kind: poly, points: [[6.52, 0.7], [8.52, 0.7], [8.52, 1.4], [6.52, 1.4]], y: [1.1, 2.5], collide: 0}
      - {kind: rod, from: [0, 2.6, 0], to: [0, 3.4, 0], radius: 1.1, collide: 0}   # the cam's bearing
joints:
  - {id: j_cam, type: hinge, body: cam, axis: [0, 1, 0], damping: 0.001}   # the one driven joint
  - {id: j_bar, type: slide, body: bar, axis: [1, 0, 0], range: [-2, 2], damping: 0.5}   # the bar; + : to the right
  - {id: j_rr, type: hinge, body: roller_r, axis: [0, 1, 0], damping: 0.00001}   # the rollers on their studs
  - {id: j_rl, type: hinge, body: roller_l, axis: [0, 1, 0], damping: 0.00001}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_cam, kind: velocity, rpm: 30, kv: 2, max_torque: 5}
checks:
  - {type: amplitude, joint: j_bar, min: 0.00528, max: 0.006018, sustain: 0.95, settle_s: 0.5, window_s: 5.5}   # half the stroke: 0.55 cm each way, and the play
  - {type: position, joint: j_bar, min: -0.65, max: 0.65, settle_s: 0.5, window_s: 5.5}   # within the stroke
  - {type: penetration, max: 0.0008, settle_s: 0.5}
camera: {target: [-2.0, 0, -1.0], position: [0.0, -58.0, 4.0], fov: 34.0}
display:
  output: j_bar
  labels: {j_cam: "Cam (driver)", j_bar: "Bar"}
  proof: {label: "Cam of equal diameter", sub: "the cam holds both rollers; three strokes of the bar a turn"}

