# No. 228 (Brown 1868): "Another kind of chain and pulley."
#
# Model (cm; the pulley's face in the x-z plane, gravity on): the plate's ladder chain: two side bars a link (pitch 2.4), joined at every joint by a round rung,
# each link hinged to the next on its rung. The pulley is an 10-sided polygon (corners at r 3.883): two rims carry the side bars, and between the rims each face
# has a wedge tooth that enters the opening between two rungs and pushes the rung ahead of it. The chain hangs over the pulley; its right-hand end carries a
# 0.4 kg weight running in vertical guides, its left end hangs free. The pulley is turned counter-clockwise (4 rpm, the only driven joint) and
# winds the weight up at 3.820 cm a radian on the mean. The plate's cheek is in front of the chain; here it is behind, so the teeth can be seen.
# Generator: opencode-runs/batch11/gen228.py.
number: 228
slug: another-chain-and-pulley
name: Another kind of chain and pulley
brown: "Another kind of chain and pulley."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  multiccd: true
  duration_s: 8
  floor: false
bodies:
  - id: pulley
    shape: part
    pos: [0, 0, 0]
    mass: 1.0
    friction: 0.2
    color: "#d9cfb6"
    pieces:
      - {kind: poly, points: [[3.5678, 0.0], [2.8864, 2.0971], [1.1025, 3.3932], [-1.1025, 3.3932], [-2.8864, 2.0971], [-3.5678, 0.0], [-2.8864, -2.0971], [-1.1025, -3.3932], [1.1025, -3.3932], [2.8864, -2.0971]], y: [0.55, 1.45], collide: 1}
      - {kind: poly, points: [[3.5678, 0.0], [2.8864, 2.0971], [1.1025, 3.3932], [-1.1025, 3.3932], [-2.8864, 2.0971], [-3.5678, 0.0], [-2.8864, -2.0971], [-1.1025, -3.3932], [1.1025, -3.3932], [2.8864, -2.0971]], y: [-1.45, -0.55], collide: 1}
      - {kind: poly, points: [[2.7314, 0.3092], [2.3914, 1.3553], [3.4852, 1.7107], [4.3789, 1.549], [4.453, 1.3207], [3.8251, 0.6645]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[2.028, 1.8556], [1.1381, 2.5021], [1.814, 3.4325], [2.6321, 3.827], [2.8263, 3.6859], [2.7039, 2.7859]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[0.55, 2.6932], [-0.55, 2.6932], [-0.55, 3.8432], [-0.12, 4.6432], [0.12, 4.6432], [0.55, 3.8432]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[-1.1381, 2.5021], [-2.028, 1.8556], [-2.7039, 2.7859], [-2.8263, 3.6859], [-2.6321, 3.827], [-1.814, 3.4325]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[-2.3914, 1.3553], [-2.7314, 0.3092], [-3.8251, 0.6645], [-4.453, 1.3207], [-4.3789, 1.549], [-3.4852, 1.7107]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[-2.7314, -0.3092], [-2.3914, -1.3553], [-3.4852, -1.7107], [-4.3789, -1.549], [-4.453, -1.3207], [-3.8251, -0.6645]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[-2.028, -1.8556], [-1.1381, -2.5021], [-1.814, -3.4325], [-2.6321, -3.827], [-2.8263, -3.6859], [-2.7039, -2.7859]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[-0.55, -2.6932], [0.55, -2.6932], [0.55, -3.8432], [0.12, -4.6432], [-0.12, -4.6432], [-0.55, -3.8432]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[1.1381, -2.5021], [2.028, -1.8556], [2.7039, -2.7859], [2.8263, -3.6859], [2.6321, -3.827], [1.814, -3.4325]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: poly, points: [[2.3914, -1.3553], [2.7314, -0.3092], [3.8251, -0.6645], [4.453, -1.3207], [4.3789, -1.549], [3.4852, -1.7107]], y: [-0.5, 0.5], collide: 1, color: "#b8ad97"}
      - {kind: disc, center: [0, 0], radius: 2.7932, inner: 0.6, y: [-0.55, 0.55], collide: 0}   # the body between the rims
      - {kind: disc, center: [0, 0], radius: 5.4833, inner: 0.6, y: [1.6, 2.0], collide: 0}   # the cheek
  - id: load
    shape: part
    pos: [3.8833, 0, -24.0]
    mass: 0.4
    friction: 0.1
    color: "#6b5a44"
    pieces:
      - {kind: rod, from: [3.8833, 0, -24.0], to: [3.8833, 0, -25.2], radius: 0.25, collide: 0}   # the hook
      - {kind: poly, points: [[2.2833, -25.2], [5.4833, -25.2], [5.4833, -28.2], [2.2833, -28.2]], y: [-1.2, 1.2], collide: 0}   # the weight
  - id: L0
    shape: part
    pos: [3.8833, 0, -24.0]
    mount: load
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -24.0], to: [3.8833, -1.0, -21.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -24.0], to: [3.8833, 1.0, -21.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -24.0], to: [3.8833, 1.0, -24.0], radius: 0.3, collide: 2, capsule: true}
  - id: L1
    shape: part
    pos: [3.8833, 0, -21.6]
    mount: L0
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -21.6], to: [3.8833, -1.0, -19.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -21.6], to: [3.8833, 1.0, -19.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -21.6], to: [3.8833, 1.0, -21.6], radius: 0.3, collide: 2, capsule: true}
  - id: L2
    shape: part
    pos: [3.8833, 0, -19.2]
    mount: L1
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -19.2], to: [3.8833, -1.0, -16.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -19.2], to: [3.8833, 1.0, -16.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -19.2], to: [3.8833, 1.0, -19.2], radius: 0.3, collide: 2, capsule: true}
  - id: L3
    shape: part
    pos: [3.8833, 0, -16.8]
    mount: L2
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -16.8], to: [3.8833, -1.0, -14.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -16.8], to: [3.8833, 1.0, -14.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -16.8], to: [3.8833, 1.0, -16.8], radius: 0.3, collide: 2, capsule: true}
  - id: L4
    shape: part
    pos: [3.8833, 0, -14.4]
    mount: L3
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -14.4], to: [3.8833, -1.0, -12.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -14.4], to: [3.8833, 1.0, -12.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -14.4], to: [3.8833, 1.0, -14.4], radius: 0.3, collide: 2, capsule: true}
  - id: L5
    shape: part
    pos: [3.8833, 0, -12.0]
    mount: L4
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -12.0], to: [3.8833, -1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -12.0], to: [3.8833, 1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -12.0], to: [3.8833, 1.0, -12.0], radius: 0.3, collide: 2, capsule: true}
  - id: L6
    shape: part
    pos: [3.8833, 0, -9.6]
    mount: L5
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -9.6], to: [3.8833, -1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -9.6], to: [3.8833, 1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -9.6], to: [3.8833, 1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
  - id: L7
    shape: part
    pos: [3.8833, 0, -7.2]
    mount: L6
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -7.2], to: [3.8833, -1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -7.2], to: [3.8833, 1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -7.2], to: [3.8833, 1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
  - id: L8
    shape: part
    pos: [3.8833, 0, -4.8]
    mount: L7
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -4.8], to: [3.8833, -1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -4.8], to: [3.8833, 1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -4.8], to: [3.8833, 1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
  - id: L9
    shape: part
    pos: [3.8833, 0, -2.4]
    mount: L8
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, -2.4], to: [3.8833, -1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, -2.4], to: [3.8833, 1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, -2.4], to: [3.8833, 1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
  - id: L10
    shape: part
    pos: [3.8833, 0, 0.0]
    mount: L9
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.8833, -1.0, 0.0], to: [3.1416, -1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, 1.0, 0.0], to: [3.1416, 1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.8833, -1.0, 0.0], to: [3.8833, 1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
  - id: L11
    shape: part
    pos: [3.1416, 0, 2.2825]
    mount: L10
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [3.1416, -1.0, 2.2825], to: [1.2, -1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.1416, 1.0, 2.2825], to: [1.2, 1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [3.1416, -1.0, 2.2825], to: [3.1416, 1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
  - id: L12
    shape: part
    pos: [1.2, 0, 3.6932]
    mount: L11
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [1.2, -1.0, 3.6932], to: [-1.2, -1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [1.2, 1.0, 3.6932], to: [-1.2, 1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [1.2, -1.0, 3.6932], to: [1.2, 1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
  - id: L13
    shape: part
    pos: [-1.2, 0, 3.6932]
    mount: L12
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-1.2, -1.0, 3.6932], to: [-3.1416, -1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-1.2, 1.0, 3.6932], to: [-3.1416, 1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-1.2, -1.0, 3.6932], to: [-1.2, 1.0, 3.6932], radius: 0.3, collide: 2, capsule: true}
  - id: L14
    shape: part
    pos: [-3.1416, 0, 2.2825]
    mount: L13
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-3.1416, -1.0, 2.2825], to: [-3.8833, -1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.1416, 1.0, 2.2825], to: [-3.8833, 1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.1416, -1.0, 2.2825], to: [-3.1416, 1.0, 2.2825], radius: 0.3, collide: 2, capsule: true}
  - id: L15
    shape: part
    pos: [-3.8833, 0, 0.0]
    mount: L14
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-3.8833, -1.0, 0.0], to: [-3.8833, -1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, 1.0, 0.0], to: [-3.8833, 1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, -1.0, 0.0], to: [-3.8833, 1.0, 0.0], radius: 0.3, collide: 2, capsule: true}
  - id: L16
    shape: part
    pos: [-3.8833, 0, -2.4]
    mount: L15
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-3.8833, -1.0, -2.4], to: [-3.8833, -1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, 1.0, -2.4], to: [-3.8833, 1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, -1.0, -2.4], to: [-3.8833, 1.0, -2.4], radius: 0.3, collide: 2, capsule: true}
  - id: L17
    shape: part
    pos: [-3.8833, 0, -4.8]
    mount: L16
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-3.8833, -1.0, -4.8], to: [-3.8833, -1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, 1.0, -4.8], to: [-3.8833, 1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, -1.0, -4.8], to: [-3.8833, 1.0, -4.8], radius: 0.3, collide: 2, capsule: true}
  - id: L18
    shape: part
    pos: [-3.8833, 0, -7.2]
    mount: L17
    mass: 0.02
    friction: 0.2
    color: "#8f8a80"
    pieces:
      - {kind: rod, from: [-3.8833, -1.0, -7.2], to: [-3.8833, -1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, 1.0, -7.2], to: [-3.8833, 1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, -1.0, -7.2], to: [-3.8833, 1.0, -7.2], radius: 0.3, collide: 2, capsule: true}
      - {kind: rod, from: [-3.8833, -1.0, -9.6], to: [-3.8833, 1.0, -9.6], radius: 0.3, collide: 2, capsule: true}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: rod, from: [0, -1.8, 0], to: [0, 3.4, 0], radius: 0.6, collide: 0, color: "#8f8a80"}   # the pulley's shaft
      - {kind: poly, points: [[-1.0, 0], [1.0, 0], [1.0, 8.0], [-1.0, 8.0]], y: [2.2, 3.4], collide: 0}   # its hanger
      - {kind: poly, points: [[-9, 8.0], [11, 8.0], [11, 9.2], [-9, 9.2]], y: [-1.5, 3.4], collide: 0, color: "#b9b09c"}   # the beam
      - {kind: rod, from: [1.8833, 2.0, -26.5], to: [1.8833, 2.0, -6], radius: 0.25, collide: 0, color: "#8f8a80"}   # the weight's guides
      - {kind: rod, from: [5.8833, 2.0, -26.5], to: [5.8833, 2.0, -6], radius: 0.25, collide: 0, color: "#8f8a80"}
joints:
  - {id: j_p, type: hinge, body: pulley, axis: [0, -1, 0], damping: 0.01}   # the one driven joint; +: counter-clockwise
  - {id: j_load, type: slide, body: load, axis: [0, 0, 1], damping: 0.5}   # +: up
  - {id: j_L0, type: hinge, body: L0, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L1, type: hinge, body: L1, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L2, type: hinge, body: L2, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L3, type: hinge, body: L3, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L4, type: hinge, body: L4, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L5, type: hinge, body: L5, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L6, type: hinge, body: L6, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L7, type: hinge, body: L7, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L8, type: hinge, body: L8, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L9, type: hinge, body: L9, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L10, type: hinge, body: L10, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L11, type: hinge, body: L11, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L12, type: hinge, body: L12, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L13, type: hinge, body: L13, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L14, type: hinge, body: L14, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L15, type: hinge, body: L15, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L16, type: hinge, body: L16, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L17, type: hinge, body: L17, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_L18, type: hinge, body: L18, axis: [0, -1, 0], damping: 0.0005}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_p, kind: velocity, rpm: 4, kv: 20, max_torque: 20}
checks:
  - {type: follow, out: j_load, in: j_p, expect: 0.03820, tol: 0.00153, min_r2: 0.995, settle_s: 1.0, window_s: 6.5}   # the chain's pitch x 10 per turn
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0.0, 0, -10.0], position: [40.0, -62.0, 16.0], fov: 34}
display:
  output: j_load
  labels: {j_p: "Chain pulley (driver)", j_load: "Weight"}

