Example #1
0
 public static void printHeights()
 {
     UserInterface.logConsole("Center:" + Heights.center + " X:" + Heights.X + " XOpp:" + Heights.XOpp + " Y:" + Heights.Y + " YOpp:" + Heights.YOpp + " Z:" + Heights.Z + " ZOpp:" + Heights.ZOpp);
 }
Example #2
0
        private static void alphaRotation(ref float X, ref float XOpp, ref float Y, ref float YOpp, ref float Z, ref float ZOpp)
        {
            float offsetX  = EEPROM.offsetX;
            float offsetY  = EEPROM.offsetY;
            float offsetZ  = EEPROM.offsetZ;
            float accuracy = UserVariables.accuracy;

            //change to object
            float alphaRotationPercentage = UserVariables.alphaRotationPercentage;

            int k = 0;

            while (k < 100)
            {
                //X Alpha Rotation
                if (YOpp > ZOpp)
                {
                    float ZYOppAvg = (YOpp - ZOpp) / 2;
                    EEPROM.A = EEPROM.A + (ZYOppAvg * alphaRotationPercentage); // (0.5/((diff y0 and z0 at X + 0.5)-(diff y0 and z0 at X = 0))) * 2 = 1.75
                    YOpp     = YOpp - ZYOppAvg;
                    ZOpp     = ZOpp + ZYOppAvg;
                }
                else if (YOpp < ZOpp)
                {
                    float ZYOppAvg = (ZOpp - YOpp) / 2;

                    EEPROM.A = EEPROM.A - (ZYOppAvg * alphaRotationPercentage);
                    YOpp     = YOpp + ZYOppAvg;
                    ZOpp     = ZOpp - ZYOppAvg;
                }

                //Y Alpha Rotation
                if (ZOpp > XOpp)
                {
                    float XZOppAvg = (ZOpp - XOpp) / 2;
                    EEPROM.B = EEPROM.B + (XZOppAvg * alphaRotationPercentage);
                    ZOpp     = ZOpp - XZOppAvg;
                    XOpp     = XOpp + XZOppAvg;
                }
                else if (ZOpp < XOpp)
                {
                    float XZOppAvg = (XOpp - ZOpp) / 2;

                    EEPROM.B = EEPROM.B - (XZOppAvg * alphaRotationPercentage);
                    ZOpp     = ZOpp + XZOppAvg;
                    XOpp     = XOpp - XZOppAvg;
                }
                //Z Alpha Rotation
                if (XOpp > YOpp)
                {
                    float YXOppAvg = (XOpp - YOpp) / 2;
                    EEPROM.C = EEPROM.C + (YXOppAvg * alphaRotationPercentage);
                    XOpp     = XOpp - YXOppAvg;
                    YOpp     = YOpp + YXOppAvg;
                }
                else if (XOpp < YOpp)
                {
                    float YXOppAvg = (YOpp - XOpp) / 2;

                    EEPROM.C = EEPROM.C - (YXOppAvg * alphaRotationPercentage);
                    XOpp     = XOpp + YXOppAvg;
                    YOpp     = YOpp - YXOppAvg;
                }

                //determine if value is close enough
                float hTow    = Math.Max(Math.Max(XOpp, YOpp), ZOpp);
                float lTow    = Math.Min(Math.Min(XOpp, YOpp), ZOpp);
                float towDiff = hTow - lTow;

                if (towDiff < UserVariables.calculationAccuracy && towDiff > -UserVariables.calculationAccuracy)
                {
                    k = 100;

                    //log
                    UserInterface.logConsole("ABC:" + EEPROM.A + " " + EEPROM.B + " " + EEPROM.C);
                }
                else
                {
                    k++;
                }
            }
        }
Example #3
0
        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;
        }
Example #4
0
        /*
         * public void analyzeGeometry(float X, float XOpp, float Y, float YOpp, float Z, float ZOpp)
         * {
         *  int analyzeCount = 0;
         *
         *
         *  UserInterface.logConsole("Expect a slight inaccuracy in the geometry analysis; basic calibration.");
         * }
         */

        private static void towerOffsets(ref float X, ref float XOpp, ref float Y, ref float YOpp, ref float Z, ref float ZOpp)
        {
            int   j          = 0;
            float accuracy   = UserVariables.calculationAccuracy;
            float tempX2     = X;
            float tempXOpp2  = XOpp;
            float tempY2     = Y;
            float tempYOpp2  = YOpp;
            float tempZ2     = Z;
            float tempZOpp2  = ZOpp;
            float offsetX    = EEPROM.offsetX;
            float offsetY    = EEPROM.offsetY;
            float offsetZ    = EEPROM.offsetZ;
            float stepsPerMM = EEPROM.stepsPerMM;

            while (j < 100)
            {
                if (Math.Abs(tempX2) > UserVariables.accuracy / 2 || Math.Abs(tempY2) > UserVariables.accuracy / 2 || Math.Abs(tempZ2) > UserVariables.accuracy / 2)
                {
                    offsetX += tempX2 * stepsPerMM * (1 / 0.60F);

                    tempXOpp2 += tempX2 * (0.5F / 0.60F);
                    tempY2    += tempX2 * (0.3F / 0.60F);
                    tempYOpp2 += tempX2 * (-0.25F / 0.60F);
                    tempZ2    += tempX2 * (0.3F / 0.60F);
                    tempZOpp2 += tempX2 * (-0.25F / 0.60F);
                    tempX2    += tempX2 / -1;

                    offsetY += tempY2 * stepsPerMM * (1 / 0.60F);

                    tempYOpp2 += tempY2 * (0.5F / 0.60F);
                    tempX2    += tempY2 * (0.3F / 0.60F);
                    tempXOpp2 += tempY2 * (-0.25F / 0.60F);
                    tempZ2    += tempY2 * (0.3F / 0.60F);
                    tempZOpp2 += tempY2 * (-0.25F / 0.60F);
                    tempY2    += tempY2 / -1;

                    offsetZ += tempZ2 * stepsPerMM * (1 / 0.60F);

                    tempZOpp2 += tempZ2 * (0.5F / 0.60F);
                    tempX2    += tempZ2 * (0.3F / 0.60F);
                    tempXOpp2 += tempZ2 * (-0.25F / 0.60F);
                    tempY2    += tempZ2 * (0.3F / 0.60F);
                    tempYOpp2 += tempZ2 * (-0.25F / 0.60F);
                    tempZ2    += tempZ2 / -1;

                    tempX2    = Validation.checkZero(tempX2);
                    tempY2    = Validation.checkZero(tempY2);
                    tempZ2    = Validation.checkZero(tempZ2);
                    tempXOpp2 = Validation.checkZero(tempXOpp2);
                    tempYOpp2 = Validation.checkZero(tempYOpp2);
                    tempZOpp2 = Validation.checkZero(tempZOpp2);

                    float tempComb    = tempX2 + tempY2 + tempZ2;
                    float tempCombAbs = Math.Abs(tempX2) + Math.Abs(tempY2) + Math.Abs(tempZ2);

                    if (Math.Abs(tempX2) <= UserVariables.accuracy && Math.Abs(tempY2) <= UserVariables.accuracy && Math.Abs(tempZ2) <= UserVariables.accuracy)
                    {
                        UserInterface.logConsole("VHeights :" + tempX2 + " " + tempXOpp2 + " " + tempY2 + " " + tempYOpp2 + " " + tempZ2 + " " + tempZOpp2);
                        UserInterface.logConsole("Offs :" + offsetX + " " + offsetY + " " + offsetZ);
                        UserInterface.logConsole("No Drad correction");

                        float smallest = Math.Min(offsetX, Math.Min(offsetY, offsetZ));

                        offsetX -= smallest;
                        offsetY -= smallest;
                        offsetZ -= smallest;

                        UserInterface.logConsole("Offs :" + offsetX + " " + offsetY + " " + offsetZ);

                        X    = tempX2;
                        XOpp = tempXOpp2;
                        Y    = tempY2;
                        YOpp = tempYOpp2;
                        Z    = tempZ2;
                        ZOpp = tempZOpp2;

                        //round to the nearest whole number
                        EEPROM.offsetX = Convert.ToInt32(offsetX);
                        EEPROM.offsetY = Convert.ToInt32(offsetY);
                        EEPROM.offsetZ = Convert.ToInt32(offsetZ);

                        j = 100;
                    }
                    else if (j == 99)
                    {
                        UserInterface.logConsole("VHeights :" + tempX2 + " " + tempXOpp2 + " " + tempY2 + " " + tempYOpp2 + " " + tempZ2 + " " + tempZOpp2);
                        UserInterface.logConsole("Offs :" + offsetX + " " + offsetY + " " + offsetZ);
                        float dradCorr = tempComb * -0.85F;

                        EEPROM.DA += dradCorr;
                        EEPROM.DB += dradCorr;
                        EEPROM.DC += dradCorr;

                        EEPROM.offsetX = 200;
                        EEPROM.offsetY = 200;
                        EEPROM.offsetZ = 200;

                        UserInterface.logConsole("Drad correction: " + dradCorr);
                        UserInterface.logConsole("DRad: " + EEPROM.DA.ToString() + ", " + EEPROM.DB.ToString() + ", " + EEPROM.DC.ToString());

                        j = 100;
                    }
                    else
                    {
                        j++;
                    }

                    //UserInterface.logConsole("Offs :" + offsetX + " " + offsetY + " " + offsetZ);
                    //UserInterface.logConsole("VHeights :" + tempX2 + " " + tempXOpp2 + " " + tempY2 + " " + tempYOpp2 + " " + tempZ2 + " " + tempZOpp2);
                }
                else
                {
                    xyzOffset = false;
                    j         = 100;
                }
            }

            if (EEPROM.offsetX > 1000 || EEPROM.offsetY > 1000 || EEPROM.offsetZ > 1000)
            {
                UserInterface.logConsole("XYZ offset calibration error, setting default values.");
                UserInterface.logConsole("XYZ offsets before damage prevention: X" + offsetX + " Y" + offsetY + " Z" + offsetZ);
                offsetX = 0;
                offsetY = 0;
                offsetZ = 0;
            }
        }