# No. 181 (Brown 1868), Nos. 181 and 182: "Motion for working the valves of steam-engines ... In 181 the lower steam-valve and upper eduction-valve are open
#  ... consequently the piston will be ascending. In the ascent of the piston-rod the lower handle will be struck by the projecting tappet, and, being raised, will
#  become engaged by the catch ... at the same time, the upper handle being disengaged ..., the back weight will pull the handle up ... 182 represents the position
#  ... when the piston is at the top of the cylinder. In going down, the tappet of the piston-rod strikes the upper handle and throws the catches and handles to the
#  position shown in 181."
#
# Model (cm): the upper handle U turns on a shaft at (0, 6), the lower L on one at (0, -6); U's back-weight turns it up (+), L's turns it down (-), both as joint
# springs set past their rest stops (8.6 deg). The diagonal catch rocks on a pin at (-2, 0) between them, held over on one of its two stops
# (+/-8.6 deg) by a spring toggle: a plunger, sprung toward the catch, works a link to the catch's tail pin, so the catch is over-centre on either side.
# It carries two hooks, arcs of radius 5 about its own pin, and a tail-arm. Each handle has a finger whose round nose lies on a hook, its back-weight pressing it
# straight in toward the catch pin, so a held handle puts no turning force on the catch; and a pusher that trips the tail-arm. Catch on its - stop: U is held down
# by the upper hook and L is at rest (No. 181). Near the top the plug-rod's tappet A throws L up: L's finger rises past the lower hook and its pusher presses the
# tail-arm down, rocking the catch over its dead centre; the toggle carries it to its + stop, the upper hook slides from under U's finger and U swings up to rest,
# and the lower hook comes under L's finger, so when the rod turns back L is held up (No. 182). Near the bottom tappet B throws U down and its pusher rocks the
# catch back. The plug-rod is worked by a crank (the one driven joint, 20 rpm) standing for the engine; the valves are not drawn. No. 181 starts in the
# state of No. 181. Generator: opencode-runs/batch11/gen181.py.
number: 181
slug: hand-gear-diagonal-catch
name: Hand-gear with a diagonal catch
brown: "181 and 182. Motion for working the valves of steam-engines: the upper handle is shown engaged and the lower disengaged ..."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 9.5
  floor: false
bodies:
  - id: handle_u
    shape: part
    pos: [0.0, 0, 6.0]
    density: 2700
    friction: 0.1
    color: "#e8dec6"
    pieces:
      - {kind: disc, center: [-2.0, 5.32], radius: 0.3, y: [-0.6, 0.6], collide: 1}   # the finger's nose
      - {kind: rod, from: [0.0, 0, 6.0], to: [-2.0, 0, 5.32], radius: 0.25, collide: 0}   # the finger
      - {kind: disc, center: [-3.8156, -0.9504], radius: 0.3, y: [-0.6, 0.6], collide: 1}   # the pusher's nose
      - {kind: rod, from: [0.0, -0.3, 6.0], to: [-3.8156, -0.3, -0.9504], radius: 0.25, collide: 0}   # the pusher
      - {kind: poly, points: [[1.0, 5.6], [8.6, 5.6], [8.6, 6.4], [1.0, 6.4]], y: [-0.6, 0.6], collide: 1}   # the tappet arm
      - {kind: disc, center: [0.0, 6.0], radius: 1.0, y: [-1.2, 1.2], collide: 0}   # the boss on its shaft
      - {kind: rod, from: [0.0, -1.0, 6.0], to: [-9.0, -1.0, 8.5], radius: 0.3, collide: 0}   # the handle
      - {kind: disc, center: [-9.0, 8.5], radius: 0.6, y: [-1.4, -0.6], collide: 0}
  - id: handle_l
    shape: part
    pos: [0.0, 0, -6.0]
    density: 2700
    friction: 0.1
    color: "#d9ccae"
    pieces:
      - {kind: disc, center: [-1.8759, -5.0288], radius: 0.3, y: [-0.6, 0.6], collide: 1}   # the finger's nose
      - {kind: rod, from: [0.0, 0, -6.0], to: [-1.8759, 0, -5.0288], radius: 0.25, collide: 0}   # the finger
      - {kind: disc, center: [-2.7341, 1.4426], radius: 0.3, y: [-0.6, 0.6], collide: 1}   # the pusher's nose
      - {kind: rod, from: [0.0, -0.3, -6.0], to: [-2.7341, -0.3, 1.4426], radius: 0.25, collide: 0}   # the pusher
      - {kind: poly, points: [[0.929, -6.5449], [8.4437, -7.6807], [8.5632, -6.8897], [1.0485, -5.7539]], y: [-0.6, 0.6], collide: 1}   # the tappet arm
      - {kind: disc, center: [0.0, -6.0], radius: 1.0, y: [-1.2, 1.2], collide: 0}   # the boss on its shaft
      - {kind: rod, from: [0.0, -1.0, -6.0], to: [-9.2725, -1.0, -7.127], radius: 0.3, collide: 0}   # the handle
      - {kind: disc, center: [-9.2725, -7.127], radius: 0.6, y: [-1.4, -0.6], collide: 0}
  - id: catch
    shape: part
    pos: [-2.0, 0, 0.0]
    density: 2700
    friction: 0.05
    color: "#cbbd9c"
    pieces:
      - {kind: band, center: [-2.0, 0.0], r: [4.2, 5.0], a: [1.3708, 1.7208], slices: 16, y: [-0.6, 0.6], collide: 2}   # the upper hook
      - {kind: band, center: [-2.0, 0.0], r: [4.2, 5.0], a: [-2.0208, -1.6708], slices: 16, y: [-0.6, 0.6], collide: 2}   # the lower hook
      - {kind: rod, from: [-2.0, 0.9, 0.0], to: [-1.0861, 0.9, 4.5083], radius: 0.25, collide: 0}
      - {kind: rod, from: [-2.0, 0.9, 0.0], to: [-2.6874, 0.9, 4.5483], radius: 0.25, collide: 0}
      - {kind: rod, from: [-2.0, 0.9, 0.0], to: [-4.0008, 0.9, -4.1421], radius: 0.25, collide: 0}
      - {kind: rod, from: [-2.0, 0.9, 0.0], to: [-2.4592, 0.9, -4.577], radius: 0.25, collide: 0}
      - {kind: poly, points: [[-2.8358, -0.1771], [-6.1977, 0.331], [-6.108, 0.9243], [-2.7462, 0.4162]], y: [-0.6, 0.6], collide: 2}   # the tail-arm the pushers trip
      - {kind: disc, center: [-2.0, 0.0], radius: 0.9, y: [-1.0, 1.0], collide: 0}   # its boss
      - {kind: rod, from: [-2.0, 0.9, 0.0], to: [-0.0225, 0.9, -0.2989], radius: 0.3, collide: 0}   # the toggle arm
  - id: toglink
    shape: part
    mount: catch
    pos: [-0.0225, 0, -0.2989]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-0.0225, 1.4, -0.2989], to: [2.4596, 1.4, 0.0], radius: 0.25, collide: 0}
  - id: plunger
    shape: part
    pos: [2.4596, 0, 0]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [2.4596, 1.4, 0], to: [6.4596, 1.4, 0], radius: 0.35, collide: 0}
      - {kind: disc, center: [6.7596, 0], radius: 0.6, y: [1.0, 1.8], collide: 0}
  - id: crank
    shape: part
    pos: [10.0, 0, -28.1909]
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [10.0, -28.1909], radius: 7.2, y: [1.6, 2.4], collide: 0}
      - {kind: rod, from: [15.0488, 1.0, -31.4327], to: [15.0488, 2.4, -31.4327], radius: 0.4, collide: 0}
  - id: conrod
    shape: part
    mount: crank
    pos: [15.0488, 0, -31.4327]
    density: 2700
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [15.0488, 1.0, -31.4327], to: [10.0, 1.0, -18.3748], radius: 0.4, collide: 0}
  - id: rod
    shape: part
    pos: [10.0, 0, -18.3748]
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: poly, points: [[9.5, -19.3748], [10.5, -19.3748], [10.5, 11.007], [9.5, 11.007]], y: [-0.6, 0.6], collide: 0}   # the plug-rod
      - {kind: poly, points: [[7.4, -16.5748], [9.5, -16.5748], [9.5, -15.3748], [7.4, -15.3748]], y: [-0.6, 0.6], collide: 2}
      - {kind: poly, points: [[7.4, 7.007], [9.5, 7.007], [9.5, 8.207], [7.4, 8.207]], y: [-0.6, 0.6], collide: 2}
  - id: guides
    shape: frame
    color: "#8f8a80"
    rods:
      - {from: [11.0, 0, -38.1909], to: [11.0, 0, 25.007], radius: 0.4}   # the plug-rod's guide
      - {from: [0, 2.0, 6], to: [-14, 2.0, 6], radius: 0.6}   # the handle shafts' bracket
      - {from: [0, 2.0, -6], to: [-14, 2.0, -6], radius: 0.6}
      - {from: [-14, 2.0, 9], to: [-14, 2.0, -38.1909], radius: 0.6}
      - {from: [-2.0, 2.0, 0], to: [-14, 2.0, 0], radius: 0.6}   # the catch pin's bracket
      - {from: [1.9596, 2.0, -0.6], to: [7.4596, 2.0, -0.6], radius: 0.25}   # the plunger's guide
joints:
  - {id: j_U, type: hinge, body: handle_u, axis: [0, -1, 0], damping: 0.01, stiffness: 0.4, springref: 0.6, range: [-0.21, 0.15]}   # 0 = the start pose; +: up (counter-clockwise); its back-weight (spring) turns it up to rest at +0.15
  - {id: j_L, type: hinge, body: handle_l, axis: [0, -1, 0], damping: 0.01, stiffness: 0.4, springref: -0.45, range: [0.0, 0.36]}   # +: up; its back-weight turns it down to rest at -0.15
  - {id: j_catch, type: hinge, body: catch, axis: [0, -1, 0], damping: 0.005, range: [0.0, 0.3]}   # 0 = start; its two stops either side of the dead centre
  - {id: j_tog, type: hinge, body: toglink, axis: [0, -1, 0], damping: 0.001}
  - {id: j_plunger, type: slide, body: plunger, axis: [1, 0, 0], damping: 0.5, stiffness: 600.0, springref: -5.0}   # the toggle spring, pressing the plunger toward the catch
  - {id: j_crank, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.001}   # the one driven joint, standing for the engine
  - {id: j_con, type: hinge, body: conrod, axis: [0, -1, 0], damping: 0.001}
  - {id: j_rod, type: slide, body: rod, axis: [0, 0, 1], damping: 0.05}
pins:
  - {id: p_tog, a: toglink, b: plunger, at: [2.4596, 0, 0.0]}
  - {id: p_rod, a: conrod, b: rod, at: [10.0, 0, -18.3748]}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_crank, kind: velocity, rpm: 20.0, kv: 2, max_torque: 12}
checks:
  - {type: position, joint: j_L, min: 0.12, max: 0.18, settle_s: 1.53, window_s: 0.45}   # after the top throw: L held up by the catch's lower hook
  - {type: position, joint: j_U, min: 0.12, max: 0.16, settle_s: 1.53, window_s: 0.45}   # and U at rest, up by its back-weight
  - {type: position, joint: j_catch, min: 0.28, max: 0.31, settle_s: 1.53, window_s: 0.45}   # the catch over on its +stop
  - {type: position, joint: j_U, min: -0.03, max: 0.03, settle_s: 3.03, window_s: 0.45}   # after the bottom throw: U held down by the catch's upper hook
  - {type: position, joint: j_L, min: -0.01, max: 0.03, settle_s: 3.03, window_s: 0.45}   # and L at rest, down by its back-weight
  - {type: position, joint: j_catch, min: -0.01, max: 0.02, settle_s: 3.03, window_s: 0.45}   # the catch over on its -stop
  - {type: position, joint: j_L, min: 0.12, max: 0.18, settle_s: 4.53, window_s: 0.45}   # after the top throw: L held up by the catch's lower hook
  - {type: position, joint: j_U, min: 0.12, max: 0.16, settle_s: 4.53, window_s: 0.45}   # and U at rest, up by its back-weight
  - {type: position, joint: j_catch, min: 0.28, max: 0.31, settle_s: 4.53, window_s: 0.45}   # the catch over on its +stop
  - {type: position, joint: j_U, min: -0.03, max: 0.03, settle_s: 6.03, window_s: 0.45}   # after the bottom throw: U held down by the catch's upper hook
  - {type: position, joint: j_L, min: -0.01, max: 0.03, settle_s: 6.03, window_s: 0.45}   # and L at rest, down by its back-weight
  - {type: position, joint: j_catch, min: -0.01, max: 0.02, settle_s: 6.03, window_s: 0.45}   # the catch over on its -stop
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [-1, 0, -11], position: [-1, -120, -10], fov: 34}
display:
  output: j_L
  labels: {j_crank: "Engine crank (driver)", j_rod: "Plug-rod", j_catch: "Catch", j_U: "Upper handle", j_L: "Lower handle"}
  proof: {label: "Tappets out of contact", sub: "the plug-rod runs, the handles stand"}

