コード例 #1
0
        public bool CorrectedPosition_m(double angle, out double X, out double Y)
        {
            if (!Calibrated)
            {
                DialogResult dialogResult = MainForm.ShowMessageBox(
                    "Needle not calibrated. Calibrate now?",
                    "Needle not calibrated", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    X = 0.0;
                    Y = 0.0;
                    return(false);
                }
                ;
                double CurrX = Cnc.CurrentX;
                double CurrY = Cnc.CurrentY;
                double CurrA = Cnc.CurrentA;
                if (!MainForm.CalibrateNeedle_m())
                {
                    X = 0;
                    Y = 0;
                    return(false);
                }
                if (!MainForm.CNC_XYA_m(CurrX, CurrY, CurrA))
                {
                    X = 0;
                    Y = 0;
                    return(false);
                }
            }
            ;

            while (angle < 0)
            {
                angle = angle + 360.0;
            }
            ;
            while (angle > 360.0)
            {
                angle = angle - 360.0;
            }
            // since we are not going to check the last point (which is the cal. value for 360)
            // in the for loop,we check that now
            if (angle > 359.98)
            {
                X = CalibrationPoints[0].X;
                Y = CalibrationPoints[0].Y;
                return(true);
            }
            ;

            for (int i = 0; i < CalibrationPoints.Count; i++)
            {
                if (Math.Abs(angle - CalibrationPoints[i].Angle) < 1.0)
                {
                    X = CalibrationPoints[i].X;
                    Y = CalibrationPoints[i].Y;
                    return(true);
                }
                if ((angle > CalibrationPoints[i].Angle)
                    &&
                    (angle < CalibrationPoints[i + 1].Angle)
                    &&
                    (Math.Abs(angle - CalibrationPoints[i + 1].Angle) > 1.0))
                {
                    // angle is between CalibrationPoints[i] and CalibrationPoints[i+1], and is not == CalibrationPoints[i+1]
                    double fract = (angle - CalibrationPoints[i + 1].Angle) / (CalibrationPoints[i + 1].Angle - CalibrationPoints[i].Angle);
                    X = CalibrationPoints[i].X + fract * (CalibrationPoints[i + 1].X - CalibrationPoints[i].X);
                    Y = CalibrationPoints[i].Y + fract * (CalibrationPoints[i + 1].Y - CalibrationPoints[i].Y);
                    return(true);
                }
            }
            MainForm.ShowMessageBox(
                "Needle Calibration value read: value not found",
                "Sloppy programmer error",
                MessageBoxButtons.OK);
            X = 0;
            Y = 0;
            return(false);
        }
コード例 #2
0
 private bool CNC_XYA(double X, double Y, double A)
 {
     return(MainForm.CNC_XYA_m(X, Y, A));
 }