Wrote unit tests for 7 point print leveling math.
This commit is contained in:
parent
1753447e89
commit
4bf742b5c7
3 changed files with 66 additions and 3 deletions
|
|
@ -115,9 +115,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|||
}
|
||||
}
|
||||
|
||||
internal static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode)
|
||||
public static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode)
|
||||
{
|
||||
// old ref code
|
||||
if (PrinterConnectionAndCommunication.Instance.ActivePrinter != null
|
||||
&& PrinterConnectionAndCommunication.Instance.ActivePrinter.DoPrintLeveling
|
||||
&& (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 "))
|
||||
|
|
@ -139,6 +138,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|||
|
||||
if (movementMode == PrinterMachineInstruction.MovementTypes.Relative)
|
||||
{
|
||||
// TODO: this is not correct for 7 point leveling
|
||||
Vector3 relativeMove = Vector3.Zero;
|
||||
GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref relativeMove.x);
|
||||
GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref relativeMove.y);
|
||||
|
|
@ -167,7 +167,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|||
return lineBeingSent;
|
||||
}
|
||||
|
||||
private static Vector3 GetPositionWithZOffset(Vector3 currentDestination, PrintLevelingData levelingData)
|
||||
public static Vector3 GetPositionWithZOffset(Vector3 currentDestination, PrintLevelingData levelingData)
|
||||
{
|
||||
double angleToPoint = Math.Atan2(currentDestination.y, currentDestination.x);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
<Compile Include="MatterControl\SetupIniTests.cs" />
|
||||
<Compile Include="MatterControl\Slicing\SliceMappingCLassesTets.cs" />
|
||||
<Compile Include="MatterControl\Slicing\SliceLayersTests.cs" />
|
||||
<Compile Include="MatterControl\LevelingTests.cs" />
|
||||
<Compile Include="MatterControl\TranslationsTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
62
Tests/MatterControl.Tests/MatterControl/LevelingTests.cs
Normal file
62
Tests/MatterControl.Tests/MatterControl/LevelingTests.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using MatterHackers.MatterControl;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterControl.Tests.MatterControl
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class LevelingTests
|
||||
{
|
||||
[Test, Category("Leveling")]
|
||||
public void Leveling7PointsCorectInterpolation()
|
||||
{
|
||||
PrintLevelingData levelingData = new PrintLevelingData();
|
||||
|
||||
double radius = 100;
|
||||
levelingData.SampledPositions = new List<Vector3>();
|
||||
Vector2 currentEdgePoint = new Vector2(radius, 0);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
|
||||
currentEdgePoint.Rotate(MathHelper.Tau / 6);
|
||||
}
|
||||
|
||||
levelingData.SampledPositions.Add(new Vector3(0, 0, 6));
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
// test actual sample position
|
||||
Vector2 currentTestPoint = new Vector2(radius, 0);
|
||||
currentTestPoint.Rotate(MathHelper.Tau / 6 * i);
|
||||
Vector3 outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
|
||||
Assert.AreEqual(outPosition.z, levelingData.SampledPositions[i].z, .001);
|
||||
|
||||
// test 1/2 angles (mid way between samples
|
||||
int nextPoint = i < 5 ? i + 1 : 0;
|
||||
currentTestPoint = new Vector2(radius, 0);
|
||||
currentTestPoint.Rotate(MathHelper.Tau / 6 * (i + .5));
|
||||
outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
|
||||
Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[i].z + levelingData.SampledPositions[nextPoint].z)/2, .001);
|
||||
|
||||
// test 1/2 to center
|
||||
currentTestPoint = new Vector2(radius / 2, 0);
|
||||
currentTestPoint.Rotate(MathHelper.Tau / 6 * i));
|
||||
outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
|
||||
Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[i].z + levelingData.SampledPositions[6].z) / 2, .001);
|
||||
}
|
||||
|
||||
Vector3 outPosition2 = LevelWizard7PointRadial.GetPositionWithZOffset(Vector3.Zero, levelingData);
|
||||
Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue