Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laser Layout Mirror Option #106

Merged
merged 10 commits into from
Dec 27, 2020
5 changes: 5 additions & 0 deletions 3d/scripts/generate_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
parser.add_argument('--render-raster', action='store_true', help='Render raster PNG from the output SVG (requires '
'Inkscape)')
parser.add_argument('--thickness', type=float, help='Override panel thickness value')
parser.add_argument('--no-etch', action='store_true', help='Do not render laser-etched features')
parser.add_argument('--mirror', action='store_true', help='Mirror the assembly so the outside faces are facing up. '
'Note that this will remove all etched features.')

args = parser.parse_args()

Expand All @@ -52,6 +55,8 @@
extra_variables = {
'render_revision': rev_info.git_short_rev(),
'render_date': rev_info.current_date(),
'render_etch' : not args.no_etch,
'render_2d_mirror' : args.mirror,
}
if args.kerf is not None:
extra_variables['kerf_width'] = args.kerf
Expand Down
19 changes: 13 additions & 6 deletions 3d/scripts/projection_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def __init__(self, input_file, output_folder, extra_variables=None):
if extra_variables is None:
extra_variables = {}
self.extra_variables = extra_variables
try:
self.etch_enabled = self.extra_variables['render_etch']
except KeyError:
self.etch_enabled = True

def clean(self):
shutil.rmtree(self.output_folder, ignore_errors=True)
Expand Down Expand Up @@ -57,7 +61,10 @@ def _get_component_file(self, i):

def _render_component(self, i, panel_horizontal, panel_vertical):
output_file = self._get_component_file(i)
for style in ('cut', 'etch'):
style_options = ['cut']
if self.etch_enabled:
style_options.append('etch')
for style in (style_options):
logging.debug('Rendering component %d, %s', i, style)
try:
_ = openscad.run(
Expand Down Expand Up @@ -85,10 +92,10 @@ def _render_component(self, i, panel_horizontal, panel_vertical):
processor.apply_laser_cut_style()
elif style == 'etch':
processor.apply_laser_etch_style()
break
else:
raise ValueError("Invalid component!", i)
return processor
return processor

logging.debug('Component %d has no geometry', i)
return None

def render_svgs(self, panelize_quantity):
assert panelize_quantity == 1 or panelize_quantity % 2 == 0, 'Panelize quantity must be 1 or an even number'
Expand All @@ -104,7 +111,7 @@ def render_svgs(self, panelize_quantity):
svg_processor = self._render_component(i, panel_horizontal, panel_vertical)
if svg_output is None:
svg_output = svg_processor
else:
elif svg_processor is not None:
svg_output.import_paths(svg_processor)
output_file_path = os.path.join(self.output_folder, 'combined.svg')
svg_output.write(output_file_path)
Expand Down
147 changes: 80 additions & 67 deletions 3d/splitflap.scad
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ render_motor = true;
// 2d parameters:
render_index = -1;
render_etch = false;
render_2d_mirror = false;

// Panelization:
panel_vertical = 0;
Expand Down Expand Up @@ -1138,7 +1139,17 @@ module split_flap_3d(letter, include_connector) {
}

module laser_etch() {
if (render_etch || render_index == -1) {
if (!render_2d_mirror && (render_etch || render_index == -1)) {
children();
}
}

module laser_mirror() {
if (render_2d_mirror) {
mirror([1, 0, 0])
children();
}
else {
children();
}
}
Expand All @@ -1149,95 +1160,97 @@ if (render_3d) {
split_flap_3d(render_letters[render_units - 1 - i], include_connector=(i != render_units - 1));
}
} else {
panel_height = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width + kerf_width + spool_strut_width + kerf_width;
projection_renderer(render_index=render_index, render_etch=render_etch, kerf_width=kerf_width, panel_height=panel_height, panel_horizontal=panel_horizontal, panel_vertical=panel_vertical) {
// Main enclosure (left, right, front)
translate([0, 0])
enclosure_left();

laser_etch()
laser_mirror() {
panel_height = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width + kerf_width + spool_strut_width + kerf_width;
projection_renderer(render_index=render_index, render_etch=render_etch, kerf_width=kerf_width, panel_height=panel_height, panel_horizontal=panel_horizontal, panel_vertical=panel_vertical) {
// Main enclosure (left, right, front)
translate([0, 0])
enclosure_left_etch();
enclosure_left();

translate([0, enclosure_length + kerf_width])
enclosure_right();
laser_etch()
translate([0, 0])
enclosure_left_etch();

laser_etch()
translate([0, enclosure_length + kerf_width])
enclosure_right_etch();
enclosure_right();

translate([0, enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width - enclosure_horizontal_inset])
rotate([0, 0, -90])
enclosure_front();
laser_etch()
translate([0, enclosure_length + kerf_width])
enclosure_right_etch();

laser_etch()
translate([0, enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width - enclosure_horizontal_inset])
rotate([0, 0, -90])
enclosure_front_etch();
enclosure_front();

// Top and bottom
translate([enclosure_height + kerf_width + enclosure_length_right, enclosure_wall_to_wall_width + kerf_width])
rotate([0, 0, 90])
enclosure_top();
laser_etch()
translate([0, enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width - enclosure_horizontal_inset])
rotate([0, 0, -90])
enclosure_front_etch();

translate([enclosure_height + kerf_width, enclosure_wall_to_wall_width])
rotate([0, 0, -90])
enclosure_bottom();
// Top and bottom
translate([enclosure_height + kerf_width + enclosure_length_right, enclosure_wall_to_wall_width + kerf_width])
rotate([0, 0, 90])
enclosure_top();

// Bottom laser etching
laser_etch()
translate([enclosure_height + kerf_width, enclosure_wall_to_wall_width])
rotate([0, 0, -90])
enclosure_bottom_etch();
enclosure_bottom();

// Spool struts cut out of right side
translate([thickness*2 + 5, enclosure_length + kerf_width + enclosure_length_right - spool_strut_width/2 - 3, thickness])
spool_strut();
// Bottom laser etching
laser_etch()
translate([enclosure_height + kerf_width, enclosure_wall_to_wall_width])
rotate([0, 0, -90])
enclosure_bottom_etch();

// Spool struts at the top
spool_strut_y_offset = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width + kerf_width + spool_strut_width/2;
translate([spool_strut_length, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
// Spool struts cut out of right side
translate([thickness*2 + 5, enclosure_length + kerf_width + enclosure_length_right - spool_strut_width/2 - 3, thickness])
spool_strut();
translate([spool_strut_length*2 + kerf_width, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
spool_strut();
translate([spool_strut_length*3 + kerf_width*2, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
spool_strut();

// Connector brackets on the top right
translate([enclosure_height + kerf_width, 2 * enclosure_wall_to_wall_width + 2 * kerf_width - thickness, 0])
connector_bracket();

translate([enclosure_height + kerf_width + connector_bracket_width - connector_bracket_length_outer, 2 * enclosure_wall_to_wall_width + 3 * kerf_width - thickness + connector_bracket_width + connector_bracket_length_outer, 0])
rotate([0,0,-90])
// Spool struts at the top
spool_strut_y_offset = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width + kerf_width + spool_strut_width/2;
translate([spool_strut_length, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
spool_strut();
translate([spool_strut_length*2 + kerf_width, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
spool_strut();
translate([spool_strut_length*3 + kerf_width*2, spool_strut_y_offset, thickness/2])
rotate([0, 0, 180])
spool_strut();

// Connector brackets on the top right
translate([enclosure_height + kerf_width, 2 * enclosure_wall_to_wall_width + 2 * kerf_width - thickness, 0])
connector_bracket();

// Flap spools in flap window
flap_spool_y_off = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width - front_window_right_inset - enclosure_horizontal_inset - front_window_width/2;
flap_spool_x_off = spool_outer_radius + enclosure_height_lower - front_window_lower + kerf_width + 2;
translate([flap_spool_x_off, flap_spool_y_off])
flap_spool_complete(motor_shaft=true, magnet_hole=true);
translate([flap_spool_x_off + spool_outer_radius*2 + 2, flap_spool_y_off])
flap_spool_complete(captive_nut=true);
translate([enclosure_height + kerf_width + connector_bracket_width - connector_bracket_length_outer, 2 * enclosure_wall_to_wall_width + 3 * kerf_width - thickness + connector_bracket_width + connector_bracket_length_outer, 0])
rotate([0,0,-90])
connector_bracket();

// Flap spool etching
laser_etch() {
// Flap spools in flap window
flap_spool_y_off = enclosure_length + kerf_width + enclosure_length_right + kerf_width + enclosure_width - front_window_right_inset - enclosure_horizontal_inset - front_window_width/2;
flap_spool_x_off = spool_outer_radius + enclosure_height_lower - front_window_lower + kerf_width + 2;
translate([flap_spool_x_off, flap_spool_y_off])
mirror([0, 1, 0])
flap_spool_etch();
flap_spool_complete(motor_shaft=true, magnet_hole=true);
translate([flap_spool_x_off + spool_outer_radius*2 + 2, flap_spool_y_off])
flap_spool_etch();
}
flap_spool_complete(captive_nut=true);

// Spool retaining wall in motor window
translate([enclosure_height_lower + 28byj48_shaft_offset - 28byj48_chassis_radius + (28byj48_chassis_radius + motor_backpack_extent)/2, enclosure_length - front_forward_offset - 28byj48_chassis_radius - motor_hole_slop/2 + spool_strut_width/2 + kerf_width])
spool_retaining_wall(m4_bolt_hole=true);
// Flap spool etching
laser_etch() {
translate([flap_spool_x_off, flap_spool_y_off])
mirror([0, 1, 0])
flap_spool_etch();
translate([flap_spool_x_off + spool_outer_radius*2 + 2, flap_spool_y_off])
flap_spool_etch();
}

// Spool retaining wall in motor window
translate([enclosure_height_lower + 28byj48_shaft_offset - 28byj48_chassis_radius + (28byj48_chassis_radius + motor_backpack_extent)/2, enclosure_length - front_forward_offset - 28byj48_chassis_radius - motor_hole_slop/2 + spool_strut_width/2 + kerf_width])
spool_retaining_wall(m4_bolt_hole=true);

// Sensor soldering jig
translate([enclosure_height_lower + 28byj48_shaft_offset - 28byj48_chassis_radius + (28byj48_chassis_radius + motor_backpack_extent)/2 + sensor_jig_width(pcb_to_spool)/2, enclosure_length - front_forward_offset + 28byj48_chassis_radius + motor_hole_slop/2 - kerf_width])
rotate([0, 0, 180])
sensor_jig(pcb_to_spool);
// Sensor soldering jig
translate([enclosure_height_lower + 28byj48_shaft_offset - 28byj48_chassis_radius + (28byj48_chassis_radius + motor_backpack_extent)/2 + sensor_jig_width(pcb_to_spool)/2, enclosure_length - front_forward_offset + 28byj48_chassis_radius + motor_hole_slop/2 - kerf_width])
rotate([0, 0, 180])
sensor_jig(pcb_to_spool);
}
}
}