Skip to content

Commit

Permalink
Bug fixes an enhancments. See changelog.md for details.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Jul 18, 2022
1 parent 5ebc00e commit 29f206a
Show file tree
Hide file tree
Showing 29 changed files with 625 additions and 429 deletions.
6 changes: 3 additions & 3 deletions CNC Controls Dragknife/DragknifeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DragKnifeViewModel.cs - part of CNC Controls DragKnife library for Grbl
*
* v0.33 / 2021-05-14 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

Expand Down Expand Up @@ -171,7 +171,7 @@ private void Transform (List<segment> polyLine, List<GCodeToken> newToolPath)
StartDirection = dir;
end = end1;
var arcdir = n1.X * n2.Y - n1.Y * n2.X;
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(end), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(end), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental));
}
if (cp2.Magnitude > _knifeTipOffset)
end = polyLine[i].P2 + n2 * _knifeTipOffset;
Expand Down Expand Up @@ -231,7 +231,7 @@ private void Transformx(List<segment> polyLine, List<GCodeToken> newToolPath)
var arcdir = n1.X * n2.Y - n1.Y * n2.X;
// newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
//newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ 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 GCArc(arc.Command, lnr++, target.Array, arc.AxisFlags | AxisFlags.Z, ijk, arc.IjkFlags, arc.R, arc.IJKMode));
newToolPath.Add(new GCArc(arc.Command, lnr++, target.Array, arc.AxisFlags | AxisFlags.Z, ijk, arc.IjkFlags, arc.R, arc.P, arc.IJKMode));
}
}
break;
Expand Down
24 changes: 21 additions & 3 deletions CNC Controls/CNC Controls/ArcsToLines.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* ArcsToLines.cs - part of CNC Controls library for Grbl
*
* v0.36 / 2021-11-01 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2021, Io Engineering (Terje Io)
Copyright (c) 2020-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -85,7 +85,25 @@ public void Apply()

case Commands.G5:
{
var spline = cmd.Token as GCSpline;
var spline = cmd.Token as GCCubicSpline;
lnroffset++;
lnr = spline.LineNumber;
toolPath.Add(new GCComment(Commands.Comment, spline.LineNumber + lnroffset, "Spline to lines start: " + spline.ToString()));

List<Point3D> points = spline.GeneratePoints(ToPos(cmd.Start, emu.IsImperial), arcTolerance, emu.DistanceMode == DistanceMode.Incremental); // Dynamic resolution
foreach (Point3D point in points)
{
lnroffset++;
toolPath.Add(new GCLinearMotion(Commands.G1, spline.LineNumber + lnroffset, ToPos(point, emu.IsImperial), AxisFlags.XYZ));
}
lnroffset++;
toolPath.Add(new GCComment(Commands.Comment, lnr, "Spline to lines end"));
}
break;

case Commands.G5_1:
{
var spline = cmd.Token as GCQuadraticSpline;
lnroffset++;
lnr = spline.LineNumber;
toolPath.Add(new GCComment(Commands.Comment, spline.LineNumber + lnroffset, "Spline to lines start: " + spline.ToString()));
Expand Down
20 changes: 15 additions & 5 deletions CNC Controls/CNC Controls/GCodeRotate.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* GCodeRotate.cs - part of CNC Controls library for Grbl
*
* v0.36 / 2021-11-01 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2021, Io Engineering (Terje Io)
Copyright (c) 2021-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -140,18 +140,28 @@ public void ApplyRotation(double angle, Vector3 offset, bool compress = false)

pos = target;

toolPath.Add(new GCArc(arc.Command, arc.LineNumber, pos.Array, arc.AxisFlags, targetijk.Array, arc.IjkFlags, arc.R, arc.IJKMode));
toolPath.Add(new GCArc(arc.Command, arc.LineNumber, pos.Array, arc.AxisFlags, targetijk.Array, arc.IjkFlags, arc.R, arc.P, arc.IJKMode));
}
break;

case Commands.G5:
{
var spline = token as GCSpline;
var spline = token as GCCubicSpline;
pos = new Vector3(spline.X, spline.Y, 0d).RotateZ(offset.X, offset.Y, angle).Round(precision);
var ij = new Vector3(spline.I, spline.J, 0d).RotateZ(offset.X, offset.Y, angle).Round(precision);
var pq = new Vector3(spline.P, spline.Q, 0d).RotateZ(offset.X, offset.Y, angle).Round(precision);

toolPath.Add(new GCSpline(spline.Command, spline.LineNumber, pos.Array, spline.AxisFlags, new double[] { ij.X, ij.Y, pq.X, pq.Y }));
toolPath.Add(new GCCubicSpline(spline.Command, spline.LineNumber, pos.Array, spline.AxisFlags, new double[] { ij.X, ij.Y, pq.X, pq.Y }));
}
break;

case Commands.G5_1:
{
var spline = token as GCQuadraticSpline;
pos = new Vector3(spline.X, spline.Y, 0d).RotateZ(offset.X, offset.Y, angle).Round(precision);
var ij = new Vector3(spline.I, spline.J, 0d).RotateZ(offset.X, offset.Y, angle).Round(precision);

toolPath.Add(new GCQuadraticSpline(spline.Command, spline.LineNumber, pos.Array, spline.AxisFlags, new double[] { ij.X, ij.Y }));
}
break;

Expand Down
4 changes: 2 additions & 2 deletions CNC Controls/CNC Controls/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
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.40.0")]
[assembly: AssemblyFileVersion("2.0.40.0")]
19 changes: 13 additions & 6 deletions CNC Controls/CNC Controls/SpindleControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* SpindleControl.xaml.cs - part of CNC Controls library
*
* v0.21 / 2020-08-03 / Io Engineering (Terje Io)
* v0.40 / 2022-07-16 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2018-2020, Io Engineering (Terje Io)
Copyright (c) 2018-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -41,13 +41,12 @@ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
using System.Windows;
using System.Windows.Controls;
using CNC.Core;
using System.Windows.Input;

namespace CNC.Controls
{
public partial class SpindleControl : UserControl
{
private bool hold = false;

public SpindleControl()
{
InitializeComponent();
Expand All @@ -64,6 +63,7 @@ public SpindleControl()
overrideControl.CoarseMinusCommand = GrblConstants.CMD_SPINDLE_OVR_COARSE_MINUS;
overrideControl.CoarsePlusCommand = GrblConstants.CMD_SPINDLE_OVR_COARSE_PLUS;

cvRPM.PreviewKeyUp += txtPos_KeyPress;
overrideControl.CommandGenerated += overrideControl_CommandGenerated;
}

Expand All @@ -81,8 +81,7 @@ private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArg
{
case nameof(GrblViewModel.GrblState):
case nameof(GrblViewModel.IsJobRunning):
var p = (GrblViewModel)sender;
hold = p.IsJobRunning && (p.GrblState.State == GrblStates.Hold || p.GrblState.State == GrblStates.Door);
var p = sender as GrblViewModel;
IsSpindleStateEnabled = !p.IsJobRunning || p.GrblState.State == GrblStates.Hold || p.GrblState.State == GrblStates.Door;
break;
}
Expand All @@ -102,6 +101,14 @@ public bool IsSpindleStateEnabled
public new bool IsFocused { get { return cvRPM.IsFocused; } }
public bool SPOr { get { return !(DataContext as GrblViewModel).IsJobRunning || (DataContext as GrblViewModel).GrblState.State == GrblStates.Hold; } }

private void txtPos_KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && !(DataContext as GrblViewModel).IsJobRunning)
{
(DataContext as GrblViewModel).ExecuteCommand(string.Format("S{0}", (sender as NumericTextBox).Value));
}
}

private void rbSpindle_Click(object sender, RoutedEventArgs e)
{
var p = DataContext as GrblViewModel;
Expand Down
6 changes: 4 additions & 2 deletions CNC Core/CNC Core/GCode.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* GCode.cs - part of CNC Controls library
*
* v0.36 / 2021-12-27 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2018-2020, Io Engineering (Terje Io)
Copyright (c) 2018-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -119,6 +119,7 @@ public enum MotionMode
G2 = 20,
G3 = 30,
G5 = 50,
G5_1 = 51,
G5_2 = 52,
G33 = 330,
G38_2 = 382,
Expand Down Expand Up @@ -217,6 +218,7 @@ public enum Commands
G3,
G4,
G5,
G5_1,
G7,
G8,
G10,
Expand Down
12 changes: 10 additions & 2 deletions CNC Core/CNC Core/GCodeEmulator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GCodeEmulator.cs - part of CNC Controls library
*
* v0.33 / 2021-05-16 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

Expand Down Expand Up @@ -110,7 +110,15 @@ public IEnumerable<RunAction> Execute(List<GCodeToken> Tokens)
// G5: Cubic Spline
case Commands.G5:
{
var spline = token as GCSpline;
var spline = token as GCCubicSpline;
setEndP(spline.Values, spline.AxisFlags);
}
break;

// G5: Quadratic Spline
case Commands.G5_1:
{
var spline = token as GCQuadraticSpline;
setEndP(spline.Values, spline.AxisFlags);
}
break;
Expand Down
10 changes: 6 additions & 4 deletions CNC Core/CNC Core/GCodeJob.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GCodeJob.cs - part of CNC Controls library
*
* v0.36 / 2022-01-20 / Io Engineering (Terje Io)
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
*
*/

Expand Down Expand Up @@ -202,9 +202,11 @@ public void AddBlock(string block, Action action)
{
if(cmd.Token is GCArc)
BoundingBox.AddBoundingBox((cmd.Token as GCArc).GetBoundingBox(emu.Plane, new double[]{ cmd.Start.X, cmd.Start.Y, cmd.Start.Z }, emu.DistanceMode == DistanceMode.Incremental));
else if (cmd.Token is GCSpline)
BoundingBox.AddBoundingBox((cmd.Token as GCSpline).GetBoundingBox(emu.Plane, new double[] { cmd.Start.X, cmd.Start.Y, cmd.Start.Z }, emu.DistanceMode == DistanceMode.Incremental));
else if(cmd.Token is GCAxisCommand6)
else if (cmd.Token is GCCubicSpline)
BoundingBox.AddBoundingBox((cmd.Token as GCCubicSpline).GetBoundingBox(emu.Plane, new double[] { cmd.Start.X, cmd.Start.Y, cmd.Start.Z }, emu.DistanceMode == DistanceMode.Incremental));
else if (cmd.Token is GCQuadraticSpline)
BoundingBox.AddBoundingBox((cmd.Token as GCQuadraticSpline).GetBoundingBox(emu.Plane, new double[] { cmd.Start.X, cmd.Start.Y, cmd.Start.Z }, emu.DistanceMode == DistanceMode.Incremental));
else if (cmd.Token is GCAxisCommand6)
BoundingBox.AddPoint(cmd.End, (cmd.Token as GCAxisCommand6).AxisFlags);
}

Expand Down
Loading

0 comments on commit 29f206a

Please sign in to comment.