private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     if (DataContext is GrblViewModel)
     {
         DataContext = model = new ProbingViewModel(DataContext as GrblViewModel);
     }
 }
Exemple #2
0
        private void AddCorner(ProbingViewModel probing, bool negx, bool negy, double XYClearance)
        {
            af[GrblConstants.X_AXIS] = negx ? -1d : 1d;
            af[GrblConstants.Y_AXIS] = negy ? -1d : 1d;

            axisflags = AxisFlags.X | AxisFlags.Y;

            Position rapidto = new Position(probing.StartPosition);

            rapidto.X -= XYClearance * af[GrblConstants.X_AXIS];
            rapidto.Y += probing.Offset * af[GrblConstants.Y_AXIS];
            rapidto.Z -= probing.Depth;

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Y);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Z);

            probing.Program.AddProbingAction(AxisFlags.X, negx);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.X);

            rapidto.X = probing.StartPosition.X + probing.Offset * af[GrblConstants.X_AXIS];
            rapidto.Y = probing.StartPosition.Y;
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X | AxisFlags.Y);
            rapidto.Y = probing.StartPosition.Values[GrblConstants.Y_AXIS] - XYClearance * af[GrblConstants.Y_AXIS];
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Y);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Z);

            probing.Program.AddProbingAction(AxisFlags.Y, negy);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Y);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     if (DataContext is GrblViewModel)
     {
         if (keyboard == null)
         {
             keyboard = new KeypressHandler(DataContext as GrblViewModel);
             keyboard.AddHandler(Key.R, ModifierKeys.Alt, StartProbe);
             keyboard.AddHandler(Key.S, ModifierKeys.Alt, StopProbe);
             keyboard.AddHandler(Key.F1, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F2, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F3, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F4, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F5, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F6, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F7, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F8, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F9, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F10, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F11, ModifierKeys.None, FnKeyHandler);
             keyboard.AddHandler(Key.F12, ModifierKeys.None, FnKeyHandler);
         }
         DataContext = model = new ProbingViewModel(DataContext as GrblViewModel, profiles);
     }
 }
        private void AddCorner(ProbingViewModel probing, bool negx, bool negy)
        {
            string x  = negx ? "X" : "X-";
            string y1 = negy ? "Y" : "Y-";
            string y2 = negy ? "Y-" : "Y";

            af[GrblConstants.X_AXIS] = negx ? -1d : 1d;
            af[GrblConstants.Y_AXIS] = negy ? -1d : 1d;

            axisflags = AxisFlags.X | AxisFlags.Y;

            var rapidto = new Position(probing.StartPosition);

            rapidto.X -= probing.XYClearance * af[GrblConstants.X_AXIS];
            rapidto.Y -= probing.Offset * af[GrblConstants.Y_AXIS];
            rapidto.Z -= probing.Depth;

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

            probing.Program.AddProbingAction(AxisFlags.X, negx);

            probing.Program.AddRapidToMPos(rapidto, axisflags);
            rapidto.X = probing.StartPosition.X - probing.Offset * af[GrblConstants.X_AXIS];
            rapidto.Y = probing.StartPosition.Y - probing.XYClearance * af[GrblConstants.Y_AXIS];
            probing.Program.AddRapidToMPos(rapidto, axisflags);

            probing.Program.AddProbingAction(AxisFlags.Y, negy);

            probing.Program.AddRapid(y1 + probing.XYClearance.ToInvariantString());
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);
        }
Exemple #5
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataContext is GrblViewModel)
            {
                if (keyboard == null)
                {
                    keyboard = new KeypressHandler(DataContext as GrblViewModel);
                }

                DataContext = model = new ProbingViewModel(DataContext as GrblViewModel);
            }
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     if (DataContext is GrblViewModel)
     {
         if (keyboard == null)
         {
             keyboard = new KeypressHandler(DataContext as GrblViewModel);
             keyboard.AddHandler(Key.None, ModifierKeys.Shift, EnableJog);
         }
         DataContext = model = new ProbingViewModel(DataContext as GrblViewModel, profiles);
     }
 }
Exemple #7
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!keyboardMappingsOk && DataContext is GrblViewModel)
            {
                grbl = (DataContext as GrblViewModel);
                KeypressHandler keyboard = grbl.Keyboard;

                keyboardMappingsOk = true;

                keyboard.AddHandler(Key.R, ModifierKeys.Alt, StartProbe, this);
                keyboard.AddHandler(Key.S, ModifierKeys.Alt, StopProbe, this);
                keyboard.AddHandler(Key.C, ModifierKeys.Alt, ProbeConnectedToggle, this);

                DataContext = model = new ProbingViewModel(DataContext as GrblViewModel, profiles);
            }
        }
Exemple #8
0
 public void Add(string name, ProbingViewModel data)
 {
     Profiles.Add(new ProbingProfile
     {
         Id               = id++,
         Name             = name,
         ProbeFeedRate    = data.ProbeFeedRate,
         LatchFeedRate    = data.LatchFeedRate,
         ProbeDistance    = data.ProbeDistance,
         LatchDistance    = data.LatchDistance,
         ProbeDiameter    = data.ProbeDiameter,
         Offset           = data.Offset,
         XYClearance      = data.XYClearance,
         Depth            = data.Depth,
         TouchPlateHeight = data.TouchPlateHeight,
         FixtureHeight    = data.FixtureHeight
     });
 }
Exemple #9
0
        public void Update(int id, string name, ProbingViewModel data)
        {
            var profile = Profiles.Where(x => x.Id == id).FirstOrDefault();

            if (profile != null)
            {
                profile.Name             = name;
                profile.ProbeFeedRate    = data.ProbeFeedRate;
                profile.LatchFeedRate    = data.LatchFeedRate;
                profile.ProbeDistance    = data.ProbeDistance;
                profile.LatchDistance    = data.LatchDistance;
                profile.ProbeDiameter    = data.ProbeDiameter;
                profile.Offset           = data.Offset;
                profile.XYClearance      = data.XYClearance;
                profile.Depth            = data.Depth;
                profile.TouchPlateHeight = data.TouchPlateHeight;
                profile.FixtureHeight    = data.FixtureHeight;
            }
        }
Exemple #10
0
        private void AddEdge(ProbingViewModel probing, char axisletter, bool negative, double XYClearance)
        {
            int axis = GrblInfo.AxisLetterToIndex(axisletter);

            af[axis] = negative ? -1d : 1d;

            axisflags = GrblInfo.AxisLetterToFlag(axisletter);

            var rapidto = new Position(probing.StartPosition);

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

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

            probing.Program.AddProbingAction(axisflags, negative);

            rapidto.Values[axis] = probing.StartPosition.Values[axis] - XYClearance * af[axis];
            probing.Program.AddRapidToMPos(rapidto, axisflags);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);
        }
Exemple #11
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);
        }
Exemple #12
0
        public int Add(string name, ProbingViewModel data)
        {
            Profiles.Add(new ProbingProfile
            {
                Id               = id++,
                Name             = name,
                RapidsFeedRate   = data.RapidsFeedRate,
                ProbeFeedRate    = data.ProbeFeedRate,
                LatchFeedRate    = data.LatchFeedRate,
                ProbeDistance    = data.ProbeDistance,
                LatchDistance    = data.LatchDistance,
                ProbeDiameter    = data.ProbeDiameter,
                Offset           = data.Offset,
                ProbeOffsetX     = data.ProbeOffsetX,
                ProbeOffsetY     = data.ProbeOffsetY,
                XYClearance      = data.XYClearance,
                Depth            = data.Depth,
                TouchPlateHeight = data.TouchPlateHeight,
                FixtureHeight    = data.FixtureHeight
            });

            return(id - 1);
        }
Exemple #13
0
        private bool AddCorner(ProbingViewModel probing, bool negx, bool negy, double XYClearance)
        {
            af[GrblConstants.X_AXIS] = negx ? -1d : 1d;
            af[GrblConstants.Y_AXIS] = negy ? -1d : 1d;

            axisflags = AxisFlags.X | AxisFlags.Y;

            if (XYClearance > probing.Offset && MessageBox.Show("Offset is less than XY Clearance + ½ Probe/tool diameter.\nUse Offset as clearance and run anyway?", "GCode Sender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return(false);
            }

            XYClearance = Math.Min(XYClearance, probing.Offset);

            var rapidto = new Position(probing.StartPosition);

            rapidto.X -= XYClearance * af[GrblConstants.X_AXIS];
            rapidto.Y -= probing.Offset * af[GrblConstants.Y_AXIS];
            rapidto.Z -= probing.Depth;

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X | AxisFlags.Y);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Z);

            probing.Program.AddProbingAction(AxisFlags.X, negx);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X);
            rapidto.X = probing.StartPosition.X - probing.Offset * af[GrblConstants.X_AXIS];
            rapidto.Y = probing.StartPosition.Y - XYClearance * af[GrblConstants.Y_AXIS];
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X | AxisFlags.Y);

            probing.Program.AddProbingAction(AxisFlags.Y, negy);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Y);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);

            return(true);
        }
Exemple #14
0
        private bool AddCorner(ProbingViewModel probing, bool negx, bool negy, double XYClearance)
        {
            af[GrblConstants.X_AXIS] = negx ? -1d : 1d;
            af[GrblConstants.Y_AXIS] = negy ? -1d : 1d;

            axisflags = AxisFlags.X | AxisFlags.Y;

            if (XYClearance > probing.Offset && MessageBox.Show(((string)FindResource("OffsetWarning")).Replace("\\n", "\n"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return(false);
            }

            XYClearance = Math.Min(XYClearance, probing.Offset);

            var rapidto = new Position(probing.StartPosition);

            rapidto.X -= XYClearance * af[GrblConstants.X_AXIS];
            rapidto.Y -= probing.Offset * af[GrblConstants.Y_AXIS];
            rapidto.Z -= probing.Depth;

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X | AxisFlags.Y);
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Z);

            probing.Program.AddProbingAction(AxisFlags.X, negx);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X);
            rapidto.X = probing.StartPosition.X - probing.Offset * af[GrblConstants.X_AXIS];
            rapidto.Y = probing.StartPosition.Y - XYClearance * af[GrblConstants.Y_AXIS];
            probing.Program.AddRapidToMPos(rapidto, AxisFlags.X | AxisFlags.Y);

            probing.Program.AddProbingAction(AxisFlags.Y, negy);

            probing.Program.AddRapidToMPos(rapidto, AxisFlags.Y);
            probing.Program.AddRapidToMPos(probing.StartPosition, AxisFlags.Z);

            return(true);
        }
Exemple #15
0
 public Program(ProbingViewModel model)
 {
     Grbl    = model.Grbl;
     probing = model;
 }
Exemple #16
0
 public GCodeTransform(ProbingViewModel model)
 {
     this.model = model;
 }
Exemple #17
0
        public void ApplyHeightMap(ProbingViewModel model)
        {
            HeightMap map           = model.HeightMap.Map;
            double    segmentLength = Math.Min(map.GridX, map.GridY);
            int       precision     = model.Grbl.Precision;

            GCPlane      plane        = new GCPlane(GrblParserState.Plane == Plane.XY ? Commands.G17 : Commands.G18, 0);
            DistanceMode distanceMode = GrblParserState.DistanceMode;

            Vector3 pos = new Vector3(model.Grbl.Position.X, model.Grbl.Position.Y, model.Grbl.Position.Z);

            List <GCodeToken> newToolPath = new List <GCodeToken>();

            uint lnr = 1;

            foreach (var token in GCode.File.Tokens)
            {
                switch (token.Command)
                {
                case Commands.G0:
                case Commands.G1:
                {
                    var motion = token as GCLinearMotion;

                    var m = new Line(motion.AxisFlags);
                    m.Start = pos;
                    m.End   = pos = ToAbsolute(pos, motion.Values, distanceMode == DistanceMode.Incremental);
                    m.Rapid = token.Command == Commands.G0;

                    foreach (Motion subMotion in m.Split(segmentLength))
                    {
                        Vector3 target = new Vector3(Math.Round(subMotion.End.X, precision), Math.Round(subMotion.End.Y, precision), Math.Round(subMotion.End.Z + map.InterpolateZ(subMotion.End.X, subMotion.End.Y), precision));

                        newToolPath.Add(new GCLinearMotion(motion.Command, lnr++, target.Array, motion.AxisFlags | AxisFlags.Z));
                    }
                }
                break;

                case Commands.G2:
                case Commands.G3:
                {
                    if (plane.Plane != Plane.XY)
                    {
                        throw new Exception(LibStrings.FindResource("HasRadiusArcs"));
                    }

                    var      arc    = token as GCArc;
                    double[] center = arc.GetCenter(plane, pos.Array);
                    double[] ijk    = new double[3];

                    Array.Copy(arc.IJKvalues, ijk, 3);

                    var m = new Arc();
                    m.Start     = pos;
                    m.End       = pos = ToAbsolute(pos, arc.Values, distanceMode == DistanceMode.Incremental);
                    m.Direction = token.Command == Commands.G2 ? ArcDirection.CW : ArcDirection.CCW;
                    m.U         = center[0];
                    m.V         = center[1];
                    m.Plane     = ArcPlane.XY;

                    foreach (Motion subMotion in m.Split(segmentLength))
                    {
                        if (!arc.IsRadiusMode)
                        {
                            ijk[0] = Math.Round(center[0] - subMotion.Start.X, precision);
                            ijk[1] = Math.Round(center[1] - subMotion.Start.Y, precision);
                        }

                        Vector3 target = new Vector3(Math.Round(subMotion.End.X, precision), Math.Round(subMotion.End.Y, precision), Math.Round(subMotion.End.Z + map.InterpolateZ(subMotion.End.X, subMotion.End.Y), precision));

                        newToolPath.Add(new GCArc(arc.Command, lnr++, target.Array, arc.AxisFlags | AxisFlags.Z, ijk, arc.IjkFlags, arc.R, arc.IJKMode));
                    }
                }
                break;

                case Commands.G17:
                case Commands.G18:
                case Commands.G19:
                    plane = token as GCPlane;
                    newToolPath.Add(token);
                    break;

                case Commands.G90:
                case Commands.G91:
                    distanceMode = (token as GCDistanceMode).DistanceMode;
                    newToolPath.Add(token);
                    break;

                default:
                    newToolPath.Add(token);
                    break;
                }
            }

            List <string> gc = GCodeParser.TokensToGCode(newToolPath, AppConfig.Settings.Base.AutoCompress);

//            GCodeParser.Save(@"C:\Users\terjeio\Desktop\Probing\file.nc", gc);

            GCode.File.AddBlock(string.Format("Heightmap applied: {0}", model.Grbl.FileName), Core.Action.New);

            foreach (string block in gc)
            {
                GCode.File.AddBlock(block, Core.Action.Add);
            }

            GCode.File.AddBlock("", Core.Action.End);

            model.HeightMapApplied = true;
        }