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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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.2;
  8. body_screw_head = 5.8;
  9. body_screw_depth = 3.2;
  10. body_screw_insert_dia = 5.0;
  11. body_screw_insert_height = 15.0;
  12. lcd_pcb_w = 29.0;
  13. lcd_pcb_h = 29.0;
  14. lcd_pcb_d = 5.2;
  15. lcd_hole_dia = 2.0;
  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.6;
  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_profile = thread_profile_m14;
  83. thread_base = 1.0;
  84. // how deep things on the outside have to be set in
  85. function circle_offset_deviation(off, dia) =
  86. dia * (1 - sin(acos(off * 2 / dia))) / 2;
  87. module lcd_cutout() {
  88. difference() {
  89. cube([lcd_pcb_w, lcd_pcb_h, lcd_pcb_d + 10]);
  90. for (x = [0, lcd_pcb_w - lcd_hole_w])
  91. for (y = [0, lcd_pcb_h - lcd_hole_w])
  92. translate([x, y, -1])
  93. cube([lcd_hole_w, lcd_hole_w, lcd_hole_h + 1]);
  94. }
  95. for (x = [0, lcd_hole_off_x])
  96. for (y = [0, lcd_hole_off_y])
  97. translate([x + lcd_hole_w / 2, y + lcd_hole_w / 2 - lcd_hole_off_y_total, lcd_hole_h - lcd_hole_screw_len])
  98. cylinder(d = lcd_hole_dia, h = lcd_hole_screw_len + 1);
  99. }
  100. module arduino_cutout() {
  101. cube([arduino_w, arduino_h, arduino_d]);
  102. }
  103. module bat_cutout() {
  104. // battery
  105. translate([0, 0, bat_tab_d + bat_wall])
  106. cube([bat_w, bat_w, bat_l + bat_spring_dist]);
  107. // negative terminal
  108. for (z = [0, bat_l + bat_spring_dist + 2 * bat_wall + bat_tab_d])
  109. translate([(bat_w - bat_tab_w) / 2, (bat_w - bat_tab_h) / 2, z])
  110. cube([bat_tab_w, bat_tab_h + (bat_w - bat_tab_h) / 2, bat_tab_d]);
  111. // spring
  112. for (z = [bat_tab_d, bat_l + bat_spring_dist + bat_wall + bat_tab_d])
  113. translate([(bat_w - bat_spring_w) / 2, (bat_w - bat_spring_w) / 2, z - 0.1])
  114. cube([bat_spring_w, bat_spring_w + (bat_w - bat_spring_w) / 2, bat_wall + 0.2]);
  115. }
  116. module switch_cutout() {
  117. translate([-switch_w / 2, -10, -switch_h / 2])
  118. cube([switch_w, switch_d + 10, switch_h]);
  119. translate([-switch_plate_w / 2, -switch_d, -switch_plate_h / 2])
  120. cube([switch_plate_w, 10, switch_plate_h]);
  121. for (x = [1, -1])
  122. scale([x, 1, 1])
  123. translate([-switch_screw_d / 2, -10, 0])
  124. rotate([-90, 0, 0])
  125. cylinder(d = switch_dia, h = switch_screw_l + 10);
  126. }
  127. module thread(profile, thread_draw) {
  128. if (profile[0]) {
  129. // male thread
  130. difference() {
  131. union() {
  132. cylinder(d = outer_dia, h = thread_base);
  133. metric_thread(profile[1], profile[2], profile[4] + thread_base, test=!thread_draw);
  134. }
  135. translate([0, 0, -1])
  136. cylinder(d = inner_dia, h = profile[4] + thread_base + 2);
  137. }
  138. } else {
  139. // female thread
  140. difference() {
  141. cylinder(d = outer_dia, h = thread_base + profile[4] + profile[3]);
  142. metric_thread(profile[1], profile[2], profile[4] + thread_base + 1, true, test=!thread_draw);
  143. translate([0, 0, thread_base + profile[4]])
  144. cylinder(d = profile[1] + 2, h = profile[3] + 1);
  145. translate([0, 0, -1])
  146. cylinder(d = inner_dia, h = profile[4] + thread_base + profile[3] + 2);
  147. }
  148. }
  149. }
  150. module half_body(right_side) {
  151. difference() {
  152. // body
  153. cylinder(d = outer_dia, h = height);
  154. // inner tube
  155. translate([0, 0, -1])
  156. cylinder(d = inner_dia, h = height + 2);
  157. // remove half of cylinder
  158. translate([-outer_dia / 2 - 1, -outer_dia + body_gap / 2, -1])
  159. cube([outer_dia + 2, outer_dia, height + 2]);
  160. // led cutouts
  161. for (x = [1, -1])
  162. scale([x, 1, 1])
  163. for (z = [led_off, height - led_off])
  164. translate([inner_dia / 2 - 1, 0, z])
  165. rotate([0, 90, 0]) {
  166. cylinder(d = led_dia, h = led_l + led_ridge_h + 1);
  167. translate([0, 0, led_l + 1])
  168. cylinder(d = led_ridge_dia, h = led_ridge_h);
  169. }
  170. // TODO hacky sensor cable, arduino side
  171. for (z = [1, -1])
  172. translate([0, 0, height / 2])
  173. scale([right_side ? -1 : 1, 1, z])
  174. translate([0, 0, height / 2 - led_off])
  175. hull() {
  176. for (x = [0, 5])
  177. translate([-inner_dia / 2 - led_l - led_ridge_h - x, 0, 0])
  178. rotate([0, 90, 0])
  179. cylinder(d = led_ridge_dia, h = led_ridge_h);
  180. translate([-inner_dia / 2 - led_l - led_ridge_h - 5, 0, -10])
  181. cylinder(d = led_ridge_dia, h = led_ridge_h);
  182. }
  183. // TODO hacky led cable, led side
  184. for (z = [1, -1])
  185. translate([0, 0, height / 2])
  186. scale([right_side ? 1 : -1, 1, z])
  187. translate([0, 0, height / 2 - led_off])
  188. hull() {
  189. for (x = [0, 5])
  190. translate([-inner_dia / 2 - led_l - led_ridge_h - x, 0, 0])
  191. rotate([0, 90, 0])
  192. cylinder(d = led_ridge_dia, h = led_ridge_h);
  193. translate([-inner_dia / 2 - led_l - led_ridge_h - 5, 0, -height / 2 + led_off - 1])
  194. cube([led_ridge_dia + 2, led_ridge_dia - 2, led_ridge_h]);
  195. }
  196. }
  197. }
  198. module screw_holes(with_head) {
  199. for (x = [body_screw_pos, -body_screw_pos])
  200. for (z = [body_screw_off, height - body_screw_off])
  201. translate([x, 0, z])
  202. rotate([-90, 0, 0]) {
  203. translate([0, 0, -1])
  204. if (with_head)
  205. cylinder(d = body_screw_dia, h = outer_dia / 2 + 2);
  206. else
  207. cylinder(d = body_screw_insert_dia, h = body_screw_insert_height);
  208. if (with_head)
  209. translate([0, 0, outer_dia / 2 - circle_offset_deviation(body_screw_pos + body_screw_head / 2, outer_dia) - body_screw_depth - 2])
  210. cylinder(d = body_screw_head, h = 50);
  211. }
  212. }
  213. module left_half(thread_draw) {
  214. difference() {
  215. union() {
  216. half_body(false);
  217. translate([0, 0, height])
  218. thread(thread_profile, thread_draw);
  219. }
  220. translate([-outer_dia / 2 - 1, -outer_dia / 2 - 1 + body_gap / 2, height - 1])
  221. cube([outer_dia + 2, outer_dia / 2 + 1, 50]);
  222. screw_holes(false);
  223. translate([0, outer_dia / 2 - circle_offset_deviation(lcd_pcb_h / 2, outer_dia) - lcd_pcb_d, height / 2 + lcd_off])
  224. rotate([0, 90, 0])
  225. translate([lcd_pcb_w / 2, 0, -lcd_pcb_h / 2])
  226. rotate([90, 0, 180])
  227. lcd_cutout();
  228. translate([-outer_dia / 2 + ((outer_dia / 2) - (inner_dia / 2) - arduino_w) / 2, arduino_d / 2, -arduino_h / 2 + height / 2])
  229. rotate([90, 0, 0])
  230. arduino_cutout();
  231. translate([0, outer_dia / 2 - circle_offset_deviation(switch_plate_w / 2, outer_dia), height / 2 - switch_off])
  232. rotate([0, 0, 180])
  233. switch_cutout();
  234. // TODO hacky switch cable
  235. translate([-16, -10, height / 2 - switch_off])
  236. rotate([-90, 0, -27])
  237. cylinder(d = switch_h - 2, h = outer_dia);
  238. // TODO hacky lcd cable
  239. translate([-15, -10, 60])
  240. rotate([-90, 0, -12])
  241. cylinder(d = 6.0, h = outer_dia);
  242. // TODO hacky led cable
  243. translate([0, 0, height / 2 + 3]) {
  244. translate([inner_dia / 2 + led_l + led_ridge_dia / 2, led_ridge_h + inner_dia / 2 + 2, 0])
  245. rotate([90, 0, 0])
  246. cylinder(d = led_ridge_dia, h = led_ridge_h + inner_dia / 2 + 2);
  247. hull() {
  248. translate([inner_dia / 2 + led_l + led_ridge_dia / 2, led_ridge_h + inner_dia / 2 + 2, 0])
  249. rotate([90, 0, 0])
  250. cylinder(d = led_ridge_dia, h = led_ridge_h);
  251. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 5, led_ridge_h + inner_dia / 2 + 2, 0])
  252. rotate([0, 90, 0])
  253. cylinder(d = led_ridge_dia, h = led_ridge_h + 5);
  254. }
  255. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  256. rotate([0, 90, 0])
  257. cylinder(d = led_ridge_dia, h = led_ridge_h + 25);
  258. hull() {
  259. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  260. rotate([90, 0, 0])
  261. cylinder(d = led_ridge_dia, h = led_ridge_h + 10);
  262. translate([inner_dia / 2 + led_l + led_ridge_dia / 2 - 25, led_ridge_h + inner_dia / 2 + 2, 0])
  263. rotate([0, 90, 0])
  264. cylinder(d = led_ridge_dia, h = led_ridge_h);
  265. }
  266. }
  267. }
  268. }
  269. module right_half(thread_draw) {
  270. difference() {
  271. union() {
  272. half_body(true);
  273. translate([0, 0, height])
  274. rotate([0, 0, 180])
  275. thread(thread_profile, thread_draw);
  276. }
  277. translate([-outer_dia / 2 - 1, -outer_dia / 2 - 1 + body_gap / 2, height - 1])
  278. cube([outer_dia + 2, outer_dia / 2 + 1, 50]);
  279. screw_holes(true);
  280. translate([outer_dia / 2 - arduino_w -((outer_dia / 2) - (inner_dia / 2) - arduino_w) / 2, arduino_d / 2, -arduino_h / 2 + height / 2])
  281. rotate([90, 0, 0])
  282. arduino_cutout();
  283. for (a = [0, bat_angle, -bat_angle])
  284. rotate([0, 0, a])
  285. translate([-bat_w / 2, outer_dia / 2 - bat_w, (height - bat_h) / 2])
  286. bat_cutout();
  287. }
  288. }
  289. module assembly_closed(thread_draw) {
  290. right_half(thread_draw);
  291. rotate([0, 0, 180])
  292. left_half(thread_draw);
  293. }
  294. module assembly_opened(angle, thread_draw) {
  295. translate([-outer_dia / 2, 0, 0]) {
  296. rotate([0, 0, angle / 2])
  297. translate([outer_dia / 2, 0, 0])
  298. right_half(thread_draw);
  299. rotate([0, 0, -angle / 2])
  300. translate([outer_dia / 2, 0, 0])
  301. rotate([0, 0, 180])
  302. left_half(thread_draw);
  303. }
  304. }
  305. module print() {
  306. translate([outer_dia / 2 + 5, 0, 0])
  307. left_half(true);
  308. translate([-outer_dia / 2 - 5, 0, 0])
  309. right_half(true);
  310. }
  311. //lcd_cutout();
  312. //left_half(false);
  313. //right_half(false);
  314. //assembly_closed(false);
  315. //assembly_opened(90, false);
  316. print();