diff --git a/MatterControl.Printing/GCode/GCodeFile.cs b/MatterControl.Printing/GCode/GCodeFile.cs index c109bf957..72799e6b1 100644 --- a/MatterControl.Printing/GCode/GCodeFile.cs +++ b/MatterControl.Printing/GCode/GCodeFile.cs @@ -214,63 +214,6 @@ namespace MatterControl.Printing return stringWithNumber; } - // Vector4 maxAccelerationMmPerS2 = new Vector4(1000, 1000, 100, 5000); - // Vector4 maxVelocityMmPerS = new Vector4(500, 500, 5, 25); - // Vector4 velocitySameAsStopMmPerS = new Vector4(8, 8, .4, 5); - - protected static double GetSecondsThisLine(Vector3 deltaPositionThisLine, - double deltaEPositionThisLine, - double feedRateMmPerMin, - Vector4 maxAccelerationMmPerS2, - Vector4 maxVelocityMmPerS, - Vector4 velocitySameAsStopMmPerS, - Vector4 speedMultiplierV4) - { - double lengthOfThisMoveMm = Math.Max(deltaPositionThisLine.Length, deltaEPositionThisLine); - - if (lengthOfThisMoveMm == 0) - { - return 0; - } - - double maxVelocityMmPerSx = Math.Min(feedRateMmPerMin / 60, maxVelocityMmPerS.X); - double startingVelocityMmPerS = Math.Min(velocitySameAsStopMmPerS.X, maxVelocityMmPerSx); - double endingVelocityMmPerS = startingVelocityMmPerS; - double acceleration = maxAccelerationMmPerS2.X; - double speedMultiplier = speedMultiplierV4.X; - - double distanceToMaxVelocity = GetDistanceToReachEndingVelocity(startingVelocityMmPerS, maxVelocityMmPerSx, acceleration); - if (distanceToMaxVelocity <= lengthOfThisMoveMm / 2) - { - // we will reach max velocity then run at it and then decelerate - double accelerationTime = GetTimeToAccelerateDistance(startingVelocityMmPerS, distanceToMaxVelocity, acceleration) * 2; - double runningTime = (lengthOfThisMoveMm - (distanceToMaxVelocity * 2)) / maxVelocityMmPerSx; - return (accelerationTime + runningTime) * speedMultiplier; - } - else - { - // we will accelerate to the center then decelerate - double accelerationTime = GetTimeToAccelerateDistance(startingVelocityMmPerS, lengthOfThisMoveMm / 2, acceleration) * 2; - return (accelerationTime) * speedMultiplier; - } - } - - private static double GetDistanceToReachEndingVelocity(double startingVelocityMmPerS, double endingVelocityMmPerS, double accelerationMmPerS2) - { - double endingVelocityMmPerS2 = endingVelocityMmPerS * endingVelocityMmPerS; - double startingVelocityMmPerS2 = startingVelocityMmPerS * startingVelocityMmPerS; - return (endingVelocityMmPerS2 - startingVelocityMmPerS2) / (2.0 * accelerationMmPerS2); - } - - private static double GetTimeToAccelerateDistance(double startingVelocityMmPerS, double distanceMm, double accelerationMmPerS2) - { - // d = vi * t + .5 * a * t^2; - // t = (√(vi^2+2ad)-vi)/a - double startingVelocityMmPerS2 = startingVelocityMmPerS * startingVelocityMmPerS; - double distanceAcceleration2 = 2 * accelerationMmPerS2 * distanceMm; - return (Math.Sqrt(startingVelocityMmPerS2 + distanceAcceleration2) - startingVelocityMmPerS) / accelerationMmPerS2; - } - private static readonly bool Is32Bit = IntPtr.Size == 4; #endregion Static Functions } diff --git a/MatterControl.Printing/GCode/GCodeMemoryFile.cs b/MatterControl.Printing/GCode/GCodeMemoryFile.cs index e3d100f43..8c9137a63 100644 --- a/MatterControl.Printing/GCode/GCodeMemoryFile.cs +++ b/MatterControl.Printing/GCode/GCodeMemoryFile.cs @@ -402,8 +402,21 @@ namespace MatterControl.Printing if (feedRateMmPerMin > 0) { - instruction.secondsThisLine = (float)GetSecondsThisLine(deltaPositionThisLine, deltaEPositionThisLine, feedRateMmPerMin, - maxAccelerationMmPerS2, maxVelocityMmPerS, velocitySameAsStopMmPerS, speedMultiplier); + var timeForE = Estimator.GetSecondsForMovement(deltaEPositionThisLine, + feedRateMmPerMin / 60.0, + maxAccelerationMmPerS2[3], + maxVelocityMmPerS[3], + velocitySameAsStopMmPerS[3], + speedMultiplier[3]); + + var timeForPosition = Estimator.GetSecondsForMovement(deltaPositionThisLine, + feedRateMmPerMin / 60.0, + new Vector3(maxAccelerationMmPerS2), + new Vector3(maxVelocityMmPerS), + new Vector3(velocitySameAsStopMmPerS), + new Vector3(speedMultiplier)); + + instruction.secondsThisLine = (float)Math.Max(timeForE, timeForPosition); } if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 721ec70bd..f1caf952a 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 721ec70bd37432a0f1aade5109b4eb2cea34a6bd +Subproject commit f1caf952a8023b38784d454fad3cc9741bb4b1e0