Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Last active October 2, 2024 16:20
Show Gist options
  • Save rocktronica/9bf386b416345a472ef2b871b6a45c42 to your computer and use it in GitHub Desktop.
Save rocktronica/9bf386b416345a472ef2b871b6a45c42 to your computer and use it in GitHub Desktop.
module horn_goldilocks_array(
height = 2.5,
plot = 10,
tolerances = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1],
shim_counts = [0, 3, 6]
) {
difference() {
cube([
plot * len(tolerances),
plot * len(shim_counts),
height
]);
for (i_tolerance = [0 : len(tolerances) - 1]) {
for (i_shim_count = [0 : len(shim_counts) - 1]) {
translate([
i_tolerance * plot + plot / 2,
i_shim_count * plot + plot / 2,
0
]) {
// So now we have X and Y as tolerances[i_tolerance] and
// shim_counts[i_shim_count], and they can be used to make
// each individual test.
// Here, for example, they're passed as arguments to an
// external cavity() module.
cavity(
diameter = SERVO_SHAFT_DIAMETER
+ tolerances[i_tolerance] * 2,
shim_count = shim_counts[i_shim_count],
height = height
);
}
}
}
}
}
@rocktronica
Copy link
Author

rocktronica commented May 28, 2020

@DPHAD

OpenSCAD (2019.05 ) complains about "cavity()" being an unknown -- am I missing an import or other helper function?

Thanks for the nudge; I've added a comment to hopefully explain... I'd left out cavity() because I wasn't actually expecting anybody to run the code, just get a feel for how the parent module is supposed to work.

Here's the missing stuff, if you want to give it a go and get the full picture in OpenSCAD. Just throw this above horn_goldilocks_array's definition

SERVO_SHAFT_DIAMETER = 5;
module cavity(
    diameter,
    height,
    shim_count = 3,
    shim_width = 1,
    shim_length = .5,
) {
    e = .005678;

    difference() {
        cylinder(
            h = height,
            d = diameter
        );

        if (shim_count > 0) {
            for (i = [0 : shim_count - 1]) {
                rotate([0, 0, i * 360 / shim_count]) {
                    translate([
                        shim_width / -2,
                        diameter / 2 - shim_length,
                        -e
                    ]) {
                        cube([shim_width, shim_length, height + e * 2]);
                    }
                }
            }
        }
    }
}

Hope that helps

@DPHAD
Copy link

DPHAD commented May 29, 2020

Thanks! I'm still new to OpenSCAD and this will help me change stuff and see what happens. Love the idea of a servo horn variety pack for dialing in just the right sizes.

@rocktronica
Copy link
Author

@DPHAD Oh, nice. I like OpenSCAD a lot. Feel free to email if you need anything else. I'm happy to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment