Skip to content

Commit

Permalink
Release 2.0.42
Browse files Browse the repository at this point in the history
See the changelog for details.
  • Loading branch information
terjeio committed Mar 22, 2023
1 parent 6a7f84b commit ad7a4f6
Show file tree
Hide file tree
Showing 67 changed files with 1,417 additions and 264 deletions.
6 changes: 3 additions & 3 deletions CNC Controls Camera/CNC Controls Camera/CameraControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* CameraControl.xaml.cs - part of CNC Controls Camera library
*
* v0.38 / 2022-04-20 / Io Engineering (Terje Io)
* v0.42 / 2023-03-22 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2018-2022, Io Engineering (Terje Io) - parts derived from AForge example code
Copyright (c) 2018-2023, Io Engineering (Terje Io) - parts derived from AForge example code
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -261,7 +261,7 @@ private void btnMove_Click(object sender, RoutedEventArgs e)

private void btnPublish_Click(object sender, RoutedEventArgs e)
{
Position pos = new Position(Grbl.GrblViewModel.MachinePosition);
Position pos = new Position(Grbl.GrblViewModel.MachinePosition, Grbl.GrblViewModel.UnitFactor);

pos.X += XOffset;
pos.Y += YOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Io Engineering")]
[assembly: AssemblyProduct("ioSender")]
[assembly: AssemblyCopyright("Copyright © 2021 Io Engineering")]
[assembly: AssemblyCopyright("Copyright © 2023 Io Engineering")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
Expand Down Expand Up @@ -52,5 +52,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.38.0")]
[assembly: AssemblyFileVersion("2.0.38.0")]
[assembly: AssemblyVersion("2.0.42.0")]
[assembly: AssemblyFileVersion("2.0.42.0")]
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* CenterFinderControl.xaml.cs - part of CNC Probing library
*
* v0.41 / 2022-11-13 / Io Engineering (Terje Io)
* v0.42 / 2023-03-22 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2022, Io Engineering (Terje Io)
Copyright (c) 2020-2023, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -387,7 +387,7 @@ private bool OnCompleted()
case ProbingViewModel.CoordMode.Measure:
center.X += probing.ProbeOffsetX;
center.Y += probing.ProbeOffsetY;
probing.Measurement.Add(center, axisflags, ProbingType);
probing.Measurement.Add(new Position(center, 1d / probing.Grbl.UnitFactor), axisflags, ProbingType);
break;

case ProbingViewModel.CoordMode.G92:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* EdgeFinderControl.xaml.cs - part of CNC Probing library
*
* v0.41 / 2022-11-13 / Io Engineering (Terje Io)
* v0.42 / 2023-03-22 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2022, Io Engineering (Terje Io)
Copyright (c) 2020-2023, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -267,7 +267,7 @@ private void OnCompleted ()
ok = ok && !isCancelled && probing.RemoveLastPosition();
if ((ok = ok && !isCancelled && probing.WaitForResponse(probing.SlowProbe + "Z-" + probing.Depth.ToInvariantString())))
{
pos.Z = probing.Grbl.ProbePosition.Z;
pos.Z = probing.Grbl.ProbePosition.Z * probing.Grbl.UnitFactor;
ok = !isCancelled && probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
}
}
Expand All @@ -287,7 +287,7 @@ private void OnCompleted ()
pos.X += probing.ProbeOffsetX;
pos.Y += probing.ProbeOffsetY;
pos.Z -= probing.WorkpieceHeight + probing.TouchPlateHeight + probing.Grbl.ToolOffset.Z;
probing.Measurement.Add(pos, axisflags, ProbingType);
probing.Measurement.Add(new Position(pos, 1d / probing.Grbl.UnitFactor), axisflags, ProbingType);
break;

case ProbingViewModel.CoordMode.G92:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* EdgeFinderIntControl.xaml.cs - part of CNC Probing library
*
* v0.41 / 2022-11-13 / Io Engineering (Terje Io)
* v0.42 / 2023-03-22 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2022, Io Engineering (Terje Io)
Copyright (c) 2020-2023, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -256,7 +256,7 @@ private void OnCompleted()
ok = ok && !isCancelled && probing.RemoveLastPosition();
if ((ok = ok && !isCancelled && probing.WaitForResponse(probing.SlowProbe + "Z-" + probing.Depth.ToInvariantString())))
{
pos.Z = probing.Grbl.ProbePosition.Z;
pos.Z = probing.Grbl.ProbePosition.Z * probing.Grbl.UnitFactor;
ok = !isCancelled && probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
}
}
Expand All @@ -275,7 +275,7 @@ private void OnCompleted()
pos.X += probing.ProbeOffsetX;
pos.Y += probing.ProbeOffsetY;
pos.Z -= probing.WorkpieceHeight + probing.TouchPlateHeight + probing.Grbl.ToolOffset.Z;
probing.Measurement.Add(pos, axisflags, ProbingType);
probing.Measurement.Add(new Position(pos, 1d / probing.Grbl.UnitFactor), axisflags, ProbingType);
break;

case ProbingViewModel.CoordMode.G92:
Expand Down
31 changes: 25 additions & 6 deletions CNC Controls Probing/CNC Controls Probing/GCodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using RP.Math;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CNC.Controls.Probing
{
Expand Down Expand Up @@ -41,8 +40,8 @@ public void ApplyHeightMap(ProbingViewModel model)

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);
Position position = new Position(model.Grbl.Position, model.Grbl.UnitFactor);
Vector3 pos = new Vector3(position.X, position.Y, position.Z);

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

Expand All @@ -56,6 +55,7 @@ public void ApplyHeightMap(ProbingViewModel model)
case Commands.G1:
{
var motion = token as GCLinearMotion;
// GCLinearMotion last_segment = null;

var m = new Line(motion.AxisFlags);
m.Start = pos;
Expand All @@ -66,8 +66,10 @@ public void ApplyHeightMap(ProbingViewModel model)
{
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));
newToolPath.Add(/*last_segment = */new GCLinearMotion(motion.Command, lnr++, target.Array, motion.AxisFlags | AxisFlags.Z));
}
// if(last_segment != null)
// pos = ToAbsolute(pos, last_segment.Values);
}
break;

Expand All @@ -78,6 +80,7 @@ public void ApplyHeightMap(ProbingViewModel model)
throw new Exception(LibStrings.FindResource("HasRadiusArcs"));

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

Expand All @@ -99,10 +102,26 @@ public void ApplyHeightMap(ProbingViewModel model)
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));
// 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));
Vector3 target = new Vector3(subMotion.End.X, subMotion.End.Y, subMotion.End.Z + map.InterpolateZ(subMotion.End.X, subMotion.End.Y));

target = new Vector3(Math.Round(target.X, precision), Math.Round(target.Y, precision), Math.Round(target.Z, precision));

AxisFlags axisFlags = AxisFlags.XYZ;
if(last_segment != null)
{
if (last_segment.X == target.X)
axisFlags &= ~AxisFlags.X;
if (last_segment.Y == target.Y)
axisFlags &= ~AxisFlags.Y;
if (last_segment.Z == target.Z)
axisFlags &= ~AxisFlags.Z;
}

newToolPath.Add(new GCArc(arc.Command, lnr++, target.Array, arc.AxisFlags | AxisFlags.Z, ijk, arc.IjkFlags, arc.R, arc.P, arc.IJKMode));
newToolPath.Add(last_segment = new GCArc(arc.Command, lnr++, target.Array, axisFlags, ijk, arc.IjkFlags, arc.R, arc.P, arc.IJKMode));
}
// if (last_segment != null)
// pos = ToAbsolute(pos, last_segment.Values);
}
break;

Expand Down
5 changes: 4 additions & 1 deletion CNC Controls Probing/CNC Controls Probing/HeightMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020-09-20 : Added constructor for separate X and Y grid sizes
2022-01-23 : Added check for rapid motions and motion validity
2023-03-02 : Added Z offset
*/

Expand Down Expand Up @@ -81,6 +82,7 @@ public class HeightMap

public double MinHeight { get; private set; } = double.MaxValue;
public double MaxHeight { get; private set; } = double.MinValue;
public double ZOffset { get; set; } = 0d;

public event Action MapUpdated;

Expand Down Expand Up @@ -160,7 +162,7 @@ public double InterpolateZ(double x, double y)
double linUpper = Points[iHX, iHY].Value * fX + Points[iLX, iHY].Value * (1 - fX); //linear immediates
double linLower = Points[iHX, iLY].Value * fX + Points[iLX, iLY].Value * (1 - fX);

return linUpper * fY + linLower * (1 - fY); //bilinear result
return linUpper * fY + linLower * (1 - fY) + ZOffset; //bilinear result
}

public Vector2 GetCoordinates(int x, int y)
Expand Down Expand Up @@ -251,6 +253,7 @@ public void Save(string path)
w.WriteAttributeString("MaxY", Max.Y.ToString(Constants.DecimalParseFormat));
w.WriteAttributeString("SizeX", SizeX.ToString(Constants.DecimalParseFormat));
w.WriteAttributeString("SizeY", SizeY.ToString(Constants.DecimalParseFormat));
w.WriteAttributeString("ZOffset", ZOffset.ToString(Constants.DecimalParseFormat));
for (int x = 0; x < SizeX; x++)
{
for (int y = 0; y < SizeY; y++)
Expand Down
55 changes: 32 additions & 23 deletions CNC Controls Probing/CNC Controls Probing/HeightMapControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* HeightMapControl.xaml.cs - part of CNC Probing library
*
* v0.41 / 2022-11-13 / Io Engineering (Terje Io)
* v0.42 / 2023-03-22 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2022, Io Engineering (Terje Io)
Copyright (c) 2020-2023, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -53,6 +53,7 @@ namespace CNC.Controls.Probing
public partial class HeightMapControl : UserControl, IProbeTab
{
private int x, y;
private Position origin;

public HeightMapControl()
{
Expand All @@ -75,6 +76,8 @@ public void Start(bool preview = false)
if (!probing.ValidateInput(true))
return;

origin = new Position(probing.Grbl.MachinePosition, probing.Grbl.UnitFactor);

if (!probing.WaitForIdle(string.Format("G90G0X{0}Y{1}", probing.HeightMap.MinX.ToInvariantString(), probing.HeightMap.MinY.ToInvariantString())))
return;

Expand Down Expand Up @@ -141,22 +144,6 @@ private void OnCompleted()

if ((ok = probing.IsSuccess && probing.Positions.Count == probing.HeightMap.Map.TotalPoints))
{
probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
probing.GotoMachinePosition(probing.StartPosition, AxisFlags.X | AxisFlags.Y);

if (probing.HeightMap.SetToolOffset)
{
if (probing.CoordinateMode == ProbingViewModel.CoordMode.G10)
probing.Grbl.ExecuteCommand(string.Format("G10L2P{0}Z{1}", probing.CoordinateSystem, (probing.Positions[0].Z - probing.Grbl.ToolOffset.Z).ToInvariantString()));
else if ((ok == probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
{
probing.Grbl.ExecuteCommand("G92Z0");
probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
if (!probing.Grbl.IsParserStateLive)
probing.Grbl.ExecuteCommand("$G");
}
}

double Z0 = probing.Positions[0].Z, z_min = 0d, z_max = 0d, z_delta;

int i = 0;
Expand Down Expand Up @@ -194,7 +181,27 @@ private void OnCompleted()
probing.HeightMap.MapPoints = mapPoints.Points;
probing.HeightMap.HasHeightMap = true;

if(ok)
// double z = probing.HeightMap.Map.InterpolateZ(0d, 0d);

if (probing.HeightMap.SetToolOffset &&
(ok = (probing.Positions[0].X == origin.X && probing.Positions[0].Y == origin.Y) || probing.Program.ProbeZ(0d, 0d)))
{
probing.HeightMap.Map.ZOffset = Z0 - probing.Positions[0].Z; // vs Z above, add check for allowed delta?

if (probing.CoordinateMode == ProbingViewModel.CoordMode.G10)
probing.Grbl.ExecuteCommand(string.Format("G10L2P{0}Z{1}", probing.CoordinateSystem, (probing.Positions[0].Z - probing.Grbl.ToolOffset.Z).ToInvariantString()));
else if ((ok = probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
{
probing.Grbl.ExecuteCommand("G92Z0");
if (!probing.Grbl.IsParserStateLive)
probing.Grbl.ExecuteCommand("$G");
}
}

probing.GotoMachinePosition(origin, AxisFlags.Z);
probing.GotoMachinePosition(origin, AxisFlags.X | AxisFlags.Y);

if (ok)
probing.Program.End(string.Format((string)FindResource("ProbingCompleted"), z_min.ToInvariantString(probing.Grbl.Format), z_max.ToInvariantString(probing.Grbl.Format)));
}

Expand Down Expand Up @@ -300,10 +307,12 @@ private void limits_Click(object sender, RoutedEventArgs e)
{
var probing = DataContext as ProbingViewModel;

probing.HeightMap.MinX = probing.Grbl.ProgramLimits.MinX;
probing.HeightMap.MinY = probing.Grbl.ProgramLimits.MinY;
probing.HeightMap.MaxX = probing.Grbl.ProgramLimits.MaxX;
probing.HeightMap.MaxY = probing.Grbl.ProgramLimits.MaxY;
ProgramLimits programLimits = new ProgramLimits(probing.Grbl.ProgramLimits, probing.Grbl.UnitFactor);

probing.HeightMap.MinX = programLimits.MinX;
probing.HeightMap.MinY = programLimits.MinY;
probing.HeightMap.MaxX = programLimits.MaxX;
probing.HeightMap.MaxY = programLimits.MaxY;
//probing.HeightMap.GridSizeLockXY = true;
//probing.HeightMap.GridSizeX = probing.HeightMap.GridSizeY = 5d;
}
Expand Down
Loading

0 comments on commit ad7a4f6

Please sign in to comment.