Search

OpenSCAD Projects

Cam profiles

Matt Venn posted a python script to generate openScad to create a cam profile based on interpolation between polar control points on its circumference. I took up the challenge to do it all in OpenSCAD and after a couple of iterations, during which I reinvented the lookup function which I hadn't noticed before, came up with

function polar_to_xy(v) = [v[1] * cos(v[0]), v[1] * sin(v[0] )];

module polar_profile(control_points,step) {
   for (angle =[0: step: 360 - 1])
         assign (ps = [angle,  lookup(angle, control_points)],
                 pe = [angle+step,  lookup(angle+step, control_points) ]
                )
         polygon ([ [0,0], polar_to_xy(ps), polar_to_xy(pe)]);
}           
        

where the control points are pairs of angle and radius.

The script in is Github. The lookup function does the interpolation using control_point[0] (the angle) to interpolate between values of control_point[1] ( the radius). The common pattern of using small triangles centered on the origin creates the 2-D shape.

Belts and Pulleys

I can across this OpenSCAD script for making pulleys, typically for printers, from maker droftarts. This is a great resource because it contains the polygon profiles for a large range of different belt types. However I found the script difficult to understand. This was partly because properties of a belt are spread around the code, and partly because the core is a single module governed by a large number of global variables.

As an exercise, I re-wrote this code. I consolidated all belt data into a multi-dimensional array.

 Belts = [
/* belt descriptor :
    0 belt type
    1 tooth spacing
        2 numbers : tooth pitch, tooth pitch line offset
        3 numbers : b,c,d
    2 tooth depth
    3 tooth width
    4 tooth profile
   
*/
   ["MXL", [2.032, 0.254], 0.508 , 1.321 ,
       [[-0.660421,-0.5],[-0.660421,0],[-0.621898,0.006033],[-0.587714,0.023037],[-0.560056,0.049424],.....   ], 
                

The main array is used as a dictionary, with the first item the key. Each sub-array contains the belt parameters, including the array of points which define the profile of a tooth. The single module was split up into separate modules for components of the pulley - the base, belt guides and the gear itself. The global variables were largely distributed over the small modules.

The core is the part which creates the ring of teeth which are then removed from the the pulley drum because these are belt profiles. Its created in 2D for later extrusion.

for(i=[1:teeth])
{
   rotate([0, 0, i* (360/teeth)])
   translate([0,-tooth_distance_from_centre, 0])
   polygon(profile) ;
{         
            

Composing the pulley from the parts is the same problem as composing a Doric column, so the stack transformation is useful here too to define the spacing between components and then place them in the ridht position.

The Thingiverse configuration tool and competition for the best configurable thing leads to scipts with large numbers of global variables and complex optional code, This code is only a library of data and modules useful for writing an OpenSCAd main script. I personally think this yields a more comprehensible and reusable script, but perhaps beauty is in the eye of the beholder, and I really only understand it better thanks to the act of re-structuring rather than the structured code. I put it up on Thingiverse as a contribution but I havent printed from it.