No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trackball.scad 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * Trackball
  3. *
  4. * Copyright (c) 2022 - 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * Required parts:
  7. * - 1x Raspberry Pi Pico
  8. * - 4x Cherry MX compatible switches and keycaps
  9. * - 1x Billard ball, diameter 38mm
  10. * - 3x Si3N4 static bearing balls, diameter 3mm
  11. * - 1x PMW3360 sensor with breakout board
  12. * - 8x M2 screw, length 5mm
  13. * - 8x M2 heat melt insert, length 4mm
  14. *
  15. * For the PMW3360 breakout board get this:
  16. * https://github.com/jfedor2/pmw3360-breakout
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * See <http://www.gnu.org/licenses/>.
  29. */
  30. include <BOSL2/std.scad>;
  31. include <BOSL2/threading.scad>;
  32. // https://www.thingiverse.com/thing:421524
  33. use <external/cherry_mx.scad>
  34. // https://www.printables.com/model/210898-raspberry-pi-pico-case
  35. use <external/pico_case.scad>
  36. // ######################
  37. // ## Rendering Select ##
  38. // ######################
  39. //ball_and_roller();
  40. //pico_wrap();
  41. //sensor();
  42. //mx_switch_cutout(wall);
  43. //mx_switch_test();
  44. //roller_mount_test();
  45. //roller_holder();
  46. //roller_mount_tri();
  47. trackball_top();
  48. //trackball_bottom();
  49. //assembly();
  50. //print();
  51. // #######################
  52. // #### Configuration ####
  53. // #######################
  54. $fn = 200;//42;
  55. ball_dia = 38.0;
  56. roller_dia = 3.0;
  57. roller_ball_h = ball_dia / 2 - 5;
  58. roller_count = 3;
  59. wall = 3.0;
  60. $c = 0.1;
  61. $e = 0.01;
  62. left_hand_version = false;
  63. cut_roller_holder = false;
  64. draw_supports = false;
  65. draw_ball_roller = true;
  66. draw_switches = true;
  67. draw_sensor = true;
  68. use_external_pico_model = true;
  69. draw_keycap = false;
  70. holdertype="ball_rollen";
  71. //holdertype="static";
  72. // #######################
  73. // ## Raspberry Pi Pico ##
  74. // #######################
  75. pico_w = 21;
  76. pico_l = 51;
  77. pico_d = 1.0;
  78. pico_hole_d = 2.1;
  79. pico_hole_x = 4.8;
  80. pico_hole_y = 2.0;
  81. pico_hole_d_x = 11.4;
  82. pico_hole_d_y = pico_l - 2 * pico_hole_y;
  83. pico_usb_w = 8.0;
  84. pico_usb_h = 2.8;
  85. pico_usb_d = 6.0;
  86. pico_usb_off = 1.3;
  87. // ######################
  88. // ### PMW3360 Sensor ###
  89. // ######################
  90. // https://github.com/jfedor2/pmw3360-breakout
  91. sensor_w = 22;
  92. sensor_l = 34;
  93. sensor_pcb_h = 1.6;
  94. sensor_hole_dia = 2.2;
  95. sensor_hole_off_x = 3.0;
  96. sensor_hole_off_y = 3.0;
  97. sensor_hole_dist_x = 16.0;
  98. sensor_hole_dist_y = 24.5;
  99. sensor_cut_w = 8.0 + 0.5;
  100. sensor_cut_h = 17.26;
  101. sensor_cut_off_x = 7.0 - 0.25;
  102. sensor_cut_off_y = 5.27;
  103. sensor_cut_edge_to_pin1 = 2.75;
  104. sensor_edge_to_pin1 = 1.52;
  105. sensor_ball_to_lens_top = 2.4;
  106. sensor_ball_to_chip_bottom = 9.81;
  107. sensor_chip_w = 9.1;
  108. sensor_chip_l = 16.2;
  109. sensor_chip_h = 2.21;
  110. sensor_pin_w = 0.5;
  111. sensor_pin_h = 4.51;
  112. sensor_pin_d = 0.2;
  113. sensor_pin_dist = 10.7;
  114. sensor_pin_off_top = 0.5;
  115. sensor_pin_pitch = 0.89;
  116. sensor_pin1_to_optical_center = 5.66;
  117. sensor_lens_cutout_r = 2.0;
  118. sensor_lens_cutout_w = 4.0;
  119. sensor_lens_cutout_growth = 0.25;
  120. sensor_lens_cutout_to_chip = 6.71 - 1.60;
  121. sensor_lens_baseplate_h = 2.40;
  122. sensor_lens_d = 19.0 + 1.0;
  123. sensor_lens_w = 21.35 + 0.2;
  124. sensor_lens_off = 10.97;
  125. // ######################
  126. // ## MX Switch Cutout ##
  127. // ######################
  128. // https://geekhack.org/index.php?topic=70654.0
  129. mx_co_w = 14.0;
  130. mx_co_w_add = 0.8;
  131. mx_co_h = 14.0;
  132. mx_co_keycap_w = mx_co_w + 2.5*2;
  133. mx_co_keycap_h = mx_co_h + 2.5*2;
  134. mx_co_h_off_1 = 1.0;
  135. mx_co_h_off_2 = 3.5;
  136. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  137. mx_co_r = 0.4;
  138. // https://geekhack.org/index.php?topic=71550.0
  139. mx_co_th = 1.5 - 0.1;
  140. mx_co_b_add = 1.0;
  141. mx_co_b_w = mx_co_w + mx_co_b_add;
  142. mx_co_b_h = mx_co_h + mx_co_b_add;
  143. mx_travel = 3.9;
  144. // ######################
  145. // ### Implementation ###
  146. // ######################
  147. base_dia = 62;
  148. grub_screw_dia = 2.8;
  149. grub_channel_dia = 4.0;
  150. roller_thread_dia = roller_dia + 5.0;
  151. roller_h = roller_dia + 7.0+2;
  152. roller_ball_h_off = 0.4;
  153. roller_ball_hold_off = 0.5;
  154. roller_thread_hole = roller_dia - 1;
  155. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  156. roller_ridge_h = 1.5;
  157. roller_mount_angle_off = 90-5;
  158. roller_mount_dia = roller_thread_dia + 2.0;
  159. ball_h = 15; // todo
  160. switch_test_w = 25;
  161. roller_mount_holder_gap = 0.8;
  162. sensor_pcb_mount_gap = 2.0;
  163. sensor_pcb_support_h = 1.6 + 3.4;
  164. // rotate translate
  165. sw = [ // x z_pre_T z_post_T
  166. [ [-5, 0, -33 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// thumb
  167. [ [-5, -15, 3 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// thumb
  168. //[ [-5, 0, -70 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 0,-14.5]],// thumb
  169. [ [-5, -15, 140 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 3,-14.5]],// middle
  170. [ [-5, 0, 100 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// ring
  171. ];
  172. sw_mount_w = mx_co_w + 7;
  173. sw_mount_co_l = 10;
  174. bottom_base_wall = wall + 0.5;
  175. bottom_base_below_zero = bottom_base_wall + 4.5;
  176. pico_co_w = pico_w + 1;
  177. pico_co_l = pico_l + 1;
  178. reset_button_dia = 4.0;
  179. reset_button_off_x = 7;
  180. reset_button_off_y = 12.15;
  181. pico_support_w = 6.5;
  182. pico_support_l = 5;
  183. pico_screw_depth = 6;
  184. pico_screw_d = 1.8;
  185. usb_cutout_grow_l = 10;
  186. usb_cutout_grow_x = 20;
  187. usb_cutout_grow_y = 10;
  188. usb_cutout_w_add = 1;
  189. usb_cutout_h_add = 0.6;
  190. assembly_dist = 20;
  191. roller_holder_sider_cut = 1.5;
  192. roller_holder_h_compensation = -0.1;
  193. bottom_add_wall = 4;
  194. screw_dia = 3.2;
  195. screw_off = base_dia / 2 - 10;
  196. screw_head_d = 6.0;
  197. screw_head_h = 3.5;
  198. //screw_angles = [ 30, -15, 180 + 40, 180 - 30 ];
  199. screw_angles = [ 15, -15, 180 + 15, 180 - 15 ];
  200. screw_insert_dia = 4.8;
  201. screw_insert_h = 6.0;
  202. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  203. function sphere_angle_at_rh(h, r) = acos(h / r);
  204. module mx_switch_cutout(h) {
  205. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  206. linear_extrude(h + 1) {
  207. translate([mx_co_w_add, 0]) {
  208. square([mx_co_w, mx_co_h]);
  209. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  210. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  211. translate([x, y])
  212. circle(r = mx_co_r);
  213. }
  214. for (x = [0, mx_co_w + mx_co_w_add])
  215. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  216. translate([x, mx_co_h_off_1 + y, 0])
  217. square([mx_co_w_add, mx_co_h_off_2]);
  218. }
  219. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  220. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  221. }
  222. translate([-mx_co_keycap_w/2,-mx_co_keycap_h/2, h])
  223. cube([mx_co_keycap_w, mx_co_keycap_h, 50]);
  224. }
  225. module mx_switch_test() {
  226. difference() {
  227. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  228. cube([switch_test_w, switch_test_w, wall]);
  229. mx_switch_cutout(wall);
  230. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  231. linear_extrude(1.1)
  232. text("switch test", size = 3, halign = "center");
  233. }
  234. %translate([0, 0, wall])
  235. rotate([0, 0, 180])
  236. mx_switch($t);
  237. }
  238. module pico_own() {
  239. translate([-pico_w / 2, -pico_l / 2, 0])
  240. difference() {
  241. union() {
  242. color("green")
  243. cube([pico_w, pico_l, pico_d]);
  244. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  245. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  246. }
  247. for (x = [0, pico_hole_d_x])
  248. for (y = [0, pico_hole_d_y])
  249. translate([pico_hole_x + x, pico_hole_y + y, -1])
  250. cylinder(d = pico_hole_d, h = pico_d + 2);
  251. }
  252. }
  253. module pico_wrap() {
  254. translate([0,0,3.9])
  255. rotate([0,180,0])
  256. if (use_external_pico_model)
  257. translate([-pico_w / 2, -pico_l / 2, 0])
  258. pico();
  259. else
  260. pico_own();
  261. }
  262. module sensor_lens_cutout_intern() {
  263. cylinder(d = sensor_lens_cutout_r * 2, h = $e);
  264. translate([-sensor_lens_cutout_r, 0, 0])
  265. cube([sensor_lens_cutout_r * 2, sensor_lens_cutout_w, $e]);
  266. }
  267. module rounded_cube(x, y, z, r) {
  268. hull()
  269. for (tx = [r, x - r])
  270. for (ty = [r, y - r])
  271. translate([tx, ty, 0])
  272. cylinder(d = r * 2, h = z);
  273. }
  274. module sensor_lens_cutout() {
  275. translate([0, 0, sensor_lens_cutout_to_chip])
  276. hull() {
  277. translate([0, 0, sensor_lens_baseplate_h - $e])
  278. sensor_lens_cutout_intern();
  279. scale(1 + sensor_lens_cutout_growth * sensor_lens_baseplate_h)
  280. sensor_lens_cutout_intern();
  281. }
  282. translate([-sensor_lens_d / 2, -sensor_lens_w + sensor_lens_off, 0])
  283. rounded_cube(sensor_lens_d, sensor_lens_w, sensor_lens_cutout_to_chip, 6);
  284. translate([-3 / 2, -sensor_lens_w + sensor_lens_off - 0.5, 0])
  285. cube([3, 0.5, sensor_lens_cutout_to_chip]);
  286. }
  287. module sensor() {
  288. translate([-sensor_w / 2, -sensor_l / 2, 0])
  289. difference() {
  290. color("green")
  291. cube([sensor_w, sensor_l, sensor_pcb_h]);
  292. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  293. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  294. for (x = [0, sensor_hole_dist_x])
  295. for (y = [0, sensor_hole_dist_y])
  296. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  297. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  298. }
  299. color("#303030")
  300. translate([-sensor_chip_w / 2, -sensor_l / 2 - sensor_chip_l + sensor_edge_to_pin1 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, -sensor_chip_h])
  301. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  302. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  303. for (p = [0 : 15])
  304. translate([0, p * sensor_pin_pitch, 0])
  305. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  306. if (((p % 2 == 0) && (x < 0))
  307. || ((p % 2 == 1) && (x > 0)))
  308. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  309. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  310. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0]) {
  311. color("cyan")
  312. translate([0, 0, -sensor_chip_h + 1])
  313. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  314. %color("blue")
  315. sensor_lens_cutout();
  316. }
  317. }
  318. module ball_and_roller() {
  319. color("red")
  320. sphere(d = ball_dia, $fn = $fn);
  321. for (r = [0 : roller_count - 1])
  322. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  323. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  324. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  325. translate([0, 0, -roller_dia / 2])
  326. roller_holder();
  327. }
  328. module roller_holder() {
  329. if(holdertype=="static") {
  330. translate([0, 0, -roller_h + roller_dia / 2])
  331. difference() {
  332. color("magenta")
  333. union() {
  334. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  335. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  336. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  337. }
  338. translate([-roller_mount_dia / 2 - 1, roller_mount_dia / 2 - roller_holder_sider_cut, -1])
  339. cube([roller_mount_dia + 2, roller_mount_dia / 2 + 1, roller_h + 2]);
  340. translate([0, 0, -$e])
  341. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  342. translate([0, 0, roller_h - roller_dia / 2 + roller_holder_h_compensation])
  343. sphere(d = roller_dia, $fn = $fn);
  344. if (cut_roller_holder)
  345. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -$e])
  346. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  347. }
  348. %color("blue")
  349. sphere(d = roller_dia, $fn = $fn);
  350. }
  351. if(holdertype=="ball_rollen") {
  352. l=10;
  353. difference() {
  354. union() {
  355. translate([0,0,$e -l +roller_dia/2 -2])
  356. cylinder(d=roller_mount_dia,h=l-1);
  357. %union(){
  358. color("red")
  359. translate([0,0,(roller_dia-3.18)/2])
  360. sphere(d = 3.18, $fn = $fn);
  361. color("silver")
  362. translate([0,0,-1.2+(3.18)/2-0.9])
  363. cylinder(d2 = 3.5,d1 = 6,h=1);
  364. translate([0,0,-l/2 +roller_dia/2 -2])
  365. threaded_rod(d=6, l=l, pitch=1.0);
  366. }
  367. }
  368. translate([0,0,$e -l/2 +roller_dia/2 -2])
  369. threaded_rod(d=6.1, l=l, pitch=1.0);
  370. if (cut_roller_holder)
  371. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -l*2])
  372. cube([roller_thread_dia + 2, roller_thread_dia, l*4]);
  373. }
  374. }
  375. }
  376. module roller_mount() {
  377. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  378. difference() {
  379. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  380. translate([0, 0, 1])
  381. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  382. if (cut_roller_holder)
  383. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  384. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  385. }
  386. }
  387. }
  388. module roller_mount_test() {
  389. roller_holder();
  390. roller_mount();
  391. }
  392. module roller_mount_tri_hull() {
  393. for (r = [0 : roller_count - 1])
  394. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  395. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  396. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  397. translate([0, 0, -roller_h])
  398. cylinder(d = roller_mount_dia + wall + 1, h = roller_h - 3);
  399. translate([0, 0, -ball_dia / 2 - 11])
  400. cylinder(d = base_dia, h = $e);
  401. }
  402. module roller_mount_tri_body() {
  403. // space for roller holder
  404. for (r = [0 : roller_count - 1])
  405. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  406. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  407. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  408. translate([0, 0, -roller_h])
  409. cylinder(d = roller_mount_dia + roller_mount_holder_gap, h = ball_dia / 2 + roller_h);
  410. // room for ball itself
  411. sphere($fn = $fn * 2, d = ball_dia + $c * 2 + 4);
  412. // grub screws
  413. for (r = [0 : roller_count - 1])
  414. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  415. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  416. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  417. translate([0, 0, -roller_h/2])
  418. rotate([0,-90,0])
  419. translate([-2, 0, 2]) {
  420. cylinder(d = grub_screw_dia, h = ball_dia);
  421. translate([0, 0, roller_mount_dia / 4 + wall])
  422. cylinder(d = grub_channel_dia, h = ball_dia);
  423. }
  424. // sensor lens
  425. translate([0, 0, -ball_dia / 2 - ball_h])
  426. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  427. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0])
  428. sensor_lens_cutout();
  429. // sensor pcb
  430. translate([-1, -1, -ball_dia / 2 - ball_h])
  431. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  432. translate([-sensor_w / 2, -sensor_l / 2, -10])
  433. cube([sensor_w + 2, sensor_l + 2, sensor_pcb_h + 10 + sensor_pcb_mount_gap]);
  434. }
  435. module roller_mount_sensor_pcb_support() {
  436. translate([-sensor_w / 2, -sensor_l / 2, sensor_pcb_h])
  437. translate([0, 0, -ball_dia / 2 - ball_h])
  438. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  439. for (x = [0, sensor_hole_dist_x])
  440. for (y = [0, sensor_hole_dist_y])
  441. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, 0])
  442. difference() {
  443. union() {
  444. color("magenta")
  445. cylinder(d = sensor_hole_dia + 1.5, h = sensor_pcb_mount_gap);
  446. if (draw_supports)
  447. color("black")
  448. translate([0, 0, -sensor_pcb_support_h])
  449. cylinder(d = sensor_hole_dia + 0.5, h = sensor_pcb_support_h);
  450. }
  451. cylinder(d = sensor_hole_dia - 0.2, h = sensor_pcb_mount_gap + 1);
  452. }
  453. if (draw_supports)
  454. color("black")
  455. for (x = [-5, 0, 5])
  456. for (y = [-8, 0, 6.5])
  457. if (((x == 0) && (y != 0)) || ((x != 0) && (y == 0)))
  458. translate([x, y + 2, -30])
  459. cylinder(d = sensor_hole_dia + 0.5, h = 8.5);
  460. if (draw_sensor)
  461. %translate([0, 0, -ball_dia / 2 - ball_h])
  462. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  463. sensor();
  464. }
  465. // TODO holes for pcb screws not going into body!!
  466. module roller_mount_tri() {
  467. if (draw_ball_roller)
  468. %ball_and_roller();
  469. difference() {
  470. hull()
  471. roller_mount_tri_hull();
  472. roller_mount_tri_body();
  473. // TODO test cable cutout
  474. translate([-6, 0, -30.1])
  475. cube([12, 50, 2]);
  476. if (cut_roller_holder)
  477. translate([0, -base_dia / 2 - 1, -40])
  478. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  479. }
  480. roller_mount_sensor_pcb_support();
  481. }
  482. module fully_rounded_cube(p,r,center) {
  483. for(x=[r,p[0]-r],
  484. y=[r,p[1]-r],
  485. z=[r,p[2]-r]
  486. ){
  487. translate([x,y,z])
  488. sphere(r,$fn=$fn/8);
  489. }
  490. }
  491. module trackball_top() {
  492. translate([0, 0, ball_dia / 2 + ball_h]) {
  493. if (draw_ball_roller)
  494. %ball_and_roller();
  495. difference() {
  496. color("orange")
  497. hull() {
  498. r=4;
  499. roller_mount_tri_hull();
  500. for ( i = [0:len(sw)-1] ){
  501. rotate([0,0,sw[i][0][2]])
  502. translate(sw[i][1])
  503. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  504. translate([-sw_mount_w/2-r, -sw_mount_w/2-r, -r-r/2])
  505. fully_rounded_cube([sw_mount_w+r*2, sw_mount_w+r*2, 0], r);
  506. }
  507. }
  508. roller_mount_tri_body();
  509. if (cut_roller_holder)
  510. translate([0, -base_dia, -base_dia])
  511. cube([base_dia *2 , base_dia * 2, base_dia*2]);
  512. for ( i = [0:len(sw)-1] ){
  513. rotate([0,0,sw[i][0][2]])
  514. translate(sw[i][1])
  515. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  516. translate([0, 0, -sw_mount_co_l]) {
  517. mx_switch_cutout(sw_mount_co_l + 1);
  518. translate([0, 0, 2])
  519. rotate([90, 0, 0])
  520. cylinder(d = 4, h = 20);
  521. rotate([0,-sw[i][0][1],0])
  522. translate([0,-15,3])
  523. rotate([0,180,0])
  524. cylinder(d=3,h=40);
  525. }
  526. }
  527. for (r = screw_angles)
  528. rotate([0, 0, r])
  529. translate([screw_off, 0, -ball_dia / 2 - 11 -1]) {
  530. cylinder(d = screw_insert_dia, h = screw_insert_h + 1);
  531. }
  532. for (x = [0, pico_hole_d_x])
  533. for (y = [0, pico_hole_d_y])
  534. rotate([0,0,0])
  535. translate([-pico_w / 2, -pico_l / 2, -25])
  536. translate([pico_hole_x + x, pico_hole_y + y, -pico_d - pico_screw_depth])
  537. cylinder(d = pico_screw_d, h = pico_d + pico_screw_depth + 1);
  538. rotate([0, 180, 0])
  539. translate([-pico_w / 2, -pico_l / 2, 0])
  540. translate([(pico_w - pico_usb_w) / 2, pico_l - 1 + pico_usb_off, 30])
  541. usb_cutout();
  542. }
  543. roller_mount_sensor_pcb_support();
  544. if (draw_switches)
  545. for ( i = [0:len(sw)-1] ){
  546. %rotate([0,0,sw[i][0][2]])
  547. translate(sw[i][1])
  548. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  549. translate([0, 0, 1.])
  550. mx_switch($t);
  551. }
  552. if (draw_keycap)
  553. for ( i = [0:len(sw)-1] ){
  554. %rotate([0,0,sw[i][0][2]])
  555. translate(sw[i][1])
  556. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  557. translate([0, 0, 1.])
  558. mx_switch($t);
  559. }
  560. }
  561. }
  562. module trackball_bottom_wrap() {
  563. color("magenta")
  564. translate([0, 0, -3.0])
  565. difference() {
  566. cylinder(d = base_dia, h = bottom_base_below_zero + ball_h - 16);
  567. translate([0, 0, bottom_base_wall])
  568. cylinder(d = base_dia - bottom_base_wall * 2 - bottom_add_wall, h = bottom_base_below_zero + ball_h - 15);
  569. translate([-pico_co_w / 2, -pico_co_l / 2, 2.5])
  570. cube([pico_co_w, pico_co_l, bottom_base_below_zero + ball_h - 11]);
  571. translate([pico_w / 2 - reset_button_off_x, pico_l / 2 - reset_button_off_y, -1])
  572. cylinder(d = reset_button_dia, h = bottom_base_wall + 2);
  573. }
  574. color("cyan")
  575. for (r = screw_angles)
  576. rotate([0, 0, r])
  577. translate([screw_off, 0, -3])
  578. cylinder(d = screw_head_d + 4, h = bottom_base_below_zero + ball_h - 16 );
  579. }
  580. module usb_cutout() {
  581. translate([8,1,4.5])
  582. rotate([0,180,0]) {
  583. translate([-usb_cutout_w_add / 2, -2, -usb_cutout_h_add / 2])
  584. cube([pico_usb_w + usb_cutout_w_add, 5, pico_usb_h + usb_cutout_h_add]);
  585. hull() {
  586. translate([-usb_cutout_w_add / 2, 1, -usb_cutout_h_add / 2])
  587. cube([pico_usb_w + usb_cutout_w_add, $e, pico_usb_h + usb_cutout_h_add]);
  588. translate([-usb_cutout_grow_x / 2, 1+usb_cutout_grow_l, -usb_cutout_grow_y / 2])
  589. cube([pico_usb_w + usb_cutout_grow_x, $e, pico_usb_h + usb_cutout_grow_y]);
  590. translate([-usb_cutout_grow_x / 2, 1+usb_cutout_grow_l*10, -usb_cutout_grow_y / 2])
  591. cube([pico_usb_w + usb_cutout_grow_x, $e, pico_usb_h + usb_cutout_grow_y]);
  592. }
  593. }
  594. }
  595. module trackball_bottom() {
  596. difference() {
  597. trackball_bottom_wrap();
  598. translate([0, 0, ball_dia / 2 + ball_h])
  599. rotate([0, 180, 0])
  600. translate([-pico_w / 2, -pico_l / 2, 0])
  601. translate([(pico_w - pico_usb_w) / 2, pico_l - 1 + pico_usb_off, 30])
  602. usb_cutout();
  603. for (r = screw_angles)
  604. rotate([0, 0, r])
  605. translate([screw_off, 0, -$e-3]) {
  606. cylinder(d = screw_dia, h = bottom_base_below_zero + 30);
  607. cylinder(d = screw_head_d, h = screw_head_h + 1);
  608. }
  609. }
  610. }
  611. module assembly() {
  612. translate([0, 0, assembly_dist / 2])
  613. trackball_top();
  614. translate([0, 0, -assembly_dist / 2])
  615. trackball_bottom();
  616. }
  617. module print() {
  618. translate([-40, 0, -4])
  619. trackball_top();
  620. translate([40, 0, bottom_base_below_zero])
  621. trackball_bottom();
  622. for (y = [-20, 0, 20])
  623. translate([0, y, 8.5])
  624. roller_holder();
  625. }