# No. 179 (Brown 1868): "Reversing-gear for a single engine. On raising the eccentric-rod the valve-spindle is released. The engine can then be reversed by working the upright lever, after which the eccentric-rod is let down again. The eccentric in this case is loose upon the shaft and driven by a projection on the shaft acting upon a nearly semi-circular projection on the side of the eccentric, which permits the eccentric to turn half-way round on the shaft on reversing the valves."
#
# Reading of the figure (cm, no gravity; a plan): the shaft (the one driven joint) turns 2 turns forward and then 4 back (a hand schedule: a swing of ±2 turns in 12.5 s). The eccentric (throw 2 cm) is loose on it; a lug on the shaft rides in a recess in the eccentric that spans a half turn,
# between two stops (real contact). Going forward the lug pushes stop A and the eccentric goes with the shaft; when the shaft reverses it runs half a turn through the recess before the lug picks up stop B, so the eccentric then runs half a turn behind: the valve motion (a 14 cm eccentric rod to a valve spindle on a slide) is reversed.
# The upright lever, the hook that releases the spindle and the raising of the eccentric rod are not modelled. The eccentric is damped (a stand-in for the load of the rod and valve) so that it stops when the lug leaves it. Generator: opencode-runs/batch11/gen179.py.
number: 179
slug: reversing-gear-single-engine
name: Reversing-gear for a single engine
brown: "Reversing-gear for a single engine. On raising the eccentric-rod the valve-spindle is released. The engine can then be reversed by working the upright lever, after which the eccentric-rod is let down again. The eccentric in this case is loose upon the shaft and driven by a projection on the shaft acting upon a nearly semi-circular projection on the side of the eccentric, which permits the eccentric to turn half-way round on the shaft on reversing the valves."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 12.5
  floor: false
  gravity: 0
bodies:
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    mass: 0.4
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -2.4, 0], to: [0, 2.0, 0], radius: 1.2, collide: 0, color: "#8f8a80"}
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-2.5, -2.0], collide: 0, color: "#b9b09c"}
      - {kind: disc, center: [0, 0], radius: 3.3, y: [-0.9, -0.2], collide: 0, color: "#d9cfb6"}
      - {kind: rod, from: [2.6, -2.0, 0.0], to: [2.6, -0.2, 0.0], radius: 0.5, collide: 1, capsule: true, color: "#6b4f3a"}
  - id: ecc
    shape: part
    pos: [0, 0, 0]
    mass: 0.3
    color: "#cfc6b4"
    pieces:
      - {kind: disc, center: [0.0, 2.0], radius: 4.4, y: [-0.1, 0.8], collide: 0, color: "#d9cfb6"}
      - {kind: poly, points: [[2.1182, 0.3545], [3.048, 0.7226], [2.7168, 1.5594], [1.787, 1.1913]], y: [-1.8, -0.9], collide: 2, color: "#8f7f66"}
      - {kind: poly, points: [[-1.787, 1.1913], [-2.7168, 1.5594], [-3.048, 0.7226], [-2.1182, 0.3545]], y: [-1.8, -0.9], collide: 2, color: "#8f7f66"}
  - id: strap
    shape: part
    pos: [0.0, 0, 2.0]
    mount: ecc
    mass: 0.2
    color: "#a89a7e"
    pieces:
      - {kind: disc, center: [0.0, 2.0], radius: 5.4, inner: 4.45, y: [-0.1, 0.8], collide: 0, color: "#a89a7e"}
      - {kind: poly, points: [[0.0, 2.6], [14.0, 2.6], [14.0, 1.4], [0.0, 1.4]], y: [0.0, 0.7], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [14.0, -0.3, 2.0], to: [14.0, 1.0, 2.0], radius: 0.55, collide: 0, color: "#8f8a80"}
  - id: spindle
    shape: part
    pos: [14.0, 0, 2.0]
    mass: 0.2
    color: "#a89a7e"
    pieces:
      - {kind: poly, points: [[14.0, 2.5], [25.0, 2.5], [25.0, 1.5], [14.0, 1.5]], y: [0.0, 0.7], collide: 0, color: "#a89a7e"}
      - {kind: rod, from: [25.0, -0.3, 2.0], to: [25.0, 1.0, 2.0], radius: 0.7, collide: 0, color: "#8f8a80"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-3.0, -9.0], [30.0, -9.0], [30.0, -8.0], [-3.0, -8.0]], y: [-3, 3], collide: 0, color: "#b9b09c"}
      - {kind: poly, points: [[-2.2, -8.0], [2.2, -8.0], [1.4, -1.2], [-1.4, -1.2]], y: [1.0, 2.4], collide: 0}
      - {kind: poly, points: [[17.0, -8.0], [18.6, -8.0], [18.6, 1.1], [17.0, 1.1]], y: [-0.3, 1.0], collide: 0}
      - {kind: poly, points: [[21.0, -8.0], [22.6, -8.0], [22.6, 1.1], [21.0, 1.1]], y: [-0.3, 1.0], collide: 0}
joints:
  - {id: j_s, type: hinge, body: shaft, axis: [0, -1, 0], damping: 0.002}   # the one driven joint: the shaft, turned 2 turns forward and back; + : counter-clockwise in the view
  - {id: j_e, type: hinge, body: ecc, axis: [0, -1, 0], damping: 0.02}   # the loose eccentric, carried only by the lug
  - {id: j_strap, type: hinge, body: strap, axis: [0, -1, 0], damping: 0.002}
  - {id: j_vs, type: slide, body: spindle, axis: [1, 0, 0], damping: 0.05}   # the valve spindle
pins:
  - {"id": "pin_p", "a": "strap", "b": "spindle", "at": [14.0, 0, 2.0]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_s, kind: velocity, rpm: 0, swing: {amplitude: 12.5664, hz: 0.08}, kv: 2.0, max_torque: 20}
checks:
  - {type: follow, out: j_e, in: j_s, expect: 1.0, tol: 0.03, min_r2: 0.99, settle_s: 0.4, window_s: 2.0}
  - {type: follow, out: j_e, in: j_s, expect: 1.0, tol: 0.03, min_r2: 0.99, settle_s: 5.0, window_s: 2.6}
  - {type: follow, out: j_vs, in: j_s, expect: -0.02, tol: 0.0016, min_r2: 0.99, settle_s: 0.9941, window_s: 0.0957}
  - {type: follow, out: j_vs, in: j_s, expect: 0.02, tol: 0.0016, min_r2: 0.99, settle_s: 1.6256, window_s: 0.1254}
  - {type: follow, out: j_vs, in: j_s, expect: 0.02, tol: 0.0016, min_r2: 0.99, settle_s: 5.1601, window_s: 0.0957}
  - {type: follow, out: j_vs, in: j_s, expect: 0.02, tol: 0.0016, min_r2: 0.99, settle_s: 6.2086, window_s: 0.0829}
  - {type: follow, out: j_vs, in: j_s, expect: 0.02, tol: 0.0016, min_r2: 0.99, settle_s: 7.2441, window_s: 0.0957}
  - {type: position, joint: j_vs, min: -2.4678, max: 2.1745, settle_s: 0.0, window_s: 12.3}
  - {type: penetration, max: 0.003, settle_s: 0.5}
camera: {target: [11.0, 0, -3.0], position: [11.0, -52.0, -3.0], fov: 34}
display:
  output: j_vs
  labels: {j_s: "Shaft (driver)", j_e: "Loose eccentric", j_vs: "Valve spindle"}

