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 22KB

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