3D printed Arduino Airsoft Chronograph
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.

openchrono.scad 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. outer_dia = 55;
  2. inner_dia = 8.5;
  3. height = 100;
  4. body_gap = 0.1;
  5. body_screw_off = 10;
  6. body_screw_pos = 20;
  7. body_screw_dia = 3.3;
  8. body_screw_head = 6.0;
  9. body_screw_depth = 3.2;
  10. body_screw_insert_dia = 4.8;
  11. body_screw_insert_height = 12.0;
  12. lcd_pcb_w = 29.0;
  13. lcd_pcb_h = 29.0;
  14. lcd_pcb_d = 5.2;
  15. lcd_hole_dia = 1.9;
  16. lcd_hole_w = 6.0;
  17. lcd_hole_h = 2.5;
  18. lcd_off = 10.0;
  19. lcd_hole_off_x = 23.1;
  20. lcd_hole_off_y = 23.65;
  21. lcd_hole_off_y_total = 0.4;
  22. lcd_hole_screw_len = 10.0;
  23. arduino_w = 19.0;
  24. arduino_h = 46.5 + 10;
  25. arduino_d = 10.0;
  26. bat_w = 11.5;
  27. bat_l = 45.5;
  28. bat_tab_w = 9.5;
  29. bat_tab_h = 8.5;
  30. bat_tab_d = 2.5; // TODO?
  31. bat_tab_con_w = 5.0; // TODO?
  32. bat_tab_con_h = 6.5; // TODO?
  33. bat_spring_w = 7.5; // TODO?
  34. bat_spring_dist = 7.5; // TODO?
  35. bat_wall = 1.0;
  36. bat_angle = 48;
  37. led_dia = 3.3;
  38. led_l = 4.5;
  39. led_off = 15;
  40. led_ridge_dia = 4.2;
  41. led_ridge_h = 1.6;
  42. switch_w = 12.0;
  43. switch_h = 6.5;
  44. switch_d = 10.0;
  45. switch_plate_w = 20.5;
  46. switch_plate_h = switch_h;
  47. switch_dia = 2.4;
  48. switch_screw_l = 10.0;
  49. switch_screw_d = 15.0;
  50. switch_off = 15;
  51. bat_h = bat_l + bat_spring_dist + 2 * bat_wall + 2 * bat_tab_d;
  52. $fn = 42;
  53. echo("sensor_distance", height - 2 * led_off);
  54. // https://dkprojects.net/openscad-threads/
  55. include <extern/threads.scad>
  56. // 1911
  57. thread_profile_1911 = [
  58. true, // type is_male
  59. 12.0, // diameter
  60. 1.0, // pitch
  61. 0.0, // offset
  62. 9.0 // length
  63. ];
  64. // M14x1.0 female thread
  65. thread_profile_m14 = [
  66. false, // type is_male
  67. 14.0, // diameter
  68. 1.0, // pitch
  69. 0.0, // offset
  70. 12.0 // length
  71. ];
  72. // ASG / KWC Cobray Ingram M11 CO2 NBB 6mm
  73. thread_profile_mac11 = [
  74. false, // type is_male
  75. 16.5, // diameter
  76. 1.5, // pitch
  77. 8.0, // offset
  78. 10.0 // length
  79. ];
  80. // debug / testing
  81. thread_profile_none = [ false, 0, 0, 0, 0 ];
  82. thread_profiles = [
  83. thread_profile_1911,
  84. thread_profile_m14,
  85. thread_profile_mac11
  86. ];
  87. thread_base = 5.0;
  88. test_bat_w = 47;
  89. test_bat_h = 59;
  90. test_bat_d = 15;
  91. test_bat_dia = 2.9;
  92. test_bat_off = 30.5;
  93. test_bat_l = 8;
  94. thread_adapter_screw_inset = 5;
  95. thread_adapter_in_body = 5;
  96. thread_adapter_h = body_screw_insert_height - thread_adapter_in_body;
  97. enable_gap_support = true;
  98. text1 = [
  99. "OpenChrono",
  100. "Liberation Sans:style=Bold",
  101. 12.0,
  102. 2.0,
  103. 55
  104. ];
  105. text2 = [
  106. "by xythobuz.de",
  107. "Liberation Sans:style=Bold",
  108. 9.0,
  109. 2.0,
  110. -60
  111. ];
  112. texts_left = [ text1, text2 ];
  113. include_uv_leds = true;
  114. // how deep things on the outside have to be set in
  115. function circle_offset_deviation(off, dia) =
  116. dia * (1 - sin(acos(off * 2 / dia))) / 2;
  117. module lcd_cutout() {
  118. difference() {
  119. cube([lcd_pcb_w, lcd_pcb_h, lcd_pcb_d + 10]);
  120. for (x = [0, lcd_pcb_w - lcd_hole_w])
  121. for (y = [0, lcd_pcb_h - lcd_hole_w])
  122. translate([x, y, -1])
  123. cube([lcd_hole_w, lcd_hole_w, lcd_hole_h + 1]);
  124. // TODO hacky
  125. if (enable_gap_support)
  126. translate([0, (lcd_pcb_w - 1) / 2, 0])
  127. cube([lcd_pcb_w, 1, 9]);
  128. }
  129. for (x = [0, lcd_hole_off_x])
  130. for (y = [0, lcd_hole_off_y])
  131. translate([x + lcd_hole_w / 2, y + lcd_hole_w / 2 - lcd_hole_off_y_total, lcd_hole_h - lcd_hole_screw_len])
  132. cylinder(d = lcd_hole_dia, h = lcd_hole_screw_len + 1);
  133. }
  134. module arduino_cutout() {
  135. cube([arduino_w, arduino_h, arduino_d]);
  136. }
  137. module bat_cutout() {
  138. // battery
  139. translate([0, 0, bat_tab_d + bat_wall])
  140. cube([bat_w, bat_w, bat_l + bat_spring_dist]);
  141. // negative terminal
  142. for (z = [0, bat_l + bat_spring_dist + 2 * bat_wall + bat_tab_d])
  143. translate([(bat_w - bat_tab_w) / 2, (bat_w - bat_tab_h) / 2, z])
  144. cube([bat_tab_w, bat_tab_h + (bat_w - bat_tab_h) / 2, bat_tab_d]);
  145. // spring
  146. for (z = [bat_tab_d, bat_l + bat_spring_dist + bat_wall + bat_tab_d])
  147. translate([(bat_w - bat_spring_w) / 2, (bat_w - bat_spring_w) / 2, z - 0.1])
  148. cube([bat_spring_w, bat_spring_w + (bat_w - bat_spring_w) / 2, bat_wall + 0.2]);
  149. }
  150. module switch_cutout() {
  151. translate([-switch_w / 2, -10, -switch_h / 2])
  152. cube([switch_w, switch_d + 10, switch_h]);
  153. translate([-switch_plate_w / 2, -switch_d, -switch_plate_h / 2])
  154. cube([switch_plate_w, 10, switch_plate_h]);
  155. for (x = [1, -1])
  156. scale([x, 1, 1])
  157. translate([-switch_screw_d / 2, -10, 0])
  158. rotate([-90, 0, 0])
  159. cylinder(d = switch_dia, h = switch_screw_l + 10);
  160. }
  161. module thread(profile, thread_draw) {
  162. if (profile[0]) {
  163. // male thread
  164. difference() {
  165. union() {
  166. cylinder(d = outer_dia, h = thread_base);
  167. metric_thread(profile[1], profile[2], profile[4] + thread_base, test=!thread_draw);
  168. }
  169. translate([0, 0, -1])
  170. cylinder(d = inner_dia, h = profile[4] + thread_base + 2);
  171. }
  172. } else {
  173. // female thread
  174. difference() {
  175. cylinder(d = outer_dia, h = thread_base + profile[4] + profile[3]);
  176. metric_thread(profile[1], profile[2], profile[4] + thread_base + 1, true, test=!thread_draw);
  177. translate([0, 0, thread_base + profile[4]])
  178. cylinder(d = profile[1] + 2, h = profile[3] + 1);
  179. translate([0, 0, -1])
  180. cylinder(d = inner_dia, h = profile[4] + thread_base + profile[3] + 2);
  181. }
  182. }
  183. }
  184. module thread_profile_adapter(profile, draw_profile) {
  185. difference() {
  186. thread(profile, draw_profile);
  187. for (r = [45, -45])
  188. for (r2 = [0, 180])
  189. rotate([0, 0, r + r2])
  190. translate([0, (outer_dia - body_screw_insert_dia) / 2 - thread_adapter_screw_inset, -1])
  191. cylinder(d = body_screw_dia, h = 100);
  192. }
  193. }
  194. module thread_adapter() {
  195. difference() {
  196. cylinder(d = outer_dia, h = thread_adapter_h);
  197. translate([0, 0, -1])
  198. cylinder(d = inner_dia, h = thread_adapter_h + 2);
  199. for (r = [45, -45])
  200. rotate([0, 0, r])
  201. translate([0, (outer_dia - body_screw_insert_dia) / 2 - thread_adapter_screw_inset, -thread_adapter_in_body])
  202. cylinder(d = body_screw_insert_dia, h = body_screw_insert_height + 1);
  203. }
  204. }
  205. module half_body(right_side) {
  206. difference() {
  207. union() {
  208. // body
  209. cylinder(d = outer_dia, h = height);
  210. translate([0, 0, height])
  211. thread_adapter();
  212. }
  213. // inner tube
  214. translate([0, 0, -1])
  215. cylinder(d = inner_dia, h = height + 2);
  216. // remove half of cylinder
  217. translate([-outer_dia / 2 - 1, -outer_dia + body_gap / 2, -1])
  218. cube([outer_dia + 2, outer_dia, height + 2]);
  219. // led cutouts
  220. for (x = [1, -1])
  221. scale([x, 1, 1])
  222. for (z = [led_off, height - led_off])
  223. translate([inner_dia / 2 - 1, 0, z])
  224. rotate([0, 90, 0]) {
  225. cylinder(d = led_dia, h = led_l + led_ridge_h + 1);
  226. translate([0, 0, led_l + 1])
  227. cylinder(d = led_ridge_dia, h = led_ridge_h);
  228. }
  229. if (include_uv_leds)
  230. for (x = [1, -1])
  231. scale([x, 1, 1])
  232. translate([inner_dia / 2 - 1, 0, led_off / 2])
  233. rotate([0, 90, 0]) {
  234. cylinder(d = led_dia, h = led_l + led_ridge_h + 1);
  235. translate([0, 0, led_l + 1])
  236. cylinder(d = led_ridge_dia, h = led_ridge_h);
  237. }
  238. // TODO hacky sensor cable, arduino side
  239. for (z = [1, -1])
  240. translate([0, 0, height / 2])
  241. scale([right_side ? -1 : 1, 1, z])
  242. translate([0, 0, height / 2 - led_off])
  243. hull() {
  244. for (x = [0, 5])
  245. translate([-inner_dia / 2 - led_l - led_ridge_h - x, 0, 0])
  246. rotate([0, 90, 0])
  247. cylinder(d = led_ridge_dia, h = led_ridge_h);
  248. translate([-inner_dia / 2 - led_l - led_ridge_h - 5, 0, -10])
  249. cylinder(d = led_ridge_dia, h = led_ridge_h);
  250. }
  251. // TODO hacky led cable, led side
  252. for (z = [1, -1])
  253. translate([0, 0, height / 2])
  254. scale([right_side ? 1 : -1, 1, z])
  255. translate([0, 0, height / 2 - led_off])
  256. hull() {
  257. for (x = [0, 5])
  258. translate([-inner_dia / 2 - led_l - led_ridge_h - x, 0, 0])
  259. rotate([0, 90, 0])
  260. cylinder(d = led_ridge_dia, h = led_ridge_h);
  261. translate([-inner_dia / 2 - led_l - led_ridge_h - 5, 0, -height / 2 + led_off - 1])
  262. cube([led_ridge_dia + 2, led_ridge_dia - 2, led_ridge_h]);
  263. if (include_uv_leds)
  264. if (z < 0)
  265. for (x = [0, 5])
  266. translate([-inner_dia / 2 - led_l - led_ridge_h - x, 0, led_off / 2])
  267. rotate([0, 90, 0])
  268. cylinder(d = led_ridge_dia, h = led_ridge_h);
  269. }
  270. }
  271. }
  272. module screw_holes(with_head) {
  273. for (x = [body_screw_pos, -body_screw_pos])
  274. for (z = [body_screw_off, height - body_screw_off])
  275. translate([x, 0, z])
  276. rotate([-90, 0, 0]) {
  277. translate([0, 0, -1])
  278. if (with_head)
  279. cylinder(d = body_screw_dia, h = outer_dia / 2 + 2);
  280. else
  281. cylinder(d = body_screw_insert_dia, h = body_screw_insert_height);
  282. if (with_head)
  283. translate([0, 0, outer_dia / 2 - circle_offset_deviation(body_screw_pos + body_screw_head / 2, outer_dia) - body_screw_depth - 2])
  284. cylinder(d = body_screw_head, h = 50);
  285. }
  286. }
  287. module left_half() {
  288. difference() {
  289. half_body(false);
  290. translate([-outer_dia / 2 - 1, -outer_dia / 2 - 1 + body_gap / 2, height - 1])
  291. cube([outer_dia + 2, outer_dia / 2 + 1, 50]);
  292. screw_holes(false);
  293. translate([0, outer_dia / 2 - circle_offset_deviation(lcd_pcb_h / 2, outer_dia) - lcd_pcb_d, height / 2 + lcd_off])
  294. rotate([0, 90, 0])
  295. translate([lcd_pcb_w / 2, 0, -lcd_pcb_h / 2])
  296. rotate([90, 0, 180])
  297. lcd_cutout();
  298. translate([-outer_dia / 2 + ((outer_dia / 2) - (inner_dia / 2) - arduino_w) / 2, arduino_d / 2, -arduino_h / 2 + height / 2])
  299. rotate([90, 0, 0])
  300. arduino_cutout();
  301. translate([0, outer_dia / 2 - circle_offset_deviation(switch_plate_w / 2, outer_dia), height / 2 - switch_off])
  302. rotate([0, 0, 180])
  303. switch_cutout();
  304. // TODO hacky switch cable
  305. translate([-16, -10, height / 2 - switch_off])
  306. rotate([-90, 0, -27])
  307. cylinder(d = switch_h - 2, h = outer_dia);
  308. // TODO hacky lcd cable
  309. translate([-15, -10, 60])
  310. rotate([-90, 0, -12])
  311. cylinder(d = 6.0, h = outer_dia);
  312. // TODO hacky led cable
  313. translate([0, 0, height / 2 + 3]) {
  314. translate([inner_dia / 2 + led_l + led_ridge_dia / 2, led_ridge_h + inner_dia / 2 + 2, 0])
  315. rotate([90, 0, 0])
  316. cylinder(d = led_ridge_dia, h = led_ridge_h + inner_dia / 2 + 2);
  317. hull() {
  318. translate([inner_dia / 2 + led_l + led_ridge_dia / 2, led_ridge_h + inner_dia / 2 + 2, 0])
  319. rotate([90, 0, 0])
  320. cylinder(d = led_ridge_dia, h = led_ridge_h);
  321. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 5, led_ridge_h + inner_dia / 2 + 2, 0])
  322. rotate([0, 90, 0])
  323. cylinder(d = led_ridge_dia, h = led_ridge_h + 5);
  324. }
  325. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  326. rotate([0, 90, 0])
  327. cylinder(d = led_ridge_dia, h = led_ridge_h + 25);
  328. hull() {
  329. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  330. rotate([90, 0, 0])
  331. cylinder(d = led_ridge_dia, h = led_ridge_h + 10);
  332. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  333. rotate([0, 90, 0])
  334. cylinder(d = led_ridge_dia, h = led_ridge_h);
  335. }
  336. }
  337. for (t = texts_left)
  338. rotate([0, 0, -t[4]])
  339. translate([0, outer_dia / 2 - t[3], (height + thread_adapter_h) / 2])
  340. rotate([0, -90, -90])
  341. linear_extrude(height = t[3] + 1)
  342. text(t[0], size = t[2], font = t[1], halign = "center", valign="center");
  343. }
  344. }
  345. module right_half() {
  346. difference() {
  347. half_body(true);
  348. translate([-outer_dia / 2 - 1, -outer_dia / 2 - 1 + body_gap / 2, height - 1])
  349. cube([outer_dia + 2, outer_dia / 2 + 1, 50]);
  350. screw_holes(true);
  351. translate([outer_dia / 2 - arduino_w -((outer_dia / 2) - (inner_dia / 2) - arduino_w) / 2, arduino_d / 2, -arduino_h / 2 + height / 2])
  352. rotate([90, 0, 0])
  353. arduino_cutout();
  354. }
  355. }
  356. module right_half_aaa_bat() {
  357. difference() {
  358. right_half();
  359. for (a = [0, bat_angle, -bat_angle])
  360. rotate([0, 0, a])
  361. translate([-bat_w / 2, outer_dia / 2 - bat_w, (height - bat_h) / 2])
  362. bat_cutout();
  363. }
  364. }
  365. module right_half_testing() {
  366. difference() {
  367. right_half();
  368. difference() {
  369. translate([-test_bat_w / 2, outer_dia / 2 - circle_offset_deviation(test_bat_w / 2, outer_dia), (height - test_bat_h) / 2])
  370. cube([test_bat_w, test_bat_d + 1, test_bat_h]);
  371. // TODO hacky
  372. if (enable_gap_support)
  373. translate([-0.5, 14, 20])
  374. cube([1, 13, test_bat_h + 2]);
  375. }
  376. for (x = [test_bat_off / 2, -test_bat_off / 2])
  377. translate([x, outer_dia / 2 - circle_offset_deviation(test_bat_w / 2, outer_dia) - test_bat_l, height / 2])
  378. rotate([-90, 0, 0])
  379. cylinder(d = test_bat_dia, h = outer_dia / 2);
  380. // TODO hacky power cable
  381. translate([15, -10, 60])
  382. rotate([-90, 0, 12])
  383. cylinder(d = 6.0, h = outer_dia);
  384. }
  385. }
  386. module assembly_closed() {
  387. //right_half_aaa_bat();
  388. right_half_testing();
  389. rotate([0, 0, 180])
  390. left_half();
  391. translate([0, 0, height + thread_adapter_h + 0.5])
  392. thread_profile_adapter(thread_profiles[0], false);
  393. }
  394. module assembly_opened(angle) {
  395. translate([-outer_dia / 2, 0, 0]) {
  396. //rotate([0, 0, angle / 2])
  397. //translate([outer_dia / 2, 0, 0])
  398. //right_half_aaa_bat();
  399. rotate([0, 0, angle / 2])
  400. translate([outer_dia / 2, 0, 0])
  401. right_half_testing();
  402. rotate([0, 0, -angle / 2])
  403. translate([outer_dia / 2, 0, 0])
  404. rotate([0, 0, 180])
  405. left_half();
  406. }
  407. }
  408. module print(all_thread_adapters) {
  409. translate([outer_dia / 2 + 5, 0, 0])
  410. left_half();
  411. //translate([-outer_dia / 2 - 5, 0, 0])
  412. //right_half_aaa_bat(true);
  413. translate([-outer_dia / 2 - 5, 0, 0])
  414. right_half_testing();
  415. if (all_thread_adapters)
  416. for (p = [0 : len(thread_profiles) - 1])
  417. translate([(p - floor(len(thread_profiles) / 2)) * (outer_dia + 5), -outer_dia / 2 - 5, 0])
  418. thread_profile_adapter(thread_profiles[p], true);
  419. }
  420. //lcd_cutout();
  421. //left_half();
  422. //right_half();
  423. //assembly_closed();
  424. //assembly_opened(90);
  425. //print(true);
  426. print(false);