Micro marble machine (part 1)

The idea is simple, we create sleepers for a rail made of filament.

 

For a first test, I created circular sleepers using a laser cutter found at ZB45 in the Netherlands.

 

Sleepers

 

/* [quality] */
$fn=64;

/* [ball] */
ball_dia=9;
rail_dia=1.75; // [1.75, 2.85, 3]

plateFn=8; // [4, 6, 8, 12, 16, 18, 20, 24]
biels_height=2;
biels_inner_dia=14;
biels_outer_dia=20;
rail_ball_dist=1.0; // [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0]

rail_center_rad=(ball_dia + rail_dia + rail_ball_dist)/2;
rail_angle=45; // [22.5, 30, 36, 45, 60, 72, 90, 120]

/* [plate] */
plateX = 3;
plateY = 4;
rail_holes=true;
type="outer"; // ["outer", "in-out", "inner", "plate", "helper"]

extrude_height = 0; // [0, 1, 2, 3, 4, 5, 6, 7, 8]

/* [Hidden] */
mountXOffset = -$plateHeight;
mountYOffset = 0;
biels_outer_rad = biels_outer_dia/2;
rail_rad= rail_dia/2;

if(extrude_height == 0)
{
bielsPlate();
}
else
{
linear_extrude(height=extrude_height)
bielsPlate();
}

/////////////////////////////////////
// modules
/////////////////////////////////////



module helperBiels()
{
difference(){
circle(d = biels_outer_dia, center=true);

railCenters()
{
circle(d=rail_dia, center=true);
translate([0, -rail_rad]) square([10, rail_dia]);
}
}
}



module bielsPlate()
{
for(x = [0:plateX-1], y = [0: plateY-1])
translate([biels_outer_rad + x * (biels_outer_dia ) + (y%2 * biels_outer_rad),
biels_outer_rad + y * biels_outer_dia * 7 / 8])
rotate([0, 0, -360/(plateFn*2)])
{
if( type == "outer" || type == "in-out")
{
outerBiels();
}
if( type == "inner" || type == "in-out")
{
innerBiels();
}
if (type == "plate")
{
plateBiels();
}
if(type == "helper")
{
helperBiels();
}
}
}

module outerBiels()
{
difference()
{
circle(d=biels_outer_dia, center=true);

if(rail_holes)
{
circle(r=rail_center_rad, center=true);
railCenters()
circle(d=rail_dia, center=true);
}
else
{
circle(d=rail_center_rad*2+rail_dia, center=true);
}
}
}


module innerBiels()
{
difference(){
circle(d=(rail_center_rad*2) - .1, center=true);

railCenters()
circle(d=rail_dia, center=true);
}
}

module plateBiels()
{
difference(){
circle(d=biels_outer_dia, center=true, $fn=plateFn);

railCenters()
circle(d=rail_dia, center=true);
}
}

module railCenters()
{
rotate([0, 0, 360/(plateFn*2)])
for(r = [0:rail_angle:360 - rail_angle])
{
rotate([0, 0, r])
translate([rail_center_rad, 0, 0])
children();
}
}