$fn=40;
HOLE_RADIUS=2.4; // my Wanhao Duplicator 4 makes no errors with Slic3r, 2.4mm is ideal lego hole

difference() {
  union() {
    translate([0, 0, 16+4]) sphere(r=3);
    hull() {
      translate([0, 0, 4]) cylinder(r=4, h=4+8);
      translate([0, 0, 4]) cylinder(r=1.5, h=4+8+3);
    }
    translate([0, 4, 4]) rotate([90, 0, 0]) cylinder(r=4, h=8);
  }
  translate([0, 4.1, 4-0.1]) rotate([90, 0, 0]) linear_extrude(height=8.2) axle();
}

module axle() {
  axle_gap = 1.95;
  union() {
    translate([-HOLE_RADIUS, -axle_gap/2, 0])
      roundedRect(HOLE_RADIUS * 2, axle_gap, .2);
    translate([-axle_gap/2, -HOLE_RADIUS, 0])
      roundedRect(axle_gap, HOLE_RADIUS * 2, .2);
  }
}

module roundedRect(x, y, radius) {
  hull() {
    translate([radius, radius, 0]) circle(r=radius);
    translate([x - radius, radius, 0]) circle(r=radius);
    translate([x - radius, y - radius, 0]) circle(r=radius);
    translate([radius, y - radius, 0]) circle(r=radius);
  }
}
