# No. 385 (Brown 1868): "Contrivance employed in Russia for shutting doors. One pin is fitted to and turns in socket attached to door, and the other is similarly attached to frame. In opening the door, pins are brought together, and weight is raised. Weight closes door by depressing the joint of the toggle toward a straight line, and so widening the space between the pins."
#
# Model (cm, gravity on): a door 46 cm wide (its top 18 cm drawn, broken off below as Brown breaks off his figures; its full weight kept) on an upright hinge, shut against its stop (the joint's lower limit). Two pins stand up in sockets, one on
# the door's top 22 cm from the hinge line, the other on the frame 22 cm the other side, each turning in its socket (an upright joint); the toggle's two
# 25 cm links are pinned to their tops and to each other at the knee, from which the 3 kg weight hangs on a hook. A hand (the one driven joint, a push-rod
# swung about the hinge line, ±1.2 rad at 0.1 Hz) presses on the door's face and opens it 1.2 rad: the pins come together from 44 to 36.3 cm
# and the knee, with the weight, rises from 69.9 to 75.2 cm. The hand only pushes; when it draws back, the weight alone, settling, straightens the toggle,
# spreads the pins and swings the door shut onto its stop.
# Generator: opencode-runs/batch13/gen385.py.
number: 385
slug: russian-door-closer
name: Russian door-closing toggle
brown: "Contrivance employed in Russia for shutting doors. One pin is fitted to and turns in socket attached to door, and the other is similarly attached to frame. In opening the door, pins are brought together, and weight is raised. Weight closes door by depressing the joint of the toggle toward a straight line, and so widening the space between the pins."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 60, duration_s: 9, floor: false}
bodies:
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#b9a882"
    pieces:
      - {kind: poly, points: [[-4.0, 31.0], [-2.5, 32.6], [-1.0, 31.6], [-1.0, 54.0], [-4.0, 54.0]], y: [-1.5, 3.5], collide: 0}   # the doorpost
      - {kind: poly, points: [[-27, 51.0], [-1.0, 51.0], [-1.0, 54.0], [-27, 54.0]], y: [-1.5, 3.5], collide: 0, color: "#a8956b"}   # the frame's head, which the pin's socket is on
      - {kind: rod, from: [-0.4, 0, 32.0], to: [-0.4, 0, 50.0], radius: 0.5, collide: 0, color: "#8f8a80"}   # the hinge pin
      - {kind: rod, from: [-22.0, 0, 54.0], to: [-22.0, 0, 56.5], radius: 1.0, collide: 0, color: "#8f8a80"}   # the socket
  - id: door
    shape: part
    pos: [0, 0, 0]
    density: 1650
    friction: 0.2
    color: "#c9b48a"
    pieces:
      - {kind: poly, points: [[0.4, 32.0], [9, 33.4], [18, 31.6], [28, 33.1], [37, 31.7], [46.0, 32.9], [46.0, 50.0], [0.4, 50.0]], y: [-1.5, 1.5], collide: 2}   # the door
      - {kind: poly, points: [[5, 35.0], [41.0, 35.0], [41.0, 45.0], [5, 45.0]], y: [-1.8, -1.5], collide: 0, color: "#b39d71"}   # its upper panel
      - {kind: rod, from: [42.0, -1.5, 38.0], to: [42.0, -3.4, 38.0], radius: 0.8, collide: 0, color: "#8f8a80"}   # the handle
      - {kind: rod, from: [22.0, 0, 50.0], to: [22.0, 0, 52.5], radius: 1.0, collide: 0, color: "#8f8a80"}   # the socket on the door
  - id: hand
    shape: part
    pos: [0, 0, 0]
    density: 2000
    friction: 0.2
    color: "#5d5448"
    pieces:
      - {kind: rod, from: [0, -2.9, 40.0], to: [36.0, -2.9, 40.0], radius: 0.35, collide: 0}   # the hand's push-rod, swung about the hinge line
      - {kind: rod, from: [0, -2.9, 38.0], to: [0, -2.9, 42.0], radius: 0.6, collide: 0}
      - {kind: rod, from: [36.0, -2.1, 37.0], to: [36.0, -2.1, 43.0], radius: 0.5, capsule: true, collide: 1}   # its pad, on the door's face
  - id: pin_f
    shape: part
    pos: [-22.0, 0, 56.5]
    density: 7800
    color: "#d8cfbd"
    pieces:
      - {kind: rod, from: [-22.0, 0, 54.5], to: [-22.0, 0, 58.0], radius: 0.6, collide: 0}   # the frame's pin, turning in its socket
  - id: pin_d
    shape: part
    pos: [22.0, 0, 52.5]
    mount: door
    density: 7800
    color: "#d8cfbd"
    pieces:
      - {kind: rod, from: [22.0, 0, 50.5], to: [22.0, 0, 58.0], radius: 0.6, collide: 0}   # the door's pin
  - id: link_f
    shape: part
    pos: [-22.0, 0, 58.0]
    mount: pin_f
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [-22.0, -1.2, 58.0], to: [0, -1.2, 69.8743], radius: 0.7, collide: 0}   # the toggle's link from the frame's pin
      - {kind: rod, from: [-22.0, -2.0, 58.0], to: [-22.0, -0.4, 58.0], radius: 1.5, collide: 0}   # its eye on the pin
      - {kind: rod, from: [0, -2.0, 69.8743], to: [0, -0.4, 69.8743], radius: 1.5, collide: 0}   # the knee's eye
  - id: link_d
    shape: part
    pos: [0, 0, 69.8743]
    mount: link_f
    density: 7800
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [0, 1.2, 69.8743], to: [22.0, 1.2, 58.0], radius: 0.7, collide: 0}   # the link to the door's pin
      - {kind: rod, from: [0, 0.4, 69.8743], to: [0, 2.0, 69.8743], radius: 1.5, collide: 0}
      - {kind: rod, from: [22.0, 0.4, 58.0], to: [22.0, 2.0, 58.0], radius: 1.5, collide: 0}
  - id: weight
    shape: part
    pos: [0, 0, 69.8743]
    mount: link_f
    density: 7800
    mass: 3.0
    color: "#8a7f6c"
    pieces:
      - {kind: rod, from: [0, 0, 68.6743], to: [0, 0, 65.3743], radius: 0.25, collide: 0}   # the hook
      - {kind: rod, from: [0, 0, 65.3743], to: [0, 0, 64.5743], radius: 0.5, collide: 0}   # the pear-shaped weight, turned as a stack of rings
      - {kind: rod, from: [0, 0, 64.5743], to: [0, 0, 63.3743], radius: 0.9, collide: 0}
      - {kind: rod, from: [0, 0, 63.3743], to: [0, 0, 62.4743], radius: 1.4, collide: 0}
      - {kind: rod, from: [0, 0, 62.4743], to: [0, 0, 61.5743], radius: 2.0, collide: 0}
      - {kind: rod, from: [0, 0, 61.5743], to: [0, 0, 60.6743], radius: 2.6, collide: 0}
      - {kind: rod, from: [0, 0, 60.6743], to: [0, 0, 59.5743], radius: 3.0, collide: 0}
      - {kind: rod, from: [0, 0, 59.5743], to: [0, 0, 58.0743], radius: 3.3, collide: 0}
      - {kind: rod, from: [0, 0, 58.0743], to: [0, 0, 57.0743], radius: 3.2, collide: 0}
      - {kind: rod, from: [0, 0, 57.0743], to: [0, 0, 56.3743], radius: 2.7, collide: 0}
      - {kind: rod, from: [0, 0, 56.3743], to: [0, 0, 55.8743], radius: 1.8, collide: 0}
joints:
  - {id: j_h, type: hinge, body: hand, axis: [0, 0, 1], damping: 0.05}   # the hand: the one driven joint; + : opening
  - {id: j_d, type: hinge, body: door, axis: [0, 0, 1], range: [0, 1.6], damping: 0.3}   # the door; + : open; shut on its stop at 0
  - {id: j_pf, type: hinge, body: pin_f, axis: [0, 0, 1], damping: 0.01}   # the frame's pin, turning in its socket
  - {id: j_pd, type: hinge, body: pin_d, axis: [0, 0, 1], damping: 0.01}   # the door's pin, in its socket
  - {id: j_lf, type: hinge, body: link_f, axis: [0, 1, 0], damping: 0.01}   # the link on the frame's pin's eye
  - {id: j_k, type: hinge, body: link_d, axis: [0, 1, 0], damping: 0.01}   # the knee
  - {id: j_wt, type: hinge, body: weight, axis: [0, 1, 0], damping: 0.02}   # the weight swinging on its hook
pins:
  - {id: p_d, a: link_d, b: pin_d, at: [22.0, 0, 58.0]}   # the toggle's other eye on the door's pin
driver: {joint: j_h, kind: velocity, rpm: 0, swing: {amplitude: 1.2, hz: 0.1}, kv: 40.0, max_torque: 30}
checks:
  - {type: follow, out: j_d, in: j_h, expect: 1.0, tol: 0.05, min_r2: 0.99, settle_s: 0.3, window_s: 1.5}   # the hand pushes the door open (it rides on the pad)
  - {type: position, joint: j_d, min: 1.0, max: 1.15, settle_s: 2.35, window_s: 0.3}   # open about 1.1 rad (the hand lags its sweep under the load)
  - {type: position, joint: j_d, min: -0.005, max: 0.03, settle_s: 7.5, window_s: 1.5}   # the weight has shut it, the hand drawn back
camera: {target: [6.0, 0, 52.0], position: [12.0, -98.0, 72.0], fov: 34.0}
display:
  output: j_d
  labels: {j_h: "Hand (driver)", j_d: "Door, open", j_k: "Toggle's knee"}
  proof: {label: "Toggle unpinned from the door", sub: "the door stays open when the hand draws back"}

