# No. 417 (Brown 1868): "Continuous circular motion into a rectilinear reciprocating. The shaft, A, working in a fixed bearing, D, is bent on one end, and fitted to turn in a socket at the upper end of a rod, B, the lower end of which works in a socket in the slide, C. Dotted lines show the position of the rod, B, and slide, when the shaft has made half a revolution from the position shown in bold lines."
#
# Model (cm, Brown's side elevation, gravity off; a 3-D linkage, built in 3-D). The shaft A turns in the fixed bearing D (the one driven joint, by
# its crank, 20 rpm); its end is bent down 20 deg. The socket at the head of the rod B turns on the bent end (two pins on
# its axis make the turning pair). The rod's lower end passes through a ball socket in the slide C: the ball swivels every way in the slide
# (three hinges) and the rod slides through it (Brown's dotted rod is longer below the shaft than the bold one), and C runs in its guide. As the
# bent end goes round, the rod's head goes round a circle and the rod, square to the bent end, rocks from leaning right to leaning left, and C
# goes 6.55 cm to and fro (2 tan 20 deg x the shaft's height above the socket), one stroke each way a turn.
# Generator: opencode-runs/batch13/gen417.py.
number: 417
slug: bent-shaft-rod-and-slide
name: Bent shaft, rod and slide
brown: "Continuous circular motion into a rectilinear reciprocating. The shaft, A, working in a fixed bearing, D, is bent on one end, and fitted to turn in a socket at the upper end of a rod, B, the lower end of which works in a socket in the slide, C. Dotted lines show the position of the rod, B, and slide, when the shaft has made half a revolution from the position shown in bold lines."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  duration_s: 9
  floor: false
  gravity: 0
bodies:
  - id: shaft
    shape: part
    pos: [0, 0, 12.2]
    mass: 1.0
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-0.5, 0.0, 12.2], to: [7.6, 0.0, 12.2], radius: 0.6}   # the shaft A
      - {kind: rod, from: [-0.5, 0.0, 12.2], to: [-4.8226, 0.0, 10.6267], radius: 0.55}   # its bent end
      - {kind: rod, from: [-0.85, 0.0, 12.2], to: [0.1, 0.0, 12.2], radius: 0.9, color: "#6f6a60"}   # the collar at the bend
      - {kind: rod, from: [7.6, 0.0, 12.8], to: [7.6, 0.0, 8.0], radius: 0.35, color: "#6f6a60"}   # the crank
      - {kind: rod, from: [7.6, 0.0, 8.0], to: [9.2, 0.0, 8.0], radius: 0.3, color: "#5a564e"}   # its handle
  - id: slide
    shape: part
    pos: [-0.4168, 0.0, 3.2]
    mass: 0.3
    color: "#b8ad97"
    pieces:
      - {kind: poly, points: [[-2.1168, 2.5], [1.2832, 2.5], [1.2832, 4.1], [-2.1168, 4.1]], y: [-1.9, 1.9]}   # the slide C (its socket's ball is seen in it)
  - id: g1
    shape: part
    pos: [-0.4168, 0.0, 3.2]
    mount: slide
    mass: 0.02
    color: "#5a564e"
    pieces:
      - {kind: rod, from: [-0.4168, -2.0, 3.2], to: [-0.4168, -1.9, 3.2], radius: 0.75, color: "#5a564e"}   # the socket's ball, swivelling in the slide
  - id: g2
    shape: part
    pos: [-0.4168, 0.0, 3.2]
    mount: g1
    mass: 0.02
    color: "#5a564e"
    pieces:
      - {kind: rod, from: [-0.4168, -0.05, 3.2], to: [-0.4168, 0.05, 3.2], radius: 0.3}
  - id: g3
    shape: part
    pos: [-0.4168, 0.0, 3.2]
    mount: g2
    mass: 0.02
    color: "#5a564e"
    pieces:
      - {kind: rod, from: [-0.4168, -0.05, 3.2], to: [-0.4168, 0.05, 3.2], radius: 0.3}
  - id: rodb
    shape: part
    pos: [-0.4168, 0.0, 3.2]
    mount: g3
    mass: 0.15
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [-2.1445, 0.0, 11.6015], to: [-4.4937, 0.0, 10.7464], radius: 0.95}   # the socket on the shaft's bent end
      - {kind: rod, from: [-4.4937, 0.0, 10.7464], to: [-4.6816, 0.0, 10.678], radius: 1.1, color: "#6f6a60"}
      - {kind: rod, from: [-3.1139, 0.0, 10.6101], to: [0.5011, 0.0, 0.678], radius: 0.42}   # the rod B
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-12, -1.0], [10, -1.0], [10, 0], [-12, 0]], y: [-3, 3]}   # the bed
      - {kind: poly, points: [[-12, 0], [2.4, 0], [2.4, 2.5], [-12, 2.5]], y: [-1.9, -0.7], color: "#a39d90"}   # the slide's guide: two rails, the rod's end runs in the slot between
      - {kind: poly, points: [[-12, 0], [2.4, 0], [2.4, 2.5], [-12, 2.5]], y: [0.7, 1.9], color: "#a39d90"}
      - {kind: rod, from: [1.2, 0, 12.2], to: [6.2, 0, 12.2], radius: 1.3, color: "#a39d90"}   # the fixed bearing D
      - {kind: poly, points: [[2.7, 0], [4.9, 0], [4.4, 11.2], [6.0, 11.2], [6.0, 11.6], [1.6, 11.6], [1.6, 11.2], [3.2, 11.2]], y: [-1.0, 1.0], color: "#a39d90"}   # its standard
joints:
  - {id: j_A, type: hinge, body: shaft, axis: [1, 0, 0], damping: 0.01}   # the shaft A (driven); + : the bent end goes from below towards the viewer
  - {id: j_C, type: slide, body: slide, axis: [1, 0, 0], damping: 0.5}   # the slide C in its guide (+ : to the right)
  - {id: j_g1, type: hinge, body: g1, axis: [1, 0, 0], damping: 0.0005}   # the ball in the slide: three hinges
  - {id: j_g2, type: hinge, body: g2, axis: [0, 1, 0], damping: 0.0005}
  - {id: j_g3, type: hinge, body: g3, axis: [0.342, 0.0, -0.9397], damping: 0.0005}
  - {id: j_b, type: slide, body: rodb, axis: [0.342, 0.0, -0.9397], damping: 0.05}   # the rod sliding through the ball (+ : downwards)
pins:
  - {id: pin_s1, a: rodb, b: shaft, at: [-2.3794, 0.0, 11.516]}   # the socket on the bent end: two pins on its axis, a turning pair
  - {id: pin_s2, a: rodb, b: shaft, at: [-4.2588, 0.0, 10.8319]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_A, kind: velocity, rpm: 20, kv: 5, max_torque: 20}
checks:
  - {type: position, joint: j_C, min: -6.6715, max: 0.12, settle_s: 0.5, window_s: 8}   # C keeps within its stroke (-6.968..-0.417 cm, from -0.4168)
  - {type: amplitude, joint: j_C, min: 0.0318, max: 0.0337, sustain: 0.95, settle_s: 0.5, window_s: 8}   # and goes the whole stroke every turn (half-stroke, m)
camera: {target: [-1.5, 0, 6], position: [-1.5, -80, 7], fov: 17}
display:
  output: j_C
  labels: {j_A: "The shaft A (driver)", j_C: "The slide C", j_b: "The rod B through its lower socket"}
  proof: {label: "Socket loose", sub: "the shaft turns alone and C stands"}
