Beispiel #1
0
        private void AddEdge(ProbingViewModel probing, int offsetAxis, int clearanceAxis, double XYClearance)
        {
            AxisFlags probeAxis = GrblInfo.AxisIndexToFlag(clearanceAxis);
            Position  rapidto   = new Position(probing.StartPosition);

            rapidto.Values[clearanceAxis] -= XYClearance * af[clearanceAxis];
            rapidto.Z -= probing.Depth;

            probing.Program.AddRapidToMPos(rapidto, probeAxis);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Z);

            probing.Program.AddProbingAction(probeAxis, af[clearanceAxis] == -1.0d);

            probing.Program.AddRapidToMPos(rapidto, probeAxis);
            rapidto.Values[offsetAxis] = probing.StartPosition.Values[offsetAxis] + probing.Offset * af[offsetAxis];
            probing.Program.AddRapidToMPos(rapidto, GrblInfo.AxisIndexToFlag(offsetAxis));
            probing.Program.AddProbingAction(probeAxis, af[clearanceAxis] == -1.0d);

            probing.Program.AddRapidToMPos(rapidto, probeAxis);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.XY);
        }
Beispiel #2
0
        private void JogCommand(string cmd)
        {
            GrblViewModel model = DataContext as GrblViewModel;

            if (cmd == "stop")
            {
                cmd = ((char)GrblConstants.CMD_JOG_CANCEL).ToString();
            }

            else
            {
                var distance = cmd[1] == '-' ? -JogData.Distance : JogData.Distance;

                if (softLimits)
                {
                    int axis = GrblInfo.AxisLetterToIndex(cmd[0]);

                    if (jogAxis != -1 && axis != jogAxis)
                    {
                        return;
                    }

                    if (axis != jogAxis)
                    {
                        position = distance + model.MachinePosition.Values[axis];
                    }
                    else
                    {
                        position += distance;
                    }

                    if (GrblInfo.ForceSetOrigin)
                    {
                        if (!GrblInfo.HomingDirection.HasFlag(GrblInfo.AxisIndexToFlag(axis)))
                        {
                            if (position > 0d)
                            {
                                position = 0d;
                            }
                            else if (position < (-GrblInfo.MaxTravel.Values[axis] + limitSwitchesClearance))
                            {
                                position = (-GrblInfo.MaxTravel.Values[axis] + limitSwitchesClearance);
                            }
                        }
                        else
                        {
                            if (position < 0d)
                            {
                                position = 0d;
                            }
                            else if (position > (GrblInfo.MaxTravel.Values[axis] - limitSwitchesClearance))
                            {
                                position = GrblInfo.MaxTravel.Values[axis] - limitSwitchesClearance;
                            }
                        }
                    }
                    else
                    {
                        if (position > -limitSwitchesClearance)
                        {
                            position = -limitSwitchesClearance;
                        }
                        else if (position < -(GrblInfo.MaxTravel.Values[axis] - limitSwitchesClearance))
                        {
                            position = -(GrblInfo.MaxTravel.Values[axis] - limitSwitchesClearance);
                        }
                    }

                    if (position == 0d)
                    {
                        return;
                    }

                    jogAxis = axis;

                    cmd = string.Format("$J=G53{0}{1}{2}F{3}", mode, cmd.Substring(0, 1), position.ToInvariantString(), Math.Ceiling(JogData.FeedRate).ToInvariantString());
                }
                else
                {
                    cmd = string.Format("$J=G91{0}{1}{2}F{3}", mode, cmd.Substring(0, 1), distance.ToInvariantString(), Math.Ceiling(JogData.FeedRate).ToInvariantString());
                }
            }

            model.ExecuteCommand(cmd);
        }
Beispiel #3
0
        public bool ProcessKeypress(KeyEventArgs e, bool allowJog)
        {
            bool isJogging = IsJogging;

            double[] dist = new double[3] {
                0d, 0d, 0d
            };

            if (e.IsUp && isJogging)
            {
                bool cancel = !allowJog;

                isJogging = false;

                for (int i = 0; i < 3; i++)
                {
                    if (axisjog[i] == e.Key)
                    {
                        axisjog[i] = Key.None;
                        cancel     = true;
                    }
                    else
                    {
                        isJogging = isJogging || (axisjog[i] != Key.None);
                    }
                }

                isJogging &= allowJog;

                if (cancel && !isJogging && jogMode != JogMode.Step)
                {
                    JogCancel();
                }
            }

            if (!isJogging && allowJog && Comms.com.OutCount != 0)
            {
                return(true);
            }

            if (e.IsDown && CanJog && allowJog)
            {
                // Do not respond to autorepeats!
                if (e.IsRepeat)
                {
                    return(true);
                }

                switch (e.Key)
                {
                case Key.PageUp:
                    isJogging = axisjog[GrblConstants.Z_AXIS] != Key.PageUp;
                    axisjog[GrblConstants.Z_AXIS] = Key.PageUp;
                    break;

                case Key.PageDown:
                    isJogging = axisjog[GrblConstants.Z_AXIS] != Key.PageDown;
                    axisjog[GrblConstants.Z_AXIS] = Key.PageDown;
                    break;

                case Key.Left:
                    isJogging = axisjog[GrblConstants.X_AXIS] != Key.Left;
                    axisjog[GrblConstants.X_AXIS] = Key.Left;
                    break;

                case Key.Up:
                    isJogging = axisjog[GrblConstants.Y_AXIS] != Key.Up;
                    axisjog[GrblConstants.Y_AXIS] = Key.Up;
                    break;

                case Key.Right:
                    isJogging = axisjog[GrblConstants.X_AXIS] != Key.Right;
                    axisjog[GrblConstants.X_AXIS] = Key.Right;
                    break;

                case Key.Down:
                    isJogging = axisjog[GrblConstants.Y_AXIS] != Key.Down;
                    axisjog[GrblConstants.Y_AXIS] = Key.Down;
                    break;
                }
            }

            if (isJogging)
            {
                string command = string.Empty;

                if (GrblInfo.LatheModeEnabled)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        switch (axisjog[i])
                        {
                        case Key.Left:
                            dist[GrblConstants.Z_AXIS] = -1d;
                            command += "Z-{3}";
                            break;

                        case Key.Up:
                            dist[GrblConstants.X_AXIS] = -1d;
                            command += "X-{1}";
                            break;

                        case Key.Right:
                            dist[GrblConstants.Z_AXIS] = 1d;
                            command += "Z{3}";
                            break;

                        case Key.Down:
                            dist[GrblConstants.X_AXIS] = 1d;
                            command += "X{1}";
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        switch (axisjog[i])
                        {
                        case Key.PageUp:
                            dist[GrblConstants.Z_AXIS] = 1d;
                            command += "Z{3}";
                            break;

                        case Key.PageDown:
                            dist[GrblConstants.Z_AXIS] = -1d;
                            command += "Z-{3}";
                            break;

                        case Key.Left:
                            dist[GrblConstants.X_AXIS] = -1d;
                            command += "X-{1}";
                            break;

                        case Key.Up:
                            dist[GrblConstants.Y_AXIS] = 1d;
                            command += "Y{2}";
                            break;

                        case Key.Right:
                            dist[GrblConstants.X_AXIS] = 1d;
                            command += "X{1}";
                            break;

                        case Key.Down:
                            dist[GrblConstants.Y_AXIS] = -1d;
                            command += "Y-{2}";
                            break;
                        }
                    }
                }

                if ((isJogging = command != string.Empty))
                {
                    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            axisjog[i] = Key.None;
                        }
                        preCancel = !(jogMode == JogMode.Step || jogMode == JogMode.None);
                        jogMode   = JogMode.Step;
                        jogDistance[(int)jogMode] = grbl.JogStep;
                    }
                    else if (fullJog)
                    {
                        preCancel = true;
                        if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                        {
                            jogMode = JogMode.Fast;
                        }
                        else
                        {
                            jogMode = JogMode.Slow;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            axisjog[i] = Key.None;
                        }
                        jogMode = JogMode.None;
                    }

                    if (jogMode != JogMode.None)
                    {
                        if (GrblInfo.IsGrblHAL || !softLimits)
                        {
                            var distance = jogDistance[(int)jogMode].ToInvariantString();
                            SendJogCommand("$J=G91G21" + string.Format(command + "F{0}",
                                                                       jogSpeed[(int)jogMode].ToInvariantString(),
                                                                       distance, distance, distance));
                        }
                        else
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                if (dist[i] != 0d)
                                {
                                    if (GrblInfo.HomingDirection.HasFlag(GrblInfo.AxisIndexToFlag(i)))
                                    {
                                        dist[i] = dist[i] < 0d ? grbl.MachinePosition.Values[i] : Math.Max(0d, GrblInfo.MaxTravel.Values[i] - grbl.MachinePosition.Values[i] - .5d);
                                    }
                                    else
                                    {
                                        dist[i] = dist[i] > 0d ? (-grbl.MachinePosition.Values[i] - .5d) : Math.Max(0d, GrblInfo.MaxTravel.Values[i] + grbl.MachinePosition.Values[i] - .5d);
                                    }
                                }
                            }
                            SendJogCommand("$J=G91G21" + string.Format(command + "F{0}",
                                                                       jogSpeed[(int)jogMode].ToInvariantString(),
                                                                       dist[GrblConstants.X_AXIS].ToInvariantString(),
                                                                       dist[GrblConstants.Y_AXIS].ToInvariantString(),
                                                                       dist[GrblConstants.Z_AXIS].ToInvariantString()));
                        }
                    }

                    return(jogMode != JogMode.None);
                }
            }

            if (e.IsUp)
            {
                if (Keyboard.Modifiers == ModifierKeys.Alt)
                {
                    var handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.SystemKey).FirstOrDefault();
                    if (handler != null)
                    {
                        return(handler.Call(e.SystemKey));
                    }
                }
                else if (Keyboard.Modifiers == ModifierKeys.None || Keyboard.Modifiers == ModifierKeys.Control || Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
                {
                    var handler = handlers.Where(k => k.modifiers == Keyboard.Modifiers && k.key == e.Key).FirstOrDefault();
                    if (handler != null)
                    {
                        return(handler.Call(e.Key));
                    }

                    else
                    {
                        switch (e.Key)
                        {
                        case Key.NumPad4:
                            JogControl.JogData.StepDec();
                            return(true);

                        //  break;

                        case Key.NumPad6:
                            JogControl.JogData.StepInc();
                            return(true);

                        case Key.NumPad8:
                            JogControl.JogData.FeedInc();
                            return(true);

                        case Key.NumPad2:
                            JogControl.JogData.FeedDec();
                            return(true);
                            //  break;
                        }
                    }
                }
            }

            return(false);
        }