diff --git a/examples/Schnittdaten-Skripte/Schnitttest erweitert.ls b/examples/Schnittdaten-Skripte/Schnitttest erweitert.ls new file mode 100644 index 0000000..d5f58b7 --- /dev/null +++ b/examples/Schnittdaten-Skripte/Schnitttest erweitert.ls @@ -0,0 +1,344 @@ +// +// Schnitttest-Skript des FabLab Altmühlfranken e.V. +// +// Basiert auf den Testskripten aus dem FabLab Nürnberg. +// +// (c) 2016, juergen@fabmail.org +// (c) 2024, fabian@fablab-altmuehlfranken.de +// +// Distributed under the terms of the GPL v2.0 + +/**** copied from VisiCut example scripts ****/ +function rectangle(x, y, width, height) +{ + move(x, y); + line(x+width, y); + line(x+width, y+height); + line(x, y+height); + line(x, y); +} + +function segmentLine(x1, y1, x2, y2) +{ + move(x1, y1); + line(x2, y2); +} + +function segment7draw (x,y,w,h,values) +{ + var xw = x+w; + var yh = y+h; + var yh2 = y+h/2; + + if (values[0] === 1) //A + { + segmentLine(x, y, xw, y); + } + if (values[1] === 1) //B + { + segmentLine(xw, y, xw, yh2); + } + if (values[2] === 1) //C + { + segmentLine(xw, yh2, xw, yh); + } + if (values[3] === 1) //D + { + segmentLine(xw, yh, x, yh); + } + if (values[4] === 1) //E + { + segmentLine(x, yh, x, yh2); + } + if (values[6] === 1) //G + { + segmentLine(x, yh2, xw, yh2); + } + if (values[5] === 1) //F + { + segmentLine(x, yh2, x, y); + } +} + + +function drawPlus(x,y,w) { + move(x,y+w/2); + line(x+w,y+w/2); + move(x+w/2,y); + line(x+w/2,y+w); +} + +function segment7write (x,y,w,string) +{ + var characterMap = + { + '0': [1, 1, 1, 1, 1, 1, 0], + '1': [0, 1, 1, 0, 0, 0, 0], + '2': [1, 1, 0, 1, 1, 0, 1], + '3': [1, 1, 1, 1, 0, 0, 1], + '4': [0, 1, 1, 0, 0, 1, 1], + '5': [1, 0, 1, 1, 0, 1, 1], + '6': [1, 0, 1, 1, 1, 1, 1], + '7': [1, 1, 1, 0, 0, 0, 0], + '8': [1, 1, 1, 1, 1, 1, 1], + '9': [1, 1, 1, 1, 0, 1, 1], + + 'A': [1, 1, 1, 0, 1, 1, 1], + 'B': [0, 0, 1, 1, 1, 1, 1], + 'C': [1, 0, 0, 1, 1, 1, 0], + 'D': [0, 1, 1, 1, 1, 0, 1], + 'E': [1, 0, 0, 1, 1, 1, 1], + 'F': [1, 0, 0, 0, 1, 1, 1], + 'G': [1, 1, 1, 1, 0, 1, 1], + 'H': [0, 1, 1, 0, 1, 1, 1], + 'I': [0, 0, 0, 0, 1, 1, 0], + 'J': [0, 1, 1, 1, 1, 0, 0], + 'K': [0, 1, 1, 0, 1, 1, 1], + 'L': [0, 0, 0, 1, 1, 1, 0], + 'M': [1, 0, 1, 0, 1, 0, 0], + 'N': [0, 0, 1, 0, 1, 0, 1], + 'O': [1, 1, 1, 1, 1, 1, 0], + 'P': [1, 1, 0, 0, 1, 1, 1], + 'Q': [1, 1, 1, 0, 0, 1, 1], + 'R': [0, 0, 0, 0, 1, 0, 1], + 'S': [1, 0, 1, 1, 0, 1, 1], + 'T': [0, 0, 0, 1, 1, 1, 1], + 'U': [0, 1, 1, 1, 1, 1, 0], + 'V': [0, 0, 1, 1, 1, 0, 0], + 'W': [0, 1, 0, 1, 0, 1, 0], + 'X': [0, 1, 1, 0, 1, 1, 1], + 'Y': [0, 1, 1, 1, 0, 1, 1], + 'Z': [1, 1, 0, 1, 1, 0, 1], + ' ': [0, 0, 0, 0, 0, 0, 0], + '_': [0, 0, 0, 1, 0, 0, 0], + '-': [0, 0, 0, 0, 0, 0, 1], + ',': [0, 0, 1, 0, 0, 0, 0] + + }; + string=string.toUpperCase(); + for (var i = 0; i < string.length; i++) + { + segment7draw(x, y, w, 2*w, characterMap[string[i]]); + x += 1.5*w; + } +} +/**** end of copied data ****/ + + +/* + * global data; copy this script and adjust these values to suit your needs + */ + +// each sample we test will be a square of this width in mm +var squareSize = 6; + +// spacing between the squares, both horizontally and vertically +var squareSpacing = 1.25; + +// if this is set, an outline close to the remaining content will be cut +var cutOutline = true; + +// once enabled, the script will prompt the user for a max/min and step interval for both power and speed +// it's not necessary to adjust the max/min/interval every time, therefore it's handy to use a fixed map to save some time +var promptUserForMaxMinIntervals = true; + +// our goal is to find the fastest setting with the lowest available power that cuts the material as quickly as possible +// therefore, the samples will be layed out in a grid with the available speeds as rows and the available powers as columns +// while the speeds decrease from the available maximum to the minimum, the powers will increase from the minimum to the maximum + + +/* + * end of global data + */ + +function setMarkProfile() { + // "generic" mark profile + set("power", 10); + set("speed", 100); +} + +// perform a focus test from -10 to +10 mm around the set focus (uses some generic mark profile that should work for the majority of materials) +// this is extremely useful to ensure your test sample is cut with the appropriate focus +// note: this only works when the device itself is focused on the material surface +// TODO: is the set (negative) cut focus used at all later on? It looks like the tests run without that value, which could possibly be annoying +function focusTest(x, y) { + setMarkProfile(); + + // focus on the material surface + set("focus", 0); + + // move to set origin + move(x, y); + + // some definitions + var maxLineHeight = 6; + var smallLineHeight = maxLineHeight * 0.75; + var spacing = 1.5; + var minFocus = -10; + var maxFocus = 10; + var fontWidth = 1.2; + + // create a list of items so we can use an integer counter below + var samples = []; + // TODO: consider making these values configurable (note: this will make drawing the "arrow" etc. a lot harder) + for (var focus = minFocus; focus <= maxFocus; ++focus) { + samples.push(focus); + } + + // next up: the actual focus test + for (var i = 0; i < samples.length; ++i) + { + currentFocus = samples[i]; + set("focus", currentFocus); + + // every number divisable by 5 will be drawn a little taller to make the scale more readable + var currentLineHeight = smallLineHeight; + if (currentFocus % 5 == 0) { + currentLineHeight = maxLineHeight; + } + + // mark the actual vertical line + xCoord = x + i * spacing; + move(xCoord, y + maxLineHeight); + line(xCoord, y + maxLineHeight - currentLineHeight); + } + + // set focus back to the material surface + set("focus", 0); + + // draw minimum and maximum values on the edges as well as a zero marker + var yTextOffset = maxLineHeight + 1 * spacing; + + var leftText = minFocus.toString(); + var leftXOffset = 0; + + var rightText = maxFocus.toString(); + // we can subtract the number of characters to align the text properly + // the 1.5 is a correctional factor we need to apply, it is used for some reason (...?) in the 7-segment font code + var rightXOffset = samples.length * spacing - rightText.length * fontWidth * 1.5; + + // draw the texts + segment7write(x + leftXOffset, y + yTextOffset, fontWidth, leftText); + segment7write(x + rightXOffset, y + yTextOffset, fontWidth, rightText); + + // draw a 0 marker, a "roof" with a 45° "slope" + for (var sign = -1; sign <= 1; sign += 2) { + var roofX = x + minFocus * spacing * -1; + move(roofX, y + yTextOffset); + line(roofX + sign * fontWidth * 1.5, y + yTextOffset + fontWidth * 1.5); + } + + // draw the word "focus" left-aligned below the soon-to-be focus test + y += fontWidth * 3 + spacing * 1 + maxLineHeight; + segment7write(x, y, fontWidth, "FOCUS"); +} + + +function cutSpeedTest(contentXOffset, contentYOffset, powersToTest, speedsToTest) { + var fontWidth = 2; + + var firstPowerRowOffset = fontWidth * 3 + squareSpacing; + + // TODO: improve + var speedsText = "speed"; + for (var i = 0; i < speedsText.length; ++i) { + var currentCharYOffset = i * (fontWidth * 3) + firstPowerRowOffset; + segment7write(contentXOffset, contentYOffset + currentCharYOffset, fontWidth, speedsText.slice(i, i+1)); + } + + // move to the right to make room for speedsText + contentXOffset += fontWidth * 1.5 + 2 * squareSpacing; + + // TODO: improve + // this text will be aligned centrally above the X axis + var firstColumnOffset = 3 * fontWidth * 1.5; + var powersText = "power"; + segment7write(contentXOffset + firstColumnOffset + powersToTest.length / 2 * (squareSize + squareSpacing - 0) - (powersText.length / 2) * fontWidth * 1.5, contentYOffset - fontWidth * 3, fontWidth, powersText); + + // write column texts in the first ever row + for (var i = 0; i < powersToTest.length; ++i) { + var currentPower = powersToTest[i]; + var currentPowerText = currentPower.toString(); + + var rowY = contentYOffset; + + var firstColumnOffset = 3 * fontWidth * 1.5; + var currentColumnXOffset = i * (squareSize + squareSpacing) + (3 - currentPowerText.length) / 2; + + setMarkProfile(); + segment7write(contentXOffset + firstColumnOffset + currentColumnXOffset, contentYOffset, fontWidth, currentPowerText); + } + + contentYOffset += firstPowerRowOffset; + + // write row texts and cut series of rectangles + for (var i = 0; i < speedsToTest.length; ++i) { + var currentSpeed = speedsToTest[i]; + var currentSpeedText = currentSpeed.toString(); + + var rowY = contentYOffset + i * (squareSize + squareSpacing); + + // 3 is the maximum number of characters to expect (100 is the max value for either setting) + var alignXOffset = (3 - currentSpeedText.length - 1) * fontWidth * 1.5; + + setMarkProfile(); + segment7write(contentXOffset + alignXOffset, rowY, fontWidth, currentSpeedText); + + // now that we're done writing the text, we can configure the actual cut profile we want to test + set("speed", currentSpeed); + + var textWidth = 3 * fontWidth * 1.5; + + for (var j = 0; j < powersToTest.length; ++j) { + var currentPower = powersToTest[j]; + + set("power", currentPower); + + var currentColumnXOffset = j * (squareSize + squareSpacing); + rectangle(contentXOffset + textWidth + currentColumnXOffset, rowY, squareSize, squareSize); + } + } +} + +// could render at (0, 0), but then again, why not add some spacing right away? +var xOffset = 5; +var yOffset = 5; + +if (cutOutline) { + // TODO + // contentXOffset += + // contentYOffset += +} + +//segment7write(2, 2, 3, "HALLO WELT"); + +focusTest(xOffset, yOffset, -10, 10); + +var powersToTest = []; +var speedsToTest = []; + +if (!promptUserForMaxMinIntervals) { + // these are some good values for general testing, you can always use more fine grained tests + powersToTest = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; + speedsToTest = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5]; +} else { + var minPower = parseFloat(prompt("Min power", 10)); + var maxPower = parseFloat(prompt("Max power", 100)); + var powerInterval = parseFloat(prompt("Power interval", 10)); + + for (var i = minPower; i <= maxPower; i += powerInterval) { + powersToTest.push(i); + } + + var maxSpeed = parseFloat(prompt("Max speed", 100)); + var minSpeed = parseFloat(prompt("Min speed", 10)); + var speedInterval = parseFloat(prompt("Speed interval", 10)); + + for (var i = maxSpeed; i >= minSpeed; i -= speedInterval) { + speedsToTest.push(i); + } +} + +yOffset += 12; + +cutSpeedTest(xOffset, yOffset, powersToTest, speedsToTest);