number: 323
slug: rolling-parallel-ruler
name: Rolling Parallel Ruler
brown: "Parallel ruler consisting of a simple straight ruler, B, with an attached axle, C, and pair of wheels, A, A. The wheels, which protrude but slightly through the under side of the ruler, have their edges nicked to take hold of the paper and keep the ruler always parallel with any lines drawn upon it."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 50, duration_s: 8, floor: false}
bodies:
  # the drawing board and its sheet of paper (the frame)
  - id: paper
    shape: part
    pos: [0, 0, 0]
    fixed: true
    friction: 0.9
    color: "#f4efe2"
    pieces:
      - {kind: poly, points: [[-14, -0.6], [14, -0.6], [14, 0], [-14, 0]], y: [-18, 18], collide: 1}
  # the hand's push, at the ruler's near end: along the paper (driven), and free across and up
  - {id: Cx, shape: part, pos: [0, 13, 1.0], mass: 0.01, color: "#8f8a80", pieces: [{kind: rod, from: [0, 13, 1.6], to: [0, 13, 1.7], radius: 0.05, collide: 0}]}
  - {id: Cy, shape: part, pos: [0, 13, 1.0], mount: Cx, mass: 0.01, color: "#8f8a80", pieces: [{kind: rod, from: [0, 13, 1.6], to: [0, 13, 1.7], radius: 0.05, collide: 0}]}
  - {id: Cz, shape: part, pos: [0, 13, 1.0], mount: Cy, mass: 0.01, color: "#8f8a80", pieces: [{kind: rod, from: [0, 13, 1.6], to: [0, 13, 1.7], radius: 0.05, collide: 0}]}
  # the ruler B, free to turn on the paper about the hand's point; its underside is 0.15 above the paper
  - id: B
    shape: part
    pos: [0, 13, 1.0]
    mount: Cz
    density: 700
    color: "#c9b68c"
    pieces:
      - {kind: poly, points: [[-3, 0.15], [3, 0.15], [3, 1.7], [-3, 1.7]], y: [-15, -11.6], collide: 0}
      - {kind: poly, points: [[-3, 0.15], [3, 0.15], [3, 1.7], [-3, 1.7]], y: [-8.4, 8.4], collide: 0}
      - {kind: poly, points: [[-3, 0.15], [3, 0.15], [3, 1.7], [-3, 1.7]], y: [11.6, 15], collide: 0}
      - {kind: poly, points: [[-3, 1.25], [3, 1.25], [3, 1.7], [-3, 1.7]], y: [-11.6, -8.4], collide: 0}
      - {kind: poly, points: [[-3, 1.25], [3, 1.25], [3, 1.7], [-3, 1.7]], y: [8.4, 11.6], collide: 0}
      - {kind: rod, from: [0, 13, 1.7], to: [0, 13, 3.2], radius: 0.35, collide: 0, color: "#8f8a80"}
  # the axle C and its pair of wheels A, A (one piece: they turn together), nicked edges on the paper
  - id: C
    shape: part
    pos: [0, 0, 1.0]
    mount: B
    friction: 0.9
    color: "#9c8f78"
    pieces:
      - {kind: rod, from: [0, -10.9, 1.0], to: [0, 10.9, 1.0], radius: 0.18, collide: 0}
      - {kind: disc, center: [0, 1.0], radius: 1.0, y: [-10.6, -9.4], collide: 2}
      - {kind: disc, center: [0, 1.0], radius: 1.0, y: [9.4, 10.6], collide: 2}
joints:
  - {id: j_x, type: slide, body: Cx, axis: [1, 0, 0], damping: 0.01}   # the hand's push (driven)
  - {id: j_y, type: slide, body: Cy, axis: [0, 1, 0], damping: 0.01}
  - {id: j_z, type: slide, body: Cz, axis: [0, 0, 1], damping: 0.01, range: [-1, 1]}
  - {id: j_yaw, type: hinge, body: B, axis: [0, 0, 1], damping: 0.0005}   # the ruler turning on the paper
  - {id: j_C, type: hinge, body: C, axis: [0, 1, 0], damping: 0.0002}   # the axle in the ruler
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_x, kind: velocity, rpm: 0, swing: {amplitude: 0.05, hz: 0.25}, kv: 50, max_torque: 20}
checks:
  # the wheels roll on the paper without slipping: the axle turns 1/r = 100 rad per metre the ruler moves
  - {type: ratio, out: j_C, in: j_x, expect: 100.0, tol: 1.5, settle_s: 0.5, window_s: 7.0}
  # Brown's point: pushed at one end only, the ruler still keeps parallel (under 0.09 deg), because both
  # wheels are on one axle and grip the paper, and it does not creep along its own length
  - {type: position, joint: j_yaw, min: -0.0015, max: 0.0015, settle_s: 0.2, window_s: 7.5}
  - {type: position, joint: j_y, min: -0.02, max: 0.02, settle_s: 0.2, window_s: 7.5}
  - {type: penetration, max: 0.0003, settle_s: 0.2}
camera: {target: [0, 0, -6], position: [-7, 0, 44], fov: 30}
display:
  output: j_C
  labels: {j_x: Hand pushing the ruler's end (driver), j_y: Ruler along its length, j_yaw: Turn of the ruler, j_C: Axle and wheels}
