diff --git a/CNC Controls Dragknife/DragknifeViewModel.cs b/CNC Controls Dragknife/DragknifeViewModel.cs index fffe548..a8f9cb6 100644 --- a/CNC Controls Dragknife/DragknifeViewModel.cs +++ b/CNC Controls Dragknife/DragknifeViewModel.cs @@ -1,13 +1,13 @@ /* * DragKnifeViewModel.cs - part of CNC Controls DragKnife library for Grbl * - * v0.40 / 2022-07-12 / Io Engineering (Terje Io) + * v0.45 / 2024-10-11 / Io Engineering (Terje Io) * */ /* -Copyright (c) 2020-2021, Io Engineering (Terje Io) +Copyright (c) 2020-2024, Io Engineering (Terje Io) All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -159,8 +159,8 @@ private void Transform (List polyLine, List newToolPath) if (i == 0) { end = prev.P1 + n1 * _knifeTipOffset; - newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end), AxisFlags.XY)); - newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z)); + newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end), AxisFlags.XY, false)); + newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z, false)); } if (Math.Abs(angle) > (i == 0 ? 1d : _swivelAngle) && cp2.Magnitude >= _dentLength) @@ -171,19 +171,19 @@ private void Transform (List polyLine, List 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, 0, 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, false)); } if (cp2.Magnitude > _knifeTipOffset) end = polyLine[i].P2 + n2 * _knifeTipOffset; else end += cp2; - newToolPath.Add(new GCLinearMotion((i & 1) == 1 ? Commands.G1 : Commands.G1, lnr++, ToPos(end), AxisFlags.XY)); + newToolPath.Add(new GCLinearMotion((i & 1) == 1 ? Commands.G1 : Commands.G1, lnr++, ToPos(end), AxisFlags.XY, false)); prev = polyLine[i]; if (i == polyLine.Count - 1) { - newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z)); + newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z, false)); } } } @@ -219,26 +219,26 @@ private void Transformx(List polyLine, List newToolPath) if (i == 0) { // start = StartDirection * _knifeTipOffset; - newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(start), AxisFlags.XY)); - newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(start + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z)); + newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(start), AxisFlags.XY, false)); + newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(start + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z, false)); } // else - newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end), AxisFlags.XY)); + newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end), AxisFlags.XY, false)); if (Math.Abs(ad) > _swivelAngle && cp2.Magnitude >= _dentLength) { 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, 0, 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, false)); } } if (i == polyLine.Count - 1) { - newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(polyLine[i].P2 + offset2), AxisFlags.XY)); - newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(polyLine[i].P2 + offset2 + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z)); + newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(polyLine[i].P2 + offset2), AxisFlags.XY, false)); + newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(polyLine[i].P2 + offset2 + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z, false)); // StartDirection = dir; } // newToolPath.Add(new GCLinearMotion(Commands.G1, (uint)i, new double[] { polyLine[i].P2.X, polyLine[i].P2.Y, polyLine[i].P2.Z }, AxisFlags.XY)); diff --git a/CNC Controls Dragknife/Properties/AssemblyInfo.cs b/CNC Controls Dragknife/Properties/AssemblyInfo.cs index 6d75f2a..aec7030 100644 --- a/CNC Controls Dragknife/Properties/AssemblyInfo.cs +++ b/CNC Controls Dragknife/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Io Engineering")] [assembly: AssemblyProduct("ioSender")] -[assembly: AssemblyCopyright("Copyright © 2021 Io Engineering")] +[assembly: AssemblyCopyright("Copyright © 2024 Io Engineering")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] @@ -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.35.0")] -[assembly: AssemblyFileVersion("2.0.35.0")] +[assembly: AssemblyVersion("2.0.45.0")] +[assembly: AssemblyFileVersion("2.0.45.0")] diff --git a/CNC Controls Lathe/CNC Controls Lathe/TaperControl.xaml.cs b/CNC Controls Lathe/CNC Controls Lathe/TaperControl.xaml.cs index 13e2364..3d0facf 100644 --- a/CNC Controls Lathe/CNC Controls Lathe/TaperControl.xaml.cs +++ b/CNC Controls Lathe/CNC Controls Lathe/TaperControl.xaml.cs @@ -1,17 +1,45 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +/* + * TaperControl.xaml.cs - part of CNC Controls library + * + * v0.45 / 2024-04-21 / Io Engineering (Terje Io) + * + */ + +/* + +Copyright (c) 2019-2024, Io Engineering (Terje Io) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +· Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +· Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +· Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +using System; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace CNC.Controls.Lathe { @@ -20,10 +48,31 @@ namespace CNC.Controls.Lathe /// public partial class TaperControl : UserControl { + public Action OnValueChanged; + public Action OnTaperEnabledChanged; + public TaperControl() { InitializeComponent(); + + data.TextChanged += Data_TextChanged; + chkTaper.Checked += ChkTaper_Checked; + chkTaper.Unchecked += ChkTaper_Checked; + } + + private void ChkTaper_Checked(object sender, RoutedEventArgs e) + { + OnTaperEnabledChanged?.Invoke(chkTaper.IsChecked == true); + } + + private void Data_TextChanged(object sender, TextChangedEventArgs e) + { + OnValueChanged?.Invoke(double.IsNaN(Value) ? 0d : Value); } + + // public string Format { get { return data.Format; } } + + public static readonly DependencyProperty IsTaperEnabledProperty = DependencyProperty.Register(nameof(IsTaperEnabled), typeof(bool), typeof(TaperControl), new PropertyMetadata(/*"Label:" , new PropertyChangedCallback(OnLabelChanged)*/)); public bool IsTaperEnabled { @@ -31,6 +80,18 @@ public bool IsTaperEnabled set { SetValue(IsTaperEnabledProperty, value); } } + public static readonly DependencyProperty FormatProperty = DependencyProperty.Register(nameof(Format), typeof(string), typeof(TaperControl), new PropertyMetadata("##0", new PropertyChangedCallback(OnFormatChanged))); + public string Format + { + get { return (string)GetValue(FormatProperty); } + set { SetValue(FormatProperty, value); } + } + + private static void OnFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaperControl)d).data.Format = (string)e.NewValue; + } + public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(TaperControl), new PropertyMetadata(/*"Label:" , new PropertyChangedCallback(OnLabelChanged)*/)); public double Value { diff --git a/CNC Controls Lathe/CNC Controls Lathe/TurningLogic.cs b/CNC Controls Lathe/CNC Controls Lathe/TurningLogic.cs index 68eaea1..5870d78 100644 --- a/CNC Controls Lathe/CNC Controls Lathe/TurningLogic.cs +++ b/CNC Controls Lathe/CNC Controls Lathe/TurningLogic.cs @@ -1,13 +1,13 @@ /* * TurningLogic.cs - part of CNC Controls Lathe library * - * v0.43 / 2023-06-03 / Io Engineering (Terje Io) + * v0.45 / 2024-04-21 / Io Engineering (Terje Io) * */ /* -Copyright (c) 2019-2023, Io Engineering (Terje Io) +Copyright (c) 2019-2024, Io Engineering (Terje Io) All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -133,8 +133,15 @@ public void Calculate() PassCalc cut = new PassCalc(xdistance, passdepth, passdepth_last, model.Precision); if (model.IsTaperEnabled) + { + if (model.Taper >= 90d) + { + model.SetError(nameof(model.Taper), "Error: taper cannot be >= 90 deg."); + return; + } angle = Math.Tan(Math.PI * model.Taper / 180.0d); - + model.ZLength = (xtarget - diameter) / angle * model.config.ZDirection; + } // error.Clear(); if (cut.Passes < 1) @@ -170,15 +177,19 @@ public void Calculate() // TODO: G0 to prev target to keep spindle speed constant? // if (css) // code[i++] = string.Format("G0 X{0}", model.FormatValue(doc_prev)); - model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget), model.FormatValue(feedrate))); if (angle != 0.0d) { ztarget = cut.Distance / angle * model.config.ZDirection; + model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget -= model.config.ZClearance / model.UnitFactor * angle), model.FormatValue(feedrate))); model.gCode.Add(string.Format("G1 X{0} Z{1}", model.FormatValue(diameter), model.FormatValue(zstart + ztarget))); + model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(diameter + xclearance))); } else + { + model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget), model.FormatValue(feedrate))); model.gCode.Add(string.Format("G1 Z{0} F{1}", model.FormatValue(ztarget), model.FormatValue(feedrate))); - model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(xtarget + xclearance))); + model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(xtarget + xclearance))); + } model.gCode.Add(string.Format("G0 Z{0}", model.FormatValue(zstart + model.config.ZClearance / model.UnitFactor))); } while (++pass <= cut.Passes); @@ -190,6 +201,8 @@ public void Calculate() GCode.File.AddBlock(string.Format("(Passdepth: {0}, Feedrate: {1}, {2}: {3})", model.FormatValue(passdepth), model.FormatValue(model.FeedRate), (model.IsCssEnabled ? "CSS" : "RPM"), model.FormatValue((double)model.CssSpeed)), Core.Action.Add); + if (angle != 0.0d) + GCode.File.AddBlock(string.Format("(Taper length: {0})", model.FormatValue(model.ZLength))); foreach (string s in model.gCode) GCode.File.AddBlock(s, Core.Action.Add); diff --git a/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml b/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml index 707bcb6..98e2cdc 100644 --- a/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml +++ b/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml @@ -6,8 +6,9 @@ xmlns:local="clr-namespace:CNC.Controls.Lathe" xmlns:Controls="clr-namespace:CNC.Controls;assembly=CNC.Controls.WPF" x:Class="CNC.Controls.Lathe.TurningWizard" xmlns:Converters="clr-namespace:CNC.Controls.Lathe" - mc:Ignorable="d" - d:DesignHeight="515" d:DesignWidth="875"> + mc:Ignorable="d" + d:DesignHeight="515" d:DesignWidth="875" + Loaded="TurningWizard_Load"> @@ -55,7 +56,7 @@ - + diff --git a/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml.cs b/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml.cs index dfe61ff..a6e0c93 100644 --- a/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml.cs +++ b/CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml.cs @@ -1,13 +1,13 @@ /* * TurningWizard.xaml.cs - part of CNC Controls library * - * v0.31 / 2021-04-27 / Io Engineering (Terje Io) + * v0.45 / 2024-04-21 / Io Engineering (Terje Io) * */ /* -Copyright (c) 2019-2021, Io Engineering (Terje Io) +Copyright (c) 2019-2024, Io Engineering (Terje Io) All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -41,6 +41,7 @@ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR using System.Collections.ObjectModel; using System.Windows.Controls; using CNC.Core; +using CNC.GCode; namespace CNC.Controls.Lathe { @@ -50,7 +51,7 @@ namespace CNC.Controls.Lathe public partial class TurningWizard : UserControl, ICNCView { private bool initOk = false, resetProfileBindings = true; - private double last_rpm = 0d, last_css = 0d; + private double last_rpm = 0d, last_css = 0d, length = 0d; private BaseViewModel model; private TurningLogic logic = new TurningLogic(); @@ -74,6 +75,8 @@ void TurningWizard_Load(object sender, EventArgs e) //UIUtils.GroupBoxCaptionBold(groupBox1); //UIUtils.GroupBoxCaptionBold(groupBox2); + taper.OnValueChanged += taperChanged; + taper.OnTaperEnabledChanged += taperEnabled; } public ObservableCollection gCode { get; private set; } @@ -120,10 +123,39 @@ public void Setup(UIViewModel model, AppConfig profile) #endregion public void InitUI() { + } public WizardConfig config { get; private set; } + private void taperEnabled (bool enabled) + { + if (enabled) + length = cvLength.Value; + else + cvLength.Value = length; + + cvLength.IsEnabled = !enabled; + } + + private void taperChanged (double angle) + { + if(taper.IsTaperEnabled && angle != 0d && Math.Abs(model.XStart - model.XTarget) != 0.0d) + { + double xtarget = model.XTarget; + double diameter = model.XStart; + + if (model.config.xmode == LatheMode.Radius) + { + xtarget /= 2.0d; + diameter /= 2.0d; + } + + //bool boring = (xtarget - diameter) > 0.0d; ?? + cvLength.Value = (xtarget - diameter) / Math.Tan(Math.PI * angle / 180.0d) * model.config.ZDirection; + } + } + private void btnCalculate_Click(object sender, System.Windows.RoutedEventArgs e) { logic.Calculate(); diff --git a/CNC Controls Probing/CNC Controls Probing/CNC Controls Probing.csproj b/CNC Controls Probing/CNC Controls Probing/CNC Controls Probing.csproj index 244f037..2ae0c34 100644 --- a/CNC Controls Probing/CNC Controls Probing/CNC Controls Probing.csproj +++ b/CNC Controls Probing/CNC Controls Probing/CNC Controls Probing.csproj @@ -48,6 +48,8 @@ + + @@ -81,10 +83,14 @@ + + MacroDialog.xaml + ProbeVerify.xaml + ProbingView.xaml @@ -137,6 +143,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -198,6 +208,12 @@ + + + + + +