Exemple #1
0
        private void XY_move(double X, double Y)
        {
            string command;
            double dX = Math.Abs(X - CurrentX);
            double dY = Math.Abs(Y - CurrentY);

            if ((dX < 0.004) && (dY < 0.004))
            {
                MainForm.DisplayText(" -- zero XY movement command --", KnownColor.Gray);
                MainForm.DisplayText("ReadyEvent: zero movement command", KnownColor.Gray);
                _readyEvent.Set();
                return;   // already there
            }
            X = X + SquareCorrection * Y;
            X = Math.Round(X, 3);
            if ((dX < 1) && (dY < 1))
            {
                // Small move
                if (SlowXY)
                {
                    if ((double)Properties.Settings.Default.CNC_SmallMovementSpeed > SlowSpeedXY)
                    {
                        command = SmallMovementString + "X" + X.ToString(CultureInfo.InvariantCulture) +
                                  " Y" + Y.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        command = "G1 F" + SlowSpeedXY.ToString()
                                  + " X" + X.ToString(CultureInfo.InvariantCulture) + " Y" + Y.ToString(CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    command = SmallMovementString + "X" + X.ToString(CultureInfo.InvariantCulture) +
                              " Y" + Y.ToString(CultureInfo.InvariantCulture);
                }
            }
            else
            {
                // large move
                if (SlowXY)
                {
                    command = "G1 F" + SlowSpeedXY.ToString()
                              + " X" + X.ToString(CultureInfo.InvariantCulture) + " Y" + Y.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    command = "G0 " + "X" + X.ToString(CultureInfo.InvariantCulture) + " Y" + Y.ToString(CultureInfo.InvariantCulture);
                }
            }
            _readyEvent.Reset();
            Com.Write("{\"gc\":\"" + command + "\"}");
            _readyEvent.Wait();
        }
Exemple #2
0
        private void XYA_move(double X, double Y, double Am)
        {
            string command;
            double dX = Math.Abs(X - CurrentX);
            double dY = Math.Abs(Y - CurrentY);
            double dA = Math.Abs(Am - CurrentA);

            if ((dX < 0.004) && (dY < 0.004) && (dA < 0.01))
            {
                MainForm.DisplayText(" -- zero XYA movement command --", KnownColor.Gray);
                MainForm.DisplayText("ReadyEvent: zero movement command", KnownColor.Gray);
                _readyEvent.Set();
                return;   // already there
            }

            X = X + SquareCorrection * Y;
            if ((dX < 1.0) && (dY < 1.0))
            {
                // small movement
                // First do XY move, then A. This works always.
                // (small moves and fast settings can sometimes cause problems)
                if ((dX < 0.004) && (dY < 0.004))
                {
                    MainForm.DisplayText(" -- XYA command, XY already there --", KnownColor.Gray);
                }
                else
                {
                    if (SlowXY)
                    {
                        if ((double)Properties.Settings.Default.CNC_SmallMovementSpeed > SlowSpeedXY)
                        {
                            command = SmallMovementString + "X" + X.ToString(CultureInfo.InvariantCulture) +
                                      " Y" + Y.ToString(CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            command = "G1 F" + SlowSpeedXY.ToString()
                                      + " X" + X.ToString(CultureInfo.InvariantCulture) + " Y" + Y.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        command = SmallMovementString + "X" + X.ToString(CultureInfo.InvariantCulture) +
                                  " Y" + Y.ToString(CultureInfo.InvariantCulture);
                    }
                    _readyEvent.Reset();
                    Com.Write("{\"gc\":\"" + command + "\"}");
                    _readyEvent.Wait();
                }

                // then A:
                if (dA < 0.01)
                {
                    MainForm.DisplayText(" -- XYA command, XY already there --", KnownColor.Gray);
                }
                else
                {
                    if (SlowA)
                    {
                        command = "G1 F" + SlowSpeedA.ToString() + " A" + Am.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        command = "G0 A" + Am.ToString(CultureInfo.InvariantCulture);
                    }
                    _readyEvent.Reset();
                    Com.Write("{\"gc\":\"" + command + "\"}");
                    _readyEvent.Wait();
                }
            }
            else
            {
                // normal case, large move
                // Possibilities:
                // SlowA, SlowXY
                // SlowA, FastXY
                // FastA, SlowXY
                // Fast A, Fast XY
                // To avoid side effects, we'll separate a and xy for first three cases
                if (SlowA || (!SlowA && SlowXY))
                {
                    // Do A first, then XY
                    if (dA < 0.01)
                    {
                        MainForm.DisplayText(" -- XYA command, XY already there --", KnownColor.Gray);
                    }
                    else
                    {
                        if (SlowA)
                        {
                            command = "G1 F" + SlowSpeedA.ToString() + " A" + Am.ToString(CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            command = "G0 A" + Am.ToString(CultureInfo.InvariantCulture);
                        }
                        _readyEvent.Reset();
                        Com.Write("{\"gc\":\"" + command + "\"}");
                        _readyEvent.Wait();
                    }
                    // A done, we know XY is slow and large
                    command = "G1 F" + SlowSpeedXY.ToString() +
                              " X" + X.ToString(CultureInfo.InvariantCulture) +
                              " Y" + Y.ToString(CultureInfo.InvariantCulture);
                    _readyEvent.Reset();
                    Com.Write("{\"gc\":\"" + command + "\"}");
                    _readyEvent.Wait();
                }
                else
                {
                    // Fast A, Fast XY
                    command = "G0 " + "X" + X.ToString(CultureInfo.InvariantCulture) +
                              " Y" + Y.ToString(CultureInfo.InvariantCulture) +
                              " A" + Am.ToString(CultureInfo.InvariantCulture);
                    _readyEvent.Reset();
                    Com.Write("{\"gc\":\"" + command + "\"}");
                    _readyEvent.Wait();
                }
            }
        }