public static void heuristicLearning() { //find base heights //find heights with each value increased by 1 - HRad, tower offset 1-3, diagonal rod if (UserVariables.advancedCalCount == 0) {//start if (Connection._serialPort.IsOpen) { EEPROM.stepsPerMM += 1; UserInterface.logConsole("Setting steps per millimeter to: " + (EEPROM.stepsPerMM).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 1) {//get diagonal rod percentages UserVariables.deltaTower = ((Heights.teX - Heights.X) + (Heights.teY - Heights.Y) + (Heights.teZ - Heights.Z)) / 3; UserVariables.deltaOpp = ((Heights.teXOpp - Heights.XOpp) + (Heights.teYOpp - Heights.YOpp) + (Heights.teZOpp - Heights.ZOpp)) / 3; if (Connection._serialPort.IsOpen) { EEPROM.stepsPerMM -= 1; UserInterface.logConsole("Setting steps per millimeter to: " + (EEPROM.stepsPerMM).ToString()); //set Hrad +1 EEPROM.HRadius += 1; UserInterface.logConsole("Setting horizontal radius to: " + (EEPROM.HRadius).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 2) {//get HRad percentages UserVariables.HRadRatio = -(Math.Abs((Heights.X - Heights.teX) + (Heights.Y - Heights.teY) + (Heights.Z - Heights.teZ) + (Heights.XOpp - Heights.teXOpp) + (Heights.YOpp - Heights.teYOpp) + (Heights.ZOpp - Heights.teZOpp))) / 6; if (Connection._serialPort.IsOpen) { //reset horizontal radius EEPROM.HRadius -= 1; UserInterface.logConsole("Setting horizontal radius to: " + (EEPROM.HRadius).ToString()); //set X offset EEPROM.offsetX += 80; UserInterface.logConsole("Setting offset X to: " + (EEPROM.offsetX).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 3) {//get X offset percentages UserVariables.offsetCorrection += Math.Abs(1 / (Heights.X - Heights.teX)); UserVariables.mainOppPerc += Math.Abs((Heights.XOpp - Heights.teXOpp) / (Heights.X - Heights.teX)); UserVariables.towPerc += (Math.Abs((Heights.Y - Heights.teY) / (Heights.X - Heights.teX)) + Math.Abs((Heights.Z - Heights.teZ) / (Heights.X - Heights.teX))) / 2; UserVariables.oppPerc += (Math.Abs((Heights.YOpp - Heights.teYOpp) / (Heights.X - Heights.teX)) + Math.Abs((Heights.ZOpp - Heights.teZOpp) / (Heights.X - Heights.teX))) / 2; if (Connection._serialPort.IsOpen) { //reset X offset EEPROM.offsetX -= 80; UserInterface.logConsole("Setting offset X to: " + (EEPROM.offsetX).ToString()); //set Y offset EEPROM.offsetY += 80; UserInterface.logConsole("Setting offset Y to: " + (EEPROM.offsetY).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 4) {//get Y offset percentages UserVariables.offsetCorrection += Math.Abs(1 / (Heights.Y - Heights.teY)); UserVariables.mainOppPerc += Math.Abs((Heights.YOpp - Heights.teYOpp) / (Heights.Y - Heights.teY)); UserVariables.towPerc += (Math.Abs((Heights.X - Heights.teX) / (Heights.Y - Heights.teY)) + Math.Abs((Heights.Z - Heights.teZ) / (Heights.Y - Heights.teY))) / 2; UserVariables.oppPerc += (Math.Abs((Heights.XOpp - Heights.teXOpp) / (Heights.Y - Heights.teY)) + Math.Abs((Heights.ZOpp - Heights.teZOpp) / (Heights.Y - Heights.teY))) / 2; if (Connection._serialPort.IsOpen) { //reset Y offset EEPROM.offsetY -= 80; UserInterface.logConsole("Setting offset Y to: " + (EEPROM.offsetY).ToString()); //set Z offset EEPROM.offsetZ += 80; UserInterface.logConsole("Setting offset Z to: " + (EEPROM.offsetZ).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 5) {//get Z offset percentages UserVariables.offsetCorrection += Math.Abs(1 / (Heights.Z - Heights.teZ)); UserVariables.mainOppPerc += Math.Abs((Heights.ZOpp - Heights.teZOpp) / (Heights.Z - Heights.teZ)); UserVariables.towPerc += (Math.Abs((Heights.X - Heights.teX) / (Heights.Z - Heights.teZ)) + Math.Abs((Heights.Y - Heights.teY) / (Heights.Z - Heights.teZ))) / 2; UserVariables.oppPerc += (Math.Abs((Heights.XOpp - Heights.teXOpp) / (Heights.Z - Heights.teZ)) + Math.Abs((Heights.YOpp - Heights.teYOpp) / (Heights.Z - Heights.teZ))) / 2; if (Connection._serialPort.IsOpen) { //set Z offset EEPROM.offsetZ -= 80; UserInterface.logConsole("Setting offset Z to: " + (EEPROM.offsetZ).ToString()); //set alpha rotation offset perc X EEPROM.A += 1; UserInterface.logConsole("Setting Alpha A to: " + (EEPROM.A).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 6)//6 { //get A alpha rotation UserVariables.alphaRotationPercentage += (2 / Math.Abs((Heights.YOpp - Heights.ZOpp) - (Heights.teYOpp - Heights.teZOpp))); if (Connection._serialPort.IsOpen) { //set alpha rotation offset perc X EEPROM.A -= 1; UserInterface.logConsole("Setting Alpha A to: " + (EEPROM.A).ToString()); //set alpha rotation offset perc Y EEPROM.B += 1; UserInterface.logConsole("Setting Alpha B to: " + (EEPROM.B).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 7) //7 { //get B alpha rotation UserVariables.alphaRotationPercentage += (2 / Math.Abs((Heights.ZOpp - Heights.XOpp) - (Heights.teXOpp - Heights.teXOpp))); if (Connection._serialPort.IsOpen) { //set alpha rotation offset perc Y EEPROM.B -= 1; UserInterface.logConsole("Setting Alpha B to: " + (EEPROM.B).ToString()); //set alpha rotation offset perc Z EEPROM.C += 1; UserInterface.logConsole("Setting Alpha C to: " + (EEPROM.C).ToString()); } //check heights UserVariables.advancedCalCount++; } else if (UserVariables.advancedCalCount == 8) //8 { //get C alpha rotation UserVariables.alphaRotationPercentage += (2 / Math.Abs((Heights.XOpp - Heights.YOpp) - (Heights.teXOpp - Heights.teYOpp))); UserVariables.alphaRotationPercentage /= 3; if (Connection._serialPort.IsOpen) { //set alpha rotation offset perc Z EEPROM.C -= 1; UserInterface.logConsole("Setting Alpha C to: " + (EEPROM.C).ToString()); } UserInterface.logConsole("Alpha offset percentage: " + UserVariables.alphaRotationPercentage); UserVariables.advancedCalibration = false; Program.mainFormTest.setButtonValues(); UserVariables.advancedCalCount = 0; //check heights UserInterface.setAdvancedCalVars(); } GCode.checkHeights = true; }