summaryrefslogtreecommitdiff
path: root/body/body.scad
blob: a3ec753b6243297948320b91aacf9558fc7e621b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
include <design.scad>
include <helpers.scad>
include <holes.scad>
include <m12_connectors.scad>
include <m12_lense_holder.scad>
include <m12_lense_holder_adapter.scad>
include <noctua_nf_a4x20.scad>
include <radxa_zero_3e.scad>
include <veye_imx287.scad>

// main frame size
// in scanner coords
// inner height is a bit random
// TODO: choose constant size to use one frame for
// many similar ranges
main_frame_height_y = 150;
main_frame_width_x = 34;
main_frame_depth_z = 56;

// wall and wall thickness
$sbfwo = $scannerBodyFrontWallOffsetMm;
$wawt = -$scannerBodyFrontWallOffsetMm + $scannerBodyWallThicknessMm;
wt = $scannerBodyWallThicknessMm;
wzo = $scannerBodyFrontWallOffsetMm;

module cam_and_lense_new()
{
    lhs = laser_holder_size();
    
    // screw insert diameter
    id = 4;
    // cam and lense holder mount plate z size (scanner coords)
    //calhmpzs = 20;
    calhmpzs = 8;
    // cam and lense holder mount plate y height (scanner coords)
    //calhmpyh = 13;
    //calhmpyh = 25.714;
    calhmpyh = 20;
    // cam and lense holder mount plate z offset (scanner coords)
    //calhmpzo = 5.07;
    calhmpzo = -0.93;
    //tpw = $m12_lense_holder_size;
    tpw = veye_imx287_pcb_w;

    //color("pink", 0.6)
    difference()
    {
        union()
        {
            //color("green", 0.3)
            difference()
            {
                //color("blue", 0.3)
                hull()
                {
                    translate([0, 0, $lenseYPosMm])
                    rotate([-$opticalAxisAngleDegrees, 0, 0])
                    translate([0, -$lenseSensorDistanceMm, 0])
                    rotate([$sensorLenseAngleDegrees, 0, 0])
                    veye_imx287_mount_plate_outer();

                    translate([0, 0, $lenseYPosMm])
                    rotate([-$opticalAxisAngleDegrees, 0, 0])
                    {
                        //color("blue", 0.3)
                        {
                            
                            m12_lense_holder_base();
                            //color("blue", 0.3)
                            *%m12_lense_holder();
                        }
                    }
                }
                
                hull()
                translate([0, 0, $lenseYPosMm])
                rotate([-$opticalAxisAngleDegrees, 0, 0])
                {
                    m12_lense_circle();
                    translate([0, -$lenseSensorDistanceMm, 0])
                    rotate([$sensorLenseAngleDegrees, 0, 0])
                    veye_imx287_mount_plate_inner();
                }
                
                translate([0, 0, $lenseYPosMm])
                rotate([-$opticalAxisAngleDegrees, 0, 0])
                scale([1, 2, 1])
                m12_lense_holder_screw_holes();
            }
            
            // top part
            hull()
            {
                // lense holder helper
                {
                    //color("red", 0.3)
                    translate([0, 0, $lenseYPosMm])
                    rotate([-$opticalAxisAngleDegrees, 0, 0])
                    //translate([0, -$lenseSensorDistanceMm, 0])
                    //rotate([$sensorLenseAngleDegrees, 0, 0])
                    m12_lense_holder_top();
                }
                
                // cam holder helper
                {
                    pcb_w = veye_imx287_pcb_w;
                    pcb_h = veye_imx287_pcb_h;
                    //color("yellow", 0.5)
                    translate([0, 0, $lenseYPosMm])
                    rotate([-$opticalAxisAngleDegrees, 0, 0])
                    translate([0, -$lenseSensorDistanceMm, 0])
                    rotate([$sensorLenseAngleDegrees, 0, 0])
                    //cube([pcb_w + $tiny_padding * 2, 1, 1]);
                    veye_imx287_mount_plate_outer_top();
                }
                
                // wall near body
                {
                    //color("orange", 0.3)
                    translate([-pcb_w / 2, -$sbfwo, 116])
                    rotate([90, 0, 0])
                    cube([pcb_w, 14, 1]);
                }
            }
        }
                    
            
        translate([0, 0, $lenseYPosMm])
        rotate([-$opticalAxisAngleDegrees, 0, 0])
        translate([0, -$lenseSensorDistanceMm, 0])
        rotate([$sensorLenseAngleDegrees, 0, 0])
        veye_imx287_mount_holes();
    }
}

module cam_and_lense()
{
    lhs = laser_holder_size();
    
    // screw insert diameter
    id = 4;
    // cam and lense holder mount plate z size (scanner coords)
    calhmpzs = 20;
    // cam and lense holder mount plate y height (scanner coords)
    calhmpyh = 13;
    // cam and lense holder mount plate z offset (scanner coords)
    calhmpzo = 5.07;
    //tpw = $m12_lense_holder_size;
    tpw = veye_imx287_pcb_w;
    
    translate([0, 0, $lenseYPosMm])
    %rotate([-$opticalAxisAngleDegrees, 0, 0])
    {
        //color("orange", 0.6)
        m12_lense_holder();
        %m12_lense();
        //color("red", 0.3)
        //%m12_lense_circle();

        translate([0, -$lenseSensorDistanceMm, 0])
        rotate([$sensorLenseAngleDegrees, 0, 0])
        {
            //color("yellow", 0.3)
            veye_imx287_natural();
        }

        color("green", 0.5)
        *difference()
        {
            // outer area
            //color("blue", 0.8)
            //color("blue")
            hull()
            {
                
                m12_lense_holder_base();
                {
                    
                    translate([0, -$lenseSensorDistanceMm, 0])
                    rotate([$sensorLenseAngleDegrees, 0, 0])
                    veye_imx287_mount_plate_outer();
                }
            }
            
            //m12_lense_circle();
            
            // inner area to cut
            //color("red", 0.3)
            hull()
            {
                m12_lense_circle();
                translate([0, -$lenseSensorDistanceMm, 0])
                rotate([$sensorLenseAngleDegrees, 0, 0])
                veye_imx287_mount_plate_inner();
            }
        }
    }
    
    color("green", 0.3)
    *hull()
    {
        translate([0, 0, $lenseYPosMm])
        rotate([-$opticalAxisAngleDegrees, 0, 0])
        {
            color("green", 0.3)
            {
                
                m12_lense_holder_base();
                {
                    
                    translate([0, -$lenseSensorDistanceMm, 0])
                    rotate([$sensorLenseAngleDegrees, 0, 0])
                    veye_imx287_mount_plate_outer();
                }
            }
        }
        
        // cam and lense mount plate
        color("red", 0.5)
        translate([
            0,
            calhmpzo,
            //0,
            -$tiny_padding - lhs[2] / 2 + main_frame_height_y])
        cube([
                //veye_imx287_pcb_h / 2,
                tpw,
                //calhmpzs,
                //tpw / 2,
                $tiny_padding,
                $tiny_padding
            ],
            center = true);
    }
    
    color("green", 0.3)
    *hull()
    {
        color("red", 0.5)
        translate([
            0,
            calhmpzo,
            //0,
            -$tiny_padding - lhs[2] / 2 + main_frame_height_y])
        cube([
                //veye_imx287_pcb_h / 2,
                tpw,
                //calhmpzs,
                //tpw / 2,
                $tiny_padding,
                $tiny_padding
            ],
            center = true);
    }
    
    
    // AAAAAAAAAAAAA
    //union()
    color("blue", 0.3)
    hull()
    {
        translate([0, 0, $lenseYPosMm])
        rotate([-$opticalAxisAngleDegrees, 0, 0])
        translate([0, -$lenseSensorDistanceMm, 0])
        rotate([$sensorLenseAngleDegrees, 0, 0])
        veye_imx287_mount_plate_outer();

        translate([0, 0, $lenseYPosMm])
        rotate([-$opticalAxisAngleDegrees, 0, 0])
        {
            color("blue", 0.3)
            {
                
                m12_lense_holder_base();
            }
        }
        // second top plate height
        stph = 5;
        translate([
            0,
            //-4.917,
            -3.85,
            //0,
            -$tiny_padding - lhs[2] / 2 + main_frame_height_y
            -stph / 2
            ])
        *cube([
                veye_imx287_pcb_h,// - veye_imx287_mount_plate_corner_radius * 2,
                //tpw,
                //calhmpzs,
                //tpw / 2,
                $tiny_padding,
                //$tiny_padding
                stph
            ],
            center = true);
    }
    
    {
        // cam and lense mount plate
        color("orange", 0.5)
        translate([
            0,
            calhmpzo,
            //0,
            -$tiny_padding -
            lhs[2] / 2 +
            main_frame_height_y -
            calhmpyh / 2])
        cube([
                //veye_imx287_pcb_h / 2,
                tpw,
                //calhmpzs,
                //tpw / 2,
                //10, 10
                calhmpzs,
                //$tiny_padding,
                //$tiny_padding
                calhmpyh
            ],
            center = true);

        translate([0, 0, $lenseYPosMm])
        rotate([-$opticalAxisAngleDegrees, 0, 0])
        {
            color("red", 0.3)
            {
                
                m12_lense_holder_base();
            }
        }
    }
    
    // cam and lense holder screw holes
    *union()
    {
        // multipliers are in scanner coords
        for (x_mult = [-1, 1], z = [0, -16])
        {
            /*translate([
                -lhs[0] * 1 / 3 * x_mult,
                //-lhs[1] / 2  * z_mult +- 4,
                z,
                -lhs[2] / 2])
            */
            translate([
                veye_imx287_pcb_h / 3 * x_mult,
                //calhmpzs / 2,
                calhmpzo,
                -lhs[2] / 2 + main_frame_height_y])
            screw_hole(
                m = m2,
                id = id,
                il = hole_insert_height * 2,
                hd = m2_head_diameter,
                hh = m2_head_height,
                hs = hole_side_top);
        }
    }
}

module cam_and_lense_holder()
{
    color("red", 0.3)
    m12_lense_circle();
}

module camera_hole()
{
    // TODO: calc Y (scanner coords) offset instead of
    // hardcoding it
    y_offset = 100;
    translate([0, 0, y_offset])
    // move to the front border of scanner body
    translate([0, $wawt, 0])
    front_glass_hole(gw = 26.6, gh = 19.6, gt = 2, gcr = 1);
}

module laser_glass_hole()
{
    // TODO: calc Y (scanner coords) offset instead of
    // hardcoding it
    y_offset = 0;
    translate([0, 0, y_offset])
    // move to the front border of scanner body
    translate([0, $wawt, 0])
    front_glass_hole(gw = 14, gh = 6, gt = 2, gcr = 1);
}

module laser_holder_screw_holes()
{
    lzo = -$laserZOffsetMm;
    ll = $laserBodyLengthMm;
    lhs = laser_holder_size();
    id = 4;
    
    // multipliers are in scanner coords
    for (x_mult = [-1, 1], z = [0, -16])
    {
        translate([
            -lhs[0] * 1 / 3 * x_mult,
            //-lhs[1] / 2  * z_mult +- 4,
            z,
            -lhs[2] / 2])
        screw_hole(
            m = m2,
            id = id,
            il = hole_insert_height * 2,
            hd = m2_head_diameter,
            hh = m2_head_height,
            hs = hole_side_bottom);
    }
}

module cam_lense_holder_screw_holes()
{
    id = 4;
    // scanner coords
    x_offset = 10;
    y_center = 123;
    y_offset = 3;
    
    for (x = [x_offset, -x_offset], yo = [y_offset, -y_offset])
    {
        translate([x, -wzo, y_center + yo])
        screw_hole(
            m = m2,
            id = id,
            il = hole_insert_height,
            hd = m2_head_diameter,
            hh = m2_head_height,
            hs = hole_side_front);
    }
}

module visualize_yz_range()
{
    lenseY = $lenseYPosMm;
    zBase = $actualZBaseMm + $wawt;
    farZ = zBase + $actualZRangeMm;
    
    color("red", 0.3)
    rotate([0, -90, 0])
    %polygon([
        [lenseY, 0],
        [0, zBase],
        [0, farZ],
    ]);
}

module visualize_xz_range()
{
    zBase = $actualZBaseMm + $wawt;
    farZ = zBase + $actualZRangeMm;
    
    color("red", 0.3)
    %polygon(
        [[$actualXStartMm / 2, zBase],
        [-$actualXStartMm / 2, zBase],
        [-$actualXEndMm / 2, farZ],
        [$actualXEndMm / 2, farZ],]);
}

module visualize_range()
{
    lenseY = $lenseYPosMm;
    zBase = $actualZBaseMm + $wawt;
    // TODO: use `zEnd` name instead of `farZ`?
    farZ = zBase + $actualZRangeMm;
    xs = $actualXStartMm;
    xe = $actualXEndMm;
    
    // lense center 
    lc = [0, 0, lenseY];
    // x start left
    xsl = [-xs / 2, zBase, 0];
    xsr = [xs / 2, zBase, 0];
    xel = [-xe / 2, farZ, 0];
    xer = [xe / 2, farZ, 0];
    //        0   1    2    3    4
    points = [lc, xsl, xsr, xel, xer];
    
    // front (top?) face
    // ff = [lc, xel, xer];
    ff = [0, 3, 4];
    // right face
    // rf = [xer, lc, xsr];
    rf = [4, 0, 2];
    // back (ass) face
    // bkf = [xsr, lc, xsl];
    bkf = [2, 0, 1];
    // left face
    // lf = [xsl, lc, xel];
    lf = [1, 0, 3];
    // bottom face
    // bmf = [xel, xer, xsr, xsl];
    bmf = [3, 4, 2, 1];
    
    faces = [ff, rf, bkf, lf, bmf];
    //faces = [ff];
    
    //polyhedron(points, faces);
    
    
    color("red", 0.4)
    polyhedron(
        [lc, xsl, xsr, xel, xer],
        //[ff, rf, bkf]
        faces
    );
}


// main frame
module scanner_main_frame()
{
    lhs = laser_holder_size();
    
    // inner height, width, depth and radius
    ih = main_frame_height_y;
    iw = main_frame_width_x;
    id = main_frame_depth_z;
    ir = wt;
    
    // now try to cut body with rounded corners to simplify
    // cnc manufacturing
    // TODO: move this shit to a module
    difference()
    {
        hull()
        {
            // outer cylinders
            union()
            {
                for (yd = [0, -id], zd = [0, ih])
                {
                    translate([0, -wzo + yd, -lhs[2] / 2 + zd])
                    rotate([0, 90, 0])
                    cylinder($fn = dToFn(ir * 2), r = ir, h = iw, center = true);
                }
            }
        }
        // inner cylinders
        hull()
        {
            union()
            {
                for (yd = [0 - ir, -id + ir], zd = [0 + ir, ih - ir])
                {
                    translate([0, -wzo + yd, -lhs[2] / 2 + zd])
                    rotate([0, 90, 0])
                    // scale by x a bit to fully cut
                    cylinder($fn = dToFn(ir * 2), r = ir, h = iw * 1.1, center = true);
                }
            }
        }
    }
    
    // TODO: and now add some stands for screwing left/right covers
    // TODO: simplify inner cut cube after implementing this:
    // rounded corners won't be needed anymore

    // chinese fan
    //translate([0, -$scannerBodyFrontWallOffsetMm, 40])
    translate([0, ld3007ms_t - wzo - id, 80])
    *ld3007ms();
}

module m12_connectors()
{
    // inner height, width, depth and radius
    ih = main_frame_height_y;
    iw = main_frame_width_x;
    id = main_frame_depth_z;
    ir = wt;
    
    {
        // add outer m12 connectors
        //scale([1.05, 1, 1.05])
        translate([0, -wzo - id + $tiny_padding, 20 + m12_male_conn_body_thick_part_d + 5])
        m12_female_connector();
        
        translate([0, -wzo - id + $tiny_padding, 20])
        m12_male_connector();
    }
}

module laser_with_holder()
{
    translate([0, -$laserZOffsetMm, 0])
    {
        %laser_body();
        %laser_holder();
    }
}

module radxa()
{
    translate([0, 0, 20])
    translate([
        0,
        -$scannerBodyFrontWallOffsetMm - 5,
        radxa_zero_3e_pcb_h - 10])
    rotate([90, 0, 0])
    //radxa_zero_3e_with_protoboard();
    radxa_zero_3e_with_protoboard_and_connectors();
}

module other()
{
    //cam_and_lense();
    difference()
    {
        cam_and_lense_new();
        //translate([-$tiny_padding*100, 0, 0])
        translate([0, $tiny_padding, 0])
        cam_lense_holder_screw_holes();
    }

    //visualize_yz_range();
    //visualize_xz_range();
    visualize_range();

    laser_with_holder();
    %radxa();
}

// visual block

union()
{
    *other();

    *cam_lense_holder_screw_holes();

    difference()
    {
        scanner_main_frame();
        camera_hole();
        laser_glass_hole();
        laser_holder_screw_holes();
        m12_connectors();
        cam_lense_holder_screw_holes();
    }
}

// printing cam/lense holder
*union()
{
    difference()
    {
        cam_and_lense_new();
        //translate([-$tiny_padding*100, 0, 0])
        translate([0, $tiny_padding, 0])
        cam_lense_holder_screw_holes();
    }
}

// printing body
*difference()
{
    scanner_main_frame();
    camera_hole();
    laser_glass_hole();
    laser_holder_screw_holes();
    m12_connectors();
}