暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

trackball.scad 22KB

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