# No. 419 (Brown 1868): "Continuous circular motion converted into a rocking motion. Used in self-rocking cradles."
#
# Model (cm, Brown's front view, gravity on). Wheel A (the one driven joint, 20 rpm) turns on a standard fixed behind the cradle and by its crank
# (3.2) and the connecting-rod (15.5) works the pin (6.8 from the centre) of the larger wheel B (8.2), which therefore swings to and fro,
# 57.1 deg in all. The two flexible bands C and D are made fast on B's rim, lie over its top and run off it, C to the left and D to the
# right, each to the top of a post standing on the rocker E. E is free on the floor (it slides, lifts and turns: three joints) and rocks on its curved
# bottom (radius 27.9) by contact and friction alone; its weight sets it upright. As B swings one way it hauls in one band and pays out the other,
# and draws the post tops with it, so the cradle's rocker rocks to and fro, once each turn of A.
# Generator: opencode-runs/batch13/gen419.py.
number: 419
slug: self-rocking-cradle-bands
name: Continuous circular motion converted into a rocking motion
brown: "Continuous circular motion converted into a rocking motion. Used in self-rocking cradles. Wheel, A, revolves, and is connected to a wheel, B, of greater radius, which receives an oscillating motion, and wheel, B, is provided with two flexible bands, C, D, which connect each to a standard or post attached to the rocker, E, of the cradle."
units: cm
sim: {timestep: 0.0001, integrator: implicitfast, iterations: 60, duration_s: 10, floor: false}
bodies:
  - id: wa
    shape: part
    pos: [0, 0, 10]
    density: 2000
    color: "#d9cfb6"
    pieces:
      - {kind: disc, center: [0, 10], radius: 4.4, inner: 0, y: [-3.2, -2.4]}   # the wheel A
      - {kind: disc, center: [0, 10], radius: 0.9, y: [-3.4, -2.4], color: "#8f8a80"}
      - {kind: rod, from: [0, -2.8, 10], to: [0, 3.4, 10], radius: 0.4, color: "#8f8a80"}   # its shaft, to the standard
      - {kind: rod, from: [-2.9456, -4.6, 11.2503], to: [-2.9456, -2.8, 11.2503], radius: 0.35, color: "#6f6a60"}   # the crank-pin
  - id: rod
    shape: part
    pos: [-2.9456, 0, 11.2503]
    mount: wa
    density: 3000
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [-2.9456, -4.1, 11.2503], to: [5.1014, -4.1, 24.4978], radius: 0.55}   # the connecting-rod
      - {kind: disc, center: [-2.9456, 11.2503], radius: 1.0, inner: 0.35, y: [-4.4, -3.8]}
      - {kind: disc, center: [5.1014, 24.4978], radius: 1.0, inner: 0.35, y: [-4.4, -3.8]}
  - {id: wb, shape: assembly, pos: [-1, 0, 27.5], mass: 0.3, color: "#e2d8bf"}
  - id: wb_web
    shape: part
    pos: [-1, 0, 27.5]
    mount: wb
    fixed: true
    density: 2000
    color: "#e2d8bf"
    pieces:
      - {kind: disc, center: [-1, 27.5], radius: 7.8, y: [-3, -2]}   # the wheel B
      - {kind: disc, center: [-1, 27.5], radius: 1.1, y: [-3.2, -2], color: "#8f8a80"}
      - {kind: rod, from: [-1, -2.5, 27.5], to: [-1, 3.4, 27.5], radius: 0.45, color: "#8f8a80"}   # its shaft, to the standard
      - {kind: rod, from: [5.1014, -4.6, 24.4978], to: [5.1014, -2.5, 24.4978], radius: 0.35, color: "#6f6a60"}   # its pin
  - id: ex
    shape: part
    pos: [0, 0, 27.9]
    density: 1500
    color: "#c9b48a"
    pieces:
      - {kind: rod, from: [-0.2, 0, 4.0], to: [0.2, 0, 4.0], radius: 0.2}   # (inside the rocker)
  - id: ez
    shape: part
    pos: [0, 0, 27.9]
    mount: ex
    density: 1500
    color: "#c9b48a"
    pieces:
      - {kind: rod, from: [-0.2, 0, 4.0], to: [0.2, 0, 4.0], radius: 0.2}   # (inside the rocker)
  - id: rock
    shape: part
    pos: [0, 0, 27.9]
    mount: ez
    density: 1500
    friction: 1.0
    color: "#c9b48a"
    pieces:
      - {kind: poly, points: [[-18.5, 7.0156], [-17.8608, 6.4664], [-17.2054, 5.9367], [-16.5342, 5.4271], [-15.848, 4.938], [-15.1473, 4.4699], [-14.4328, 4.0231], [-13.7051, 3.5981], [-12.9649, 3.1953], [-12.2129, 2.815], [-11.4497, 2.4576], [-10.6761, 2.1235], [-9.8928, 1.8128], [-9.1004, 1.5259], [-8.2997, 1.2631], [-7.4915, 1.0246], [-6.6764, 0.8106], [-5.8553, 0.6213], [-5.0287, 0.4569], [-4.1977, 0.3176], [-3.3627, 0.2034], [-2.5247, 0.1145], [-1.6844, 0.0509], [-0.8426, 0.0127], [0.0, 0.0], [0.8426, 0.0127], [1.6844, 0.0509], [2.5247, 0.1145], [3.3627, 0.2034], [4.1977, 0.3176], [5.0287, 0.4569], [5.8553, 0.6213], [6.6764, 0.8106], [7.4915, 1.0246], [8.2997, 1.2631], [9.1004, 1.5259], [9.8928, 1.8128], [10.6761, 2.1235], [11.4497, 2.4576], [12.2129, 2.815], [12.9649, 3.1953], [13.7051, 3.5981], [14.4328, 4.0231], [15.1473, 4.4699], [15.848, 4.938], [16.5342, 5.4271], [17.2054, 5.9367], [17.8608, 6.4664], [18.5, 7.0156]], y: [-1.4, 1.4], collide: 1}   # the rocker E
      - {kind: poly, points: [[-15.6, 7.0156], [-14.4, 7.0156], [-14.4, 36.55], [-15.6, 36.55]], y: [-3.35, -2.45]}   # the post C
      - {kind: poly, points: [[-12.8, 7.0156], [-15.6, 7.0156], [-15.6, 8.4156], [-14.4, 9.4156]], y: [-3.35, -1.4]}   # its foot on the rocker
      - {kind: poly, points: [[14.4, 7.0156], [15.6, 7.0156], [15.6, 36.55], [14.4, 36.55]], y: [-2.55, -1.65]}   # the post D
      - {kind: poly, points: [[12.8, 7.0156], [15.6, 7.0156], [15.6, 8.4156], [14.4, 9.4156]], y: [-2.55, -1.4]}   # its foot on the rocker
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-34, -1.2], [34, -1.2], [34, 0], [-34, 0]], y: [-6, 6], collide: 2}   # the floor
      - {kind: poly, points: [[-3.0, 0], [3.0, 0], [0.2, 27.5], [-2.2, 27.5]], y: [2.6, 3.6]}   # the standard carrying A and B, behind the cradle
      - {kind: disc, center: [-1, 27.5], radius: 1.4, y: [2.4, 3.8], color: "#8f8a80"}
      - {kind: disc, center: [0, 10], radius: 1.3, y: [2.4, 3.8], color: "#8f8a80"}
      - {kind: poly, points: [[-7, 0], [7, 0], [7, 0.8], [-7, 0.8]], y: [2, 4.2]}
joints:
  - {id: j_A, type: hinge, body: wa, axis: [0, -1, 0], damping: 0.01}   # wheel A: the one driven joint
  - {id: j_r, type: hinge, body: rod, axis: [0, -1, 0], damping: 0.0005}
  - {id: j_B, type: hinge, body: wb, axis: [0, -1, 0], damping: 0.01}   # wheel B; + : anticlockwise as drawn
  - {id: j_ex, type: slide, body: ex, axis: [1, 0, 0]}   # the rocker E, free on the floor: along it,
  - {id: j_ez, type: slide, body: ez, axis: [0, 0, 1]}   # up and down,
  - {id: j_E, type: hinge, body: rock, axis: [0, -1, 0], damping: 0.002}   # and rocking; + : anticlockwise
wheels:
  # B's rim, where the bands lie
  - {id: w_b, body: wb, pos: [0, -2.5, 0], radius: 8.2, width: 1.6, flange: 0.25, spokes: 0, web: true, mass: 0.05, color: "#e2d8bf"}
pins:
  - {id: pin_b, a: rod, b: wb, at: [5.1014, -4.1, 24.4978]}   # the rod on B's pin

cords:
  - id: band_c
    from: {body: rock, at: [-15, -2.9, 35.85]}   # the top of the post
    to: {body: wb, at: [4.5453, -2.9, 33.5407], wound: true}   # made fast on B's rim
    over: [w_b]
    senses: [1]
    links: 40
    segments: 4
    root_damping: 0.0001
    joint_armature: 0.000001
    thickness: 0.3
    stiffness: 30000
    pretension: 3
    damping: 2.0
    friction: 0.8
  - id: band_d
    from: {body: rock, at: [15, -2.1, 35.85]}   # the top of the post
    to: {body: wb, at: [-6.5453, -2.1, 33.5407], wound: true}   # made fast on B's rim
    over: [w_b]
    senses: [-1]
    links: 40
    segments: 4
    root_damping: 0.0001
    joint_armature: 0.000001
    thickness: 0.3
    stiffness: 30000
    pretension: 3
    damping: 2.0
    friction: 0.8
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_A, kind: velocity, rpm: 20, kv: 20, max_torque: 200}
checks:
  # B swings 57.1 deg in all as A goes round; E rocks with it, the post tops going with B's rim: 8.35 / 35.85 of B's angle
  - {type: amplitude, joint: j_E, min: 0.105, max: 0.125, sustain: 0.95, settle_s: 0.5, window_s: 9}   # E rocks about +-6.5 deg every turn of A (rad)
  - {type: follow, out: j_E, in: j_B, expect: 0.2329, tol: 0.02, min_r2: 0.99, settle_s: 0.5, window_s: 9}
  # and it rolls on the floor, not sliding: its travel along the floor is its rocking times its radius (m per rad)
  - {type: follow, out: j_ex, in: j_E, expect: -0.279, tol: 0.01, min_r2: 0.99, settle_s: 0.5, window_s: 9}
  - {type: position, joint: j_ez, min: -0.05, max: 0.05, settle_s: 0.5, window_s: 9}   # on the floor throughout (cm)
  - {type: penetration, max: 0.0025, settle_s: 0.5}
camera: {target: [0, 0, 18.5], position: [0, -160, 18.5], fov: 22}
display:
  output: j_E
  labels: {j_A: "Wheel A (turned)", j_B: "Wheel B", j_E: "Rocker E", j_ex: "Rocker E (along the floor)"}
