use <achse.scad>
use <gears/gears.scad>
use <kugellager.scad>
use <stepper.scad>
use <zahnkranz.scad>

/*
Schraube MetricCountersunkBolt()
Schraubenloch CountersunkClearanceHole()
Gewindebolzen RodStart() RodEnd()
Mutter MetricNut()
*/

$fn = 200;
gear_modul = 0.5;
laser_h = 3;
brett_dicke = 13;
brett_bohrung = 15.5;
bretter_abstand = 8;
gear_abstand_unten = 2;

// Verwendetes Reely-Plastik-Doppelzahnrad
module double_gear(tooth_number, flipped = false) {
  if (!flipped) {
    spur_gear(modul = gear_modul, tooth_number = tooth_number, width = 1.5,
              bore = 3);
    translate([ 0, 0, 1.5 ])
        spur_gear(modul = gear_modul, tooth_number = 12, width = 4, bore = 3);
  } else {
    spur_gear(modul = gear_modul, tooth_number = 12, width = 4, bore = 3);
    translate([ 0, 0, 4 ]) spur_gear(
        modul = gear_modul, tooth_number = tooth_number, width = 1.5, bore = 3);
  }
}

// Holzbrett
module brett() {
  brett_durchmesser = 197;
  linear_extrude(brett_dicke) difference() {
    circle(d = brett_durchmesser);
    circle(d = brett_bohrung);
  }
}

// Stepper
stepper_grundkoerper_h = 32;
stepper_befestigung_l = 78;
stepper_befestigung_screw_d = 4;
stepper_befestigung_screw_abstand = 4;

translate([
  0, 0, -(stepper_grundkoerper_h + 3 * laser_h)
]) stepper_small(grundkoerper_h = stepper_grundkoerper_h,
                 befestigung_l = stepper_befestigung_l,
                 befestigung_screw_d = stepper_befestigung_screw_d,
                 befestigung_screw_abstand = stepper_befestigung_screw_abstand);

// Anordnung der Zahnräder (mit Augenmaß)
color("red") translate([ 0, 14.7, gear_abstand_unten ])
    double_gear(tooth_number = 40);
color("green") translate([ 0, 30.2, gear_abstand_unten ])
    double_gear(tooth_number = 50, flipped = true);
translate([ 0, 48.3, gear_abstand_unten ]) double_gear(tooth_number = 60);

color("blue") translate([ 0, 0, bretter_abstand - laser_h ])
    zahnkranz(tooth_number = 206, laser_h = laser_h);

*color("grey") translate([ 0, 0, bretter_abstand ]) brett();

color("blue")
    achse(laser_h = laser_h,
          brett_bohrung = brett_bohrung,
          brett_dicke = brett_dicke,
          stepper_befestigung_screw_d = stepper_befestigung_screw_d,
          stepper_befestigung_l = stepper_befestigung_l,
          stepper_befestigung_screw_abstand = stepper_befestigung_screw_abstand,
          gear_abstand_unten = gear_abstand_unten,
          bretter_abstand = bretter_abstand);

color("red") kugellager_mit_nuts(sphere_number = 290, h = bretter_abstand);

translate([ 0, 0, bretter_abstand + brett_dicke + 0.5 + 8 ]) mirror([ 0, 0, 1 ])
    kugellager(sphere_number = 100, h = 8, nut_d = 10, wall_d = 3);