Commit 8cafef00 authored by William Wadsworth's avatar William Wadsworth
Browse files

start to put camera rotation into dictionaries

parent e962b5b5
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12,5 +12,5 @@ camera_platform_stl();
module camera_platform_stl(){
    params = default_params();
    optics_config = c270lens_config();
    camera_platform(params, optics_config, base_r=5, camera_rotation=-135);
    camera_platform(params, optics_config, base_r=5);
}
+4 −3
Original line number Diff line number Diff line
@@ -428,14 +428,15 @@ function camera_board_thickness(optics_config) = key_lookup("board_thickness", o
* * base_r - radius of mount body
* * camera_rotation - orientation of the camera compared the the OFM std
*/
module camera_platform(params, optics_config, base_r, camera_rotation=0, text_=""){

module camera_platform(params, optics_config, base_r, _camera_rotation=0, text_=""){ //TODO remove _camera rotation when eliminated
    assert(key_lookup("optics_type", optics_config)=="spacer", "Use spacer optics configuration to create a camera_platform.");

    // platform height is 5mm below the lens spacer (board is 1mm thick mounting posts are 4mm tall)
    platform_h = lens_spacer_z(params, optics_config) - camera_mounting_post_height(optics_config) - camera_board_thickness(optics_config);
    assert(platform_h > upper_z_flex_z(params), "Platform height too low for z-axis mounting");

    camera_rotation = key_lookup("rotation", optics_config); // TODO deal with undefined, or put zero in all dictionaries (better)

    // Make a camera platform with a fitting wedge on the side and a platform on the top
    difference(){
        union(){
@@ -503,7 +504,7 @@ module camera_platform(params, optics_config, base_r, camera_rotation=0, text_="
        }
        // cut ledge for the backshell, with a little clearance
        if(is_c270_spacer(optics_config)){
            rotate_z(camera_rotation){
            rotate_z(camera_rotation + 135){
                translate_z(lens_spacer_z(params, optics_config)-0.1){
                    rotate([180,0,0]){
                        c270_backshell();
+9 −4
Original line number Diff line number Diff line
@@ -36,7 +36,9 @@ function rms_infinity_f50d13_config(camera_type = "picamera_2", beamsplitter=fal
    replacements = [["is_finite_conjugate", false]]
) replace_multiple_values(replacements, finite_config);

function pilens_config(camera_type = "picamera_2") = let(
function pilens_config(camera_type = "picamera_2", upright=false) = let(
    // note the base rotation of 45 degrees is hard coded
    rotation = upright ? 180 : 0,
    config_dict = [["optics_type", "spacer"],
                   ["camera_type", camera_type],
                   ["lens_r", 3],
@@ -44,7 +46,8 @@ function pilens_config(camera_type = "picamera_2") = let(
                   ["lens_h", 2.5], // For a lens spacer this is the lens thickness to be gripped
                   ["lens_spacing", 17], // Minimum 17 for spacer to build correctly
                   ["mounting_post_height",4],
                   ["board_thickness",1]]
                   ["board_thickness",1],
                   ["rotation", rotation]] // camera rotation about z
) config_dict;

function c270lens_config(camera_type = "logitech_c270") = let(
@@ -55,7 +58,8 @@ function c270lens_config(camera_type = "logitech_c270") = let(
                   ["lens_h", 4], // For a lens spacer this is the lens thickness to be gripped
                   ["lens_spacing", 17], // Minimum 13 for spacer to build correctly
                   ["mounting_post_height",4],
                   ["board_thickness",1]]
                   ["board_thickness",1],
                   ["rotation", -135]] // camera rotation about z
) config_dict;

function b0196lens_config(camera_type = "arducam_b0196") = let(
@@ -66,5 +70,6 @@ function b0196lens_config(camera_type = "arducam_b0196") = let(
                   ["lens_h", 2.5], // For a lens spacer this is the lens thickness to be gripped
                   ["lens_spacing", 17], // Minimum 17 for spacer to build correctly
                   ["mounting_post_height",4],
                   ["board_thickness",1]]
                   ["board_thickness",1],
                   ["rotation", 0]] // camera rotation about z
) config_dict;
+2 −2
Original line number Diff line number Diff line
@@ -13,6 +13,6 @@ camera_platform_stl();

module camera_platform_stl(){
    params = default_params();
    optics_config = pilens_config();
    camera_platform(params, optics_config, base_r=5, camera_rotation=90, text_="upright");
    optics_config = pilens_config(upright=true);
    camera_platform(params, optics_config, base_r=5, text_="upright");
}
+81 −38
Original line number Diff line number Diff line
@@ -14,14 +14,26 @@ use <librender/electronics.scad>
use <librender/hardware.scad>
use <librender/rendered_components.scad>

/*
Frames 1, 2, 3: Press the lens spacer on to the lens
Frames 4 ,5: Screw lens spacer and camera board to the platform
Frames 6, 7, 8: Add mounting nut and M3 screw
Frames 9, 10, 11: Connect camera cable ("pi_camera" only)
Frames 12, 13: Screw C270 camera to lens spacer ("c270" only)
Frames 14, 15, 16: Add C270 backshell ("c270" only)
*/

FRAME = 11;
// CAMERA_TYPE is either "c270" or "pi_camera"
CAMERA_TYPE = "pi_camera";
// UPRIGHT is true or false and determines the rotation of the camera and the version of the camera platform
UPRIGHT = false;

render_low_cost_assembly(FRAME, CAMERA_TYPE);

module render_low_cost_assembly(frame, camera_type){
render_low_cost_assembly(FRAME, CAMERA_TYPE, UPRIGHT);
module render_low_cost_assembly(frame, camera_type, upright){
    if (frame <= 3){
        // The lens spacer is the same for any rotation of the camera,
        // so has no dependence on 'upright' 
        assemble_lens_spacer(frame, camera_type);
    }
    else if (frame == 4){
@@ -35,7 +47,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 opt_axis_line=true,
                                 connector_open=true,
                                 explode="camera",
                                 camera_type=camera_type);
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 5){
        rendered_low_cost_optics(optics_module_pos(),
@@ -46,7 +59,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 screw=false,
                                 ribbon_cable=false,
                                 connector_open=true,
                                 camera_type=camera_type);
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 6){
        rendered_low_cost_optics(optics_module_pos(),
@@ -58,10 +72,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 ribbon_cable=false,
                                 connector_open=true,
                                 explode="nut",
                                 camera_type=camera_type);
        if (camera_type == "c270"){
            rendered_backshell();
        }
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 7){
        rendered_low_cost_optics(optics_module_pos(),
@@ -73,10 +85,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 ribbon_cable=false,
                                 connector_open=true,
                                 explode="screw",
                                 camera_type=camera_type);
        if (camera_type == "c270"){
            rendered_backshell();
        }
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 8){
        rendered_low_cost_optics(optics_module_pos(),
@@ -88,10 +98,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 ribbon_cable=false,
                                 screw_tight=false,
                                 connector_open=true,
                                 camera_type=camera_type);
        if (camera_type == "c270"){
            rendered_backshell();
        }
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 9){
        assert(camera_type=="pi_camera","Camera cable insert only for pi Camera")
@@ -105,7 +113,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 screw_tight=false,
                                 connector_open=true,
                                 explode="ribbon_cable",
                                 camera_type=camera_type);
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 10){
        assert(camera_type=="pi_camera","Camera cable insert only for pi Camera")
@@ -118,7 +127,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 ribbon_cable=true,
                                 screw_tight=false,
                                 connector_open=true,
                                 camera_type=camera_type);
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 11){
        assert(camera_type=="pi_camera","Camera cable insert only for pi Camera")
@@ -131,7 +141,8 @@ module render_low_cost_assembly(frame, camera_type){
                                 ribbon_cable=true,
                                 screw_tight=false,
                                 connector_open=false,
                                 camera_type=camera_type);
                                 camera_type=camera_type,
                                 upright=upright);
    }
    else if (frame == 12){
        assert(camera_type=="c270","C270 back screw only for C270 Camera")
@@ -194,19 +205,22 @@ module assemble_lens_spacer(frame, camera_type="pi_camera"){
    }
}

module rendered_camera_platform(camera_type="pi_camera"){
module rendered_camera_platform(camera_type="pi_camera", upright=false){
    params = render_params();
    optics_config = (camera_type == "c270") ? c270lens_config() : pilens_config();
    optics_config = (camera_type == "c270") ? c270lens_config() : pilens_config(upright=upright);
    message = (upright)? "upright" : "";
    coloured_render(optics_module_colour()){
        camera_platform(params, optics_config, 5);
        camera_platform(params, optics_config, 5, text_=message);
    }
}

module camera_platform_and_screws(lens_spacer_z, explode=false, connector_open=false, camera_type="pi_camera"){
module camera_platform_and_screws(lens_spacer_z, explode=false, connector_open=false, camera_type="pi_camera", upright=false){
    ex_dist = 13;
    screw_z = - 1 - (explode ? 2*ex_dist : 0);
    holes = (camera_type == "c270") ? c270_holes() : picamera2_holes();
    camera_rot = (camera_type == "c270") ? 0 : 135 ;
    camera_rot = (camera_type == "c270") ? 0 :
                                          (camera_type=="pi_camera" && upright)? -45 :
                                                                                135 ;
    camera_pos = create_placement_dict([0, 0, lens_spacer_z], [0, 0, camera_rot]);
    camera_pos_ex = translate_pos(camera_pos, [0, 0, -ex_dist]);

@@ -215,7 +229,7 @@ module camera_platform_and_screws(lens_spacer_z, explode=false, connector_open=f
    platform_z_pos = !explode ? 0 :
        (camera_type == "c270") ? - ex_dist : - 2*ex_dist;
    translate_z(platform_z_pos){
        rendered_camera_platform(camera_type=camera_type);
        rendered_camera_platform(camera_type=camera_type, upright=upright);
    }
    place_part(render_pos){
        if (camera_type == "pi_camera"){
@@ -225,6 +239,7 @@ module camera_platform_and_screws(lens_spacer_z, explode=false, connector_open=f
            raise_cam = explode ? ex_dist : 0;
            translate_z(raise_cam){
                c270_board();
                rendered_c270_third_screw(screw_z=1, explode=false);
            }
        }
        for (hole_pos = holes){
@@ -255,7 +270,8 @@ module rendered_low_cost_optics(pos,
                                screw_tight=true,
                                connector_open=false,
                                cable_positions=undef,
                                camera_type="pi_camera"){
                                camera_type="pi_camera",
                                upright=false){
    
    cut_camera = (camera_type == "c270")? "+xy" : "+x";
    cut_dir = cut ? cut_camera : "none";
@@ -266,9 +282,12 @@ module rendered_low_cost_optics(pos,
        cable_positions;

    place_part(pos){
        rot = (upright && camera_type=="pi_camera")? 180 : 0;
        cutaway(cut_dir, optics_module_colour()){
            rotate_z(rot){
                lens_spacer(params, optics_config);
            }
        }
        if (nut){
            exploded = (explode == "nut") ? true : false;
            nut_pos_ex = translate_pos(camera_platform_nut_pos(), [0, 5, 20]);
@@ -282,6 +301,10 @@ module rendered_low_cost_optics(pos,
                                      translate_pos(camera_platform_nut_pos(), [0,0,5]));
                }
            }
            if (camera_type == "c270"){
                rendered_backshell();
                rendered_c270_backshell_screws();
            }
        }
        if (screw){
            exploded = (explode == "screw") ? true : false;
@@ -301,9 +324,10 @@ module rendered_low_cost_optics(pos,
        lens_spacer_z = lens_spacer_z(params, optics_config);
        if (camera){
            exploded = (explode == "camera") ? true : false;
            camera_platform_and_screws(lens_spacer_z, exploded, connector_open=connector_open, camera_type=camera_type);
            camera_platform_and_screws(lens_spacer_z, exploded, connector_open=connector_open, camera_type=camera_type, upright=upright);
        }
        if (ribbon_cable){
            rotate_z(rot){
                ribbon_start = create_placement_dict([0, 0, lens_spacer_z-1.25], [0, 0, 135], [0, 180, 0], init_translation=[15, 0, 0]);
                positions = concat([ribbon_start], ribbon_pos);
                exploded = (explode == "ribbon_cable") ? true : false;
@@ -316,6 +340,7 @@ module rendered_low_cost_optics(pos,
                                    translate_pos(ribbon_start, ribbon_tr));
                }
            }
        }
        // lens last as transparent!
        if (lens){
            translate_z(pi_lens_z_pos(params, optics_config)){
@@ -368,26 +393,33 @@ module render_mount_c270_back_shell(pos, explode=false, platform=true, backshell
                }
            }
        }
        rotate_z(180){
            translate(c270_far_third_hole_pos() - [0,0,screw_z]){
                mirror([0,0,1]){
                    no1_x5_0_selftap();
                }
                if (explode){
                    construction_line([0, 0, 0], [0, 0, 2*screw_z]);
                }
            }
        }
        rendered_c270_third_screw(screw_z=screw_z, explode=explode);
    }
    
    
    if (platform){
        rendered_camera_platform(camera_type="c270");
        holes = c270_holes();
        for (hole_pos = holes){
            translate(hole_pos + [0, 0, lens_spacer_z+1]){
                no1_x5_0_selftap();
            }
        }
        backshell_pos = backshell_out ? -8 : 0;
        translate_y(backshell_pos){
            rendered_backshell();
        }
        if (!backshell_out){
            screw_ex = screw_out ? ex_dist : 0;
            rendered_c270_backshell_screws(screw_ex=screw_ex, screw_out=screw_out);
        }
    }
}

module rendered_c270_backshell_screws(screw_ex=0, screw_out=false){
    params = render_params();
    optics_config = c270lens_config();
    lens_spacer_z = lens_spacer_z(params, optics_config);
    pos = c270_backshell_screw_positions();
    backshell_screw_z = pos[1].z;
    for (p = pos){
@@ -401,5 +433,16 @@ module render_mount_c270_back_shell(pos, explode=false, platform=true, backshell
        } 
    }
}

module rendered_c270_third_screw(screw_z=0, explode=false){
    rotate_z(180){
        translate(c270_far_third_hole_pos() - [0,0,screw_z]){
            mirror([0,0,1]){
                no1_x5_0_selftap();
            }
            if (explode){
                construction_line([0, 0, 0], [0, 0, 2*screw_z]);
            }
        }
    }
}
Loading