{"id":"0lz72vXpwih2IlCv","name":"ParkBar","license":"CC-BY-NC-4.0","published_at":"2026-11-23T00:57:24.423Z","updated_at":"2026-11-23T00:57:24.423Z","author":{"id":"kEk1ip7lDTEFgjmz","name":"bongkow","image":null},"thumb":1,"unit":"mm","code":"// ParkBar: remote-controlled parking blocker. A 2020 aluminium profile stands up (90) to block a parking\n// space and lies flat (0) so a car can drive over. Part 0 = assembly, part k = one printable part on z=0.\npart = 0; // [0:Assembly, 1:Base, 2:Lid, 3:Hub]\nNAME = \"ParkBar\";\n$hl = 0;   // set by the web app: the assembly draws only part $hl (red in P0); -1 = every part, lifted apart\n\nbar_angle = 90;  // [0:90] 0 = lying flat, 90 = standing\nbar_len = 500;   // 2020 profile length\ndebug = 0;       // [0:off, 1:swing collisions, 2:bought parts vs base] 1 and 2 must render empty\n\n/* [Bought parts: measure yours] */\nbar_w = 20;            // 2020 profile\nsv_l = 40.7;           // servo body length (MG996R assumed)\nsv_w = 19.7;           // servo body thickness\nsv_h = 37;             // servo body, bottom to case top\nsv_shaft_off = 10;     // shaft centre from the near body end\nsv_tab_l = 54.5;       // length over mounting tabs\nsv_tab_t = 2.5;\nsv_above_tab = 7.5;    // case top above the tab's top face\nsv_shaft = 6;          // spline height above case top\nsv_hole_x = 49.5;      // tab hole spacing, long way\nsv_hole_z = 10;        // tab hole spacing, short way\nhorn_d = 21;           // round servo horn disc\nhorn_t = 2.5;\nhorn_hole_r = 7.5;     // horn screw circle radius\nesp = [51.5, 28.5, 1.6];   // ESP32 DevKit (30 pin) board\nbat = [77, 41, 21];        // 2x18650 holder\n\n/* [Printed] */\nclr = 0.2;\nfloor_t = 3;\nwall = 3;\ncheek_t = 5;\nwall_h = 32;\nlid_t = 2.4;\npivot_z = 18;\nhub_wall = 3.8;\nwall_s = 6;        // hub wall, servo side\nwall_p = 8;        // hub wall, pivot bolt side\nhub_len = 46;\nbar_back = 6;      // profile end behind the pivot\nflange = 16;\nanchor_d = 6.5;    // M6 ground anchors\n$fn = 48;\n$ba = bar_angle;\n\nbore = bar_w + 2 * clr;\nhub_h = bore + 2 * hub_wall;\nhub_w = bore + wall_s + wall_p;\nhub_y0 = -(bore / 2 + wall_s);\nhub_yp = hub_y0 + hub_w;\n// Y stack on the servo side, from the hub outward\nsv_top_y = hub_y0 + horn_t - 1 - sv_shaft;   // servo case top\nyb1 = sv_top_y - sv_above_tab + cheek_t;     // box/cheek outer face (bar side)\nyi1 = yb1 - cheek_t;                         // box inner face = servo tab seat\nyk0 = hub_yp + 0.6;                          // far cheek\nyk1 = yk0 + cheek_t;\nyf1 = yk1 + flange;\nx0 = -22;\nxi0 = x0 + wall;\npost = 7;\nsv_cx = sv_l / 2 - sv_shaft_off;   // servo body centre x\nsv_tab_x1 = sv_cx + sv_tab_l / 2;\nesp_x = sv_tab_x1 + 5.5;\nbat_x = esp_x + esp.x + 3.5;\nxi1 = bat_x + bat.x + 0.5 + post;\nx1 = xi1 + wall;\nyi0 = yi1 - bat.y - 1;\nyb0 = yi0 - wall;\nyf0 = yb0 - flange;\nesp_y = yi0 + 0.5;\nesp_z = floor_t + 10;    // board sits high so the header pins hang free\nstop_x = hub_h / 2 + 0.05;\nposts = [[sv_cx, yi0 + post / 2], [sv_tab_x1 + 0.5 + post / 2, yi1 - post / 2],\n         [xi1 - post / 2, yi0 + post / 2], [xi1 - post / 2, yi1 - post / 2]];\nanchors = [[0, yf0 + flange / 2], [x1 - 14, yf0 + flange / 2], [0, yf1 - flange / 2], [x1 - 14, yf1 - flange / 2]];\n\nmodule show(k) if ($hl == 0 || $hl == k || $hl == -1) translate([0, 0, $hl == -1 ? k * 10000 : 0]) children();\n\n/** \"Pk:NAME\" cut into the face at z=0 from below (mirrored so it reads correctly from underneath). */\nmodule engrave(k, size = 4, depth = 0.4)\n  translate([0, 0, -0.01]) linear_extrude(depth + 0.01) mirror([1, 0, 0])\n    text(str(\"P\", k, \":\", NAME), size = size, halign = \"center\", valign = \"center\");\n\n/** cylinder along +Y starting at the current origin */\nmodule ycyl(d, h) rotate([-90, 0, 0]) cylinder(d = d, h = h);\n\n// ---- P1 Base: floor with anchor flanges, electronics box, two cheeks around the hub, end stops ----\nmodule part1() difference() {\n  union() {\n    translate([x0, yf0, 0]) cube([x1 - x0, yf1 - yf0, floor_t]);\n    difference() {   // box; its bar-side wall is the servo cheek\n      translate([x0, yb0, 0]) cube([x1 - x0, yb1 - yb0, wall_h]);\n      translate([xi0, yi0, floor_t]) cube([xi1 - xi0, yi1 - yi0, wall_h]);\n    }\n    translate([-stop_x - 4, yk0, 0]) cube([40, cheek_t, wall_h]);             // far cheek\n    translate([-stop_x - 4, yb1 - 0.01, 0]) cube([4, yk1 - yb1, 30]);         // up stop (90)\n    translate([25, -bar_w / 2, 0]) cube([20, bar_w, pivot_z - hub_h / 2]);    // down stop (0)\n    for (p = posts) translate([p.x - post / 2, p.y - post / 2, 0]) cube([post, post, wall_h]);\n    difference() {   // ESP32 corner posts: 2.5 mm ledge under each board corner, 2 mm rim outside it\n      for (dx = [0, 1], dy = [0, 1])\n        translate([esp_x + dx * esp.x - (dx ? 2.5 : 2), esp_y + dy * esp.y - (dy ? 2.5 : 2), 0])\n          cube([4.5, 4.5, esp_z + esp.z + 1.5]);\n      translate([esp_x - clr, esp_y - clr, esp_z]) cube([esp.x + 2 * clr, esp.y + 2 * clr, 10]);\n    }\n    translate([bat_x - 2.5, yi0, 0]) cube([1.6, yi1 - yi0, floor_t + 8]);     // battery divider\n  }\n  // servo body cutout, tab screw pilots, and screwdriver holes through the opposite wall\n  translate([-sv_shaft_off - clr, yi1 - 1, pivot_z - sv_w / 2 - clr]) cube([sv_l + 2 * clr, cheek_t + 2, sv_w + 2 * clr]);\n  for (sx = [-1, 1], sz = [-1, 1]) translate([sv_cx + sx * sv_hole_x / 2, 0, pivot_z + sz * sv_hole_z / 2]) {\n    translate([0, yi1 - 1, 0]) ycyl(2.5, cheek_t + 2);\n    translate([0, yb0 - 1, 0]) ycyl(5, wall + 2);\n  }\n  translate([0, yk0 - 1, pivot_z]) ycyl(5.4, cheek_t + 2);                    // M5 pivot bolt\n  for (p = posts) translate([p.x, p.y, wall_h - 12]) cylinder(d = 2.5, h = 13);   // M3 lid screws\n  for (a = anchors) translate([a.x, a.y, -1]) cylinder(d = anchor_d, h = floor_t + 2);\n  translate([(x0 + x1) / 2, (yb0 + yb1) / 2, 0]) engrave(1);\n}\n\n// ---- P2 Lid: flat plate, engraved on the inside ----\nmodule part2() difference() {\n  translate([x0, yb0, 0]) cube([x1 - x0, yb1 - yb0, lid_t]);\n  for (p = posts) translate([p.x, p.y, -1]) cylinder(d = 3.4, h = lid_t + 2);\n  translate([(x0 + x1) / 2 + 40, (yb0 + yb1) / 2, 0]) engrave(2);\n}\n\n// ---- P3 Hub: sleeve over the profile, servo horn on one side, M5 pivot on the other ----\nmodule hub_raw() difference() {   // lying-flat pose, pivot axis = Y through the origin\n  union() {\n    translate([0, hub_y0, -hub_h / 2]) cube([hub_len, hub_w, hub_h]);\n    translate([0, hub_y0, 0]) ycyl(hub_h, hub_w);\n  }\n  translate([-bar_back - clr, -bore / 2, -bore / 2]) cube([hub_len + bar_back + 1, bore, bore]);\n  translate([0, hub_y0 - 0.01, 0]) ycyl(horn_d + 0.4, horn_t + 0.01);         // horn pocket\n  translate([0, hub_y0 - 0.01, 0]) ycyl(8, wall_s + 1);                       // horn screw access\n  for (a = [0:90:270]) translate([horn_hole_r * cos(a), hub_y0 - 0.01, horn_hole_r * sin(a)]) ycyl(2, wall_s + 1);\n  translate([0, hub_yp - wall_p + 1.5, 0]) ycyl(4.5, wall_p);                 // M5 pivot bolt taps in here\n  for (x = [15, 38]) translate([x, 0, bore / 2 - 0.5]) cylinder(d = 5.4, h = hub_wall + 1);   // M5 into T-nuts\n}\nmodule part3() difference() {     // printed on its pivot-side face\n  translate([0, 0, hub_yp]) rotate([-90, 0, 0]) hub_raw();\n  translate([26, 0, 0]) engrave(3);\n}\nmodule swing() translate([0, 0, pivot_z]) rotate([0, -$ba, 0]) children();\nmodule hub_placed() swing() rotate([90, 0, 0]) translate([0, 0, -hub_yp]) part3();\n\n// ---- bought parts ----\nmodule label(t, s = 5) translate([0, 0, -0.6]) linear_extrude(0.7) text(t, size = s, halign = \"center\", valign = \"center\");\nmodule bar_ghost() swing() difference() {\n  translate([-bar_back, -bar_w / 2, -bar_w / 2]) cube([bar_len, bar_w, bar_w]);\n  translate([hub_len + 70, 0, bar_w / 2]) label(\"2020 PROFILE\", 7);\n}\nmodule fixed_ghosts() {\n  difference() {   // servo\n    union() {\n      translate([-sv_shaft_off, sv_top_y - sv_h, pivot_z - sv_w / 2]) cube([sv_l, sv_h, sv_w]);\n      translate([sv_cx - sv_tab_l / 2, yi1 - sv_tab_t, pivot_z - sv_w / 2]) cube([sv_tab_l, sv_tab_t, sv_w]);\n      translate([0, sv_top_y - 0.01, pivot_z]) ycyl(6, sv_shaft);\n    }\n    translate([sv_cx, sv_top_y - sv_h / 2 - 2, pivot_z + sv_w / 2]) label(\"SERVO\");\n  }\n  difference() {   // ESP32\n    union() {\n      translate([esp_x, esp_y, esp_z]) cube(esp);\n      translate([esp_x + 4, esp_y + 4, esp_z]) cube([esp.x - 8, esp.y - 8, esp.z + 3]);\n    }\n    translate([esp_x + esp.x / 2, esp_y + esp.y / 2, esp_z + esp.z + 3]) label(\"ESP32\");\n  }\n  difference() {   // battery\n    translate([bat_x, yi0 + 0.5, floor_t]) cube(bat);\n    translate([bat_x + bat.x / 2, yi0 + 0.5 + bat.y / 2, floor_t + bat.z]) label(\"2x18650\", 8);\n  }\n}\nmodule ghosts() if ($hl <= 0) { fixed_ghosts(); bar_ghost(); }\n\nif (debug == 1) for (a = [0:15:90]) intersection() {\n  union() { part1(); translate([0, 0, wall_h]) part2(); fixed_ghosts(); }\n  union() { hub_placed($ba = a); bar_ghost($ba = a); }\n} else if (debug == 2) intersection() { part1(); fixed_ghosts(); }\nelse if (part == 0) {\n  show(1) part1();\n  show(2) translate([0, 0, wall_h]) part2();\n  show(3) hub_placed();\n  ghosts();\n}\nif (debug == 0 && part == 1) part1();\nif (debug == 0 && part == 2) part2();\nif (debug == 0 && part == 3) part3();\n","param_values":{},"print":{"threemf":true,"stl":false}}