Skip to content

Instantly share code, notes, and snippets.

@scamiv
Last active January 23, 2024 15:50
Show Gist options
  • Save scamiv/92495fe963bf4ebaec8c7f5f459fb99d to your computer and use it in GitHub Desktop.
Save scamiv/92495fe963bf4ebaec8c7f5f459fb99d to your computer and use it in GitHub Desktop.
fullcontrol_ledmatrix_grid.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/scamiv/92495fe963bf4ebaec8c7f5f459fb99d/fullcontrol_ledmatrix_grid.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ac9_FmrCOwQL"
},
"source": [
"# FullControl LED-Matrix cover\n",
"\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/scamiv/92495fe963bf4ebaec8c7f5f459fb99d/fullcontrol_ledmatrix_grid.ipynb)\n",
"\n",
"\n",
"press ctrl+F9 to run all cells in this notebook, or press shift+enter to run each cell sequentially\n",
"\n",
"if you change one of the cells, make sure you run it and all subsequent cells again (in order)\n",
"\n",
"\n",
"check out [FullControlXYZ](https://github.com/FullControlXYZ/fullcontrol)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "57XXnogSOvDx",
"cellView": "form"
},
"outputs": [],
"source": [
"# @markdown #setup\n",
"if 'google.colab' in str(get_ipython()):\n",
" !pip install git+https://github.com/FullControlXYZ/fullcontrol --quiet\n",
"import fullcontrol as fc\n",
"from google.colab import files\n",
"from math import tau, radians"
]
},
{
"cell_type": "markdown",
"source": [
"Printer settings.\n",
"\n",
"Speed preset works well with vulcano style hotend"
],
"metadata": {
"id": "GF4sYOJ5mqgy"
}
},
{
"cell_type": "code",
"source": [
"# @markdown #printer settings\n",
"nozzle_temp = 215 # @param {type:\"number\"}\n",
"bed_temp = 60 # @param {type:\"number\"}\n",
"fan_percent = 30 # @param {type:\"number\"} #starts at grid\n",
"printer_name='prusa_i3' # generic / ultimaker2plus / prusa_i3 / ender_3 / cr_10 / bambulab_x1 / toolchanger_T0\n",
"\n",
"# @markdown all speeds in in mm/s, we are extruding 0.3mm layers with 0.8mm thick lines, extrusion rate(see below) will be the limiting factor.\n",
"outline_print_speed = 150 # @param {type:\"number\"}base perimeter\n",
"baseplate_print_speed = 150 # @param {type:\"number\"}\n",
"layer2_print_speed = 100 # @param {type:\"number\"} thin 2nd layer\n",
"main_print_speed = 90 # @param {type:\"number\"}the grid\n",
"upper_print_speed = 85 # @param {type:\"number\"}the \"case\" on top\n",
"\n",
"\n",
"\n",
"#print speeds are pretty much limited by extrusion speed because of the huge EW\n",
"outlineSpeed = outline_print_speed*60\n",
"baseplateSpeed = baseplate_print_speed*60\n",
"\n",
"bottomL2Speed = layer2_print_speed*60\n",
"gridSpeed = main_print_speed*60\n",
"upperSpeed = upper_print_speed*60\n",
"\n",
"#baseSpeed = main_print_speed*60"
],
"metadata": {
"id": "kwMuYtramZZW",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Model generation settings"
],
"metadata": {
"id": "dBjAVnp9mkUL"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "nmayn7bdLttw",
"cellView": "form"
},
"outputs": [],
"source": [
"# @markdown #model parameters\n",
"\n",
"# @markdown number of rectangles in the X/Y direction, must be power of 2\n",
"grid_cells_x = 16 # @param {type:\"integer\"}\n",
"grid_cells_y = 16 # @param {type:\"integer\"}\n",
"# @markdown size of each rectangle in mm (LED spacing)\n",
"line_spacing = 10 # @param {type:\"integer\"} size of the rect\n",
"\n",
"#print 0.1mm 2nd layer to reinforce base, hides 1st layer defects,\n",
"# @markdown print 90deg offset 2nd layer?\n",
"Second_bottom_layer = True # @param {type:\"boolean\"}\n",
"# @markdown determines number of copys of the bottom layer(s), 0 to disable\n",
"bottom_total_height_mm = 1 # @param {type:\"number\"} determines number of copys of the two bottom layers, 0 to disable\n",
"\n",
"# @markdown height(mm) of the rectangular grid\n",
"grid_height = 5 # @param {type:\"number\"}\n",
"\n",
"# @markdown height(mm) of another half grid on top of the grid, spacing for resistors. (0 to disable)\n",
"gap_height = .9 # @param {type:\"number\"}\n",
"\n",
"# @markdown height(mm) of top rectangle, creates space for the pcb (0 to disable)\n",
"height_upper = 0.3 # @param {type:\"number\"}\n",
"\n",
"# @markdown line width, equals extrusion width,use to set grid line thickness\n",
"line_width = 1 # @param {type:\"number\"}\n",
"\n",
"# @markdown overlap ratio betwene \"infill\" lines (extrusion_width*overlap_ratio) reduce value to get higher overlap\n",
"overlap_ratio = 0.8 # @param {type:\"number\"}\n",
"\n",
"\n",
"\n",
"# @markdown layer settings\n",
"layer_height = 0.3 # @param {type:\"number\"}\n",
"# @markdown the \"bottom\" is 2 grids offset 90deg, printing the layer thin helps prettyness\n",
"first_layer_height = 0.15 # @param {type:\"number\"} EH*0.8 # first layer height\n",
"second_layer_height = 0.15 # @param {type:\"number\"} EH*0.8 # 2nd layer height\n",
"first_layer_extrusion_width = 0.42 # @param {type:\"number\"} ew for 1st layer\n",
"\n",
"\n",
"initial_ew = first_layer_extrusion_width\n",
"initial_z = first_layer_height\n",
"EW = line_width\n",
"EH = layer_height #extrusion height (and layer height)"
]
},
{
"cell_type": "markdown",
"source": [
"Resulting extrusion rates. These are going to be your limiting actor, adjust speeds to match your extruder capabilitys.\n"
],
"metadata": {
"id": "pepk-ip9EO5X"
}
},
{
"cell_type": "code",
"source": [
"# @markdown #Run to see resulting extrusion rates.\n",
"outline1_fr = initial_ew * first_layer_height * outline_print_speed\n",
"base1_fr = initial_ew * first_layer_height * baseplate_print_speed\n",
"outline2_fr = line_width * second_layer_height * layer2_print_speed\n",
"base2_fr = line_width * second_layer_height * layer2_print_speed\n",
"grid_fr = line_width * layer_height * main_print_speed\n",
"upper_fr = line_width * layer_height * upper_print_speed\n",
"print(\"L1 Outline Flowrate:\",outline1_fr,\"mm³/s\")\n",
"print(\"L1 Base Flowrate:\",base1_fr,\"mm³/s\")\n",
"print(\"L2 Outline Flowrate:\",outline2_fr,\"mm³/s\")\n",
"print(\"L2 Base Flowrate:\",base2_fr,\"mm³/s\")\n",
"print(\"Grid Flowrate:\",grid_fr,\"mm³/s\")\n",
"print(\"Toprect Flowrate:\",upper_fr,\"mm³/s\")\n",
"\n",
"\n"
],
"metadata": {
"id": "ntv-d-NWvamz",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Generate&Preview"
],
"metadata": {
"id": "Br9QJ1TfnfrI"
}
},
{
"cell_type": "code",
"source": [
"# @markdown #Generate&Preview\n",
"\n",
"sizeX = grid_cells_x * line_spacing\n",
"sizeY = grid_cells_y * line_spacing\n",
"gridLayerCount = int((grid_height)/EH)\n",
"gaplayers=int((gap_height)/EH)\n",
"upperLayerCount = int((height_upper)/EH)\n",
"#baseLayers = int((base_height-initial_z)/EH)\n",
"\n",
"z_clear = 0.05 #clearance for the grid building rectangles\n",
"\n",
"design_name = 'ledMatrix-' + str(grid_cells_x) + \"x\" + str(grid_cells_y) + \" s\" +str(sizeX)+\"x\"+str(sizeY) +\"x\" + str(grid_height) + \"mm\" + \" lh\" + str(EH) + \" ew\" + str(EW) + \" ps\" + str(main_print_speed) + \" t\" +str(nozzle_temp)+\"_\"+str(bed_temp)\n",
"\n",
"amplitudeX = grid_cells_x * line_spacing\n",
"amplitudeY = grid_cells_y * line_spacing\n",
"periodsX = int(grid_cells_x/2)\n",
"periodsY = int(grid_cells_y/2)\n",
"dir=0\n",
"\n",
"# -- 1st layer --\n",
"gap = (initial_ew*overlap_ratio)\n",
"\n",
"base_start_point = fc.Point(x=20, y=20, z=initial_z)\n",
"outline_start_point = fc.relative_point(base_start_point,-gap,-gap,0)\n",
"\n",
"outline = fc.rectangleXY(outline_start_point, sizeX+gap*2, sizeY+gap*2, 1)\n",
"l1_plate = fc.squarewaveXY(base_start_point, fc.Vector(x=1,y=0), amplitudeY, gap, int(periodsX*line_spacing/gap), True, False)\n",
"dir ^= 1\n",
"bottom = [fc.ExtrusionGeometry(height=initial_z,width=initial_ew)] + [fc.Printer(print_speed=outlineSpeed)]\n",
"bottom += outline\n",
"bottom += [fc.Printer(print_speed=baseplateSpeed)] +l1_plate\n",
"\n",
"# --2nd layer --\n",
"if Second_bottom_layer == True:\n",
" gap = (EW*overlap_ratio)\n",
"\n",
" bottom2_start_point = fc.relative_point(bottom,0,0,second_layer_height)\n",
" outline2_start_point = fc.relative_point(bottom,gap, gap, second_layer_height)\n",
"\n",
" outline2 = fc.rectangleXY(outline2_start_point, (sizeX+gap*2)*-1, (sizeY+gap*2)*-1, 1)\n",
" bottom2 = fc.squarewaveXY(bottom2_start_point, fc.Vector(x=0,y=-1), amplitudeX*-1, gap, int(periodsY*line_spacing/gap),True,False)\n",
"\n",
" bottom += [fc.Printer(print_speed=bottomL2Speed)] + [fc.ExtrusionGeometry(height=second_layer_height,width=EW)] + outline2 +bottom2\n",
"else:\n",
" bottom=fc.move_polar(bottom,fc.first_point(bottom),0,radians(180),False,0)\n",
"\n",
"\n",
"\n",
"#do copys\n",
"if bottom_total_height_mm > 0:\n",
" curheight=fc.relative_point(bottom,0,0,0).z #bottom_layer_height+initial_z\n",
" bottom = fc.move(bottom, fc.Vector(z=second_layer_height+initial_z), copy=True, copy_quantity=int(bottom_total_height_mm/curheight))\n",
"\n",
"\n",
"# -- grid start --\n",
"bottom.append(fc.ExtrusionGeometry(height=EH))\n",
"bottom.append(fc.Printer(print_speed=gridSpeed))\n",
"bottom.append(fc.Fan(speed_percent=fan_percent))\n",
"\n",
"wave1_start_point = fc.relative_point(bottom,0,0,EH)\n",
"wave = fc.squarewaveXY(wave1_start_point, fc.Vector(x=dir,y=0), (amplitudeY*-1,amplitudeY)[dir], line_spacing, periodsX, True, False)\n",
"#wave.append(fc.PlotAnnotation(point=wave1_start_point, label=\"start of wave 1\"))\n",
"#wave.append(fc.PlotAnnotation(point=wave[-2], label=\"end of wave 1\"))\n",
"dir ^= 1\n",
"wave2_start_point = fc.relative_point(wave,0,0,z_clear)\n",
"wave2 = fc.squarewaveXY(wave2_start_point, fc.Vector(x=dir,y=-1), (amplitudeX*-1,amplitudeX)[dir], line_spacing, periodsY, True, False)\n",
"#wave2.append(fc.PlotAnnotation(point=wave2[-1], label=\"end of wave 2\"))\n",
"#dir ^= 1\n",
"\n",
"gridlayers = fc.move(wave + wave2, fc.Vector(z=EH), copy=True, copy_quantity=gridLayerCount)\n",
"\n",
"\n",
"#top wave? #creates gaps for resistors\n",
"idir=dir\n",
"wave3_start_point = fc.relative_point(gridlayers,0,0,EH)\n",
"for i in range(gaplayers):\n",
" wave3 = fc.squarewaveXY(wave3_start_point, fc.Vector(x=-dir,y=0), (amplitudeY,amplitudeY*-1)[idir], line_spacing, periodsX-1, True, True)\n",
" wave3_start_point = fc.relative_point(wave3,0,0,EH)\n",
" dir ^= 1\n",
" gridlayers+=wave3\n",
"\n",
"\n",
"# -- rectangle on top --\n",
"upperrect_start_point = fc.relative_point(gridlayers,line_spacing,0,EH)\n",
"\n",
"upperrect = fc.rectangleXY(upperrect_start_point, (sizeX,sizeX*-1)[dir], -sizeY, 0)\n",
"upperlayers = fc.move(upperrect, fc.Vector(z=EH), copy=True, copy_quantity=upperLayerCount)\n",
"\n",
"gridlayers.append(fc.Printer(print_speed=upperSpeed))\n",
"\n",
"# -- done --\n",
"steps=bottom+gridlayers +upperlayers\n",
"\n",
"if Second_bottom_layer == False:\n",
" steps=fc.move_polar(steps,fc.first_point(steps),0,radians(180),False,0) #lets stay positive :)\n",
"\n",
"#retract and wipe at the end\n",
"steps.append(fc.PrinterCommand(id='retract'))\n",
"steps.append(fc.Extruder(on=False))\n",
"#turn off the extruder a bit early?\n",
"#steps.insert(-1,fc.Extruder(on=False))\n",
"steps.append(fc.relative_point(steps[-4],0,0,0)) #move back to the previous point with extruder off\n",
"\n",
"#fc.transform(bottom, 'plot', fc.PlotControls(color_type='print_sequence', style='line'))\n",
"#fc.transform(outline2+outline, 'plot', fc.PlotControls(color_type='print_sequence', style='line'))\n",
"#fc.transform(wave, 'plot', fc.PlotControls(color_type='print_sequence', style='line'))\n",
"#fc.transform(wave2, 'plot', fc.PlotControls(color_type='print_sequence', style='line'))\n",
"\n",
"fc.transform(steps, 'plot', fc.PlotControls(style='tube', zoom=0.7, initialization_data={'extrusion_width': EW, 'extrusion_height': EH}))"
],
"metadata": {
"id": "YtmLaiQqL90V",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Download Gcode"
],
"metadata": {
"id": "7Qz2ctRmnqkH"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "tggFoUeJReQR",
"cellView": "form"
},
"outputs": [],
"source": [
"# @markdown #generate and save gcode\n",
"\n",
"gcode_controls = fc.GcodeControls(\n",
" printer_name=printer_name,\n",
"\n",
" initialization_data={\n",
" 'primer': 'front_lines_then_y',\n",
" 'print_speed': outlineSpeed,\n",
" 'nozzle_temp': nozzle_temp,\n",
" 'bed_temp': bed_temp,\n",
" 'fan_percent': 0,\n",
" 'extrusion_width': initial_ew,\n",
" 'extrusion_height': initial_z})\n",
"gcode = fc.transform(steps, 'gcode', gcode_controls)\n",
"open(f'{design_name}.gcode', 'w').write(gcode)\n",
"files.download(f'{design_name}.gcode')"
]
}
],
"metadata": {
"colab": {
"provenance": [],
"private_outputs": true,
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment