Skip to content

Commit be639d5

Browse files
committed
LTT: improve and simplify time calculation
1 parent 4333150 commit be639d5

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/main/java/de/thomas_oster/liblasercut/drivers/LaserToolsTechnicsCutter.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,30 @@ private double speedPercentToMmPerSec(double speedPercent) {
627627
* @return time in seconds
628628
*/
629629
private double cuttingTimeForPxDistance(double distancePx, double resolution, double speedPercent) {
630-
return Util.px2mm(distancePx, resolution) / speedPercentToMmPerSec(speedPercent);
630+
double speedMmPerSec = speedPercentToMmPerSec(speedPercent);
631+
double distanceMm = Util.px2mm(distancePx, resolution);
632+
// for the value of the acceleration, we assume the same as configured for "joint tangential curve".
633+
if (!isUseTangentCurves())
634+
{
635+
// acceleration is not configured, fall back to simple computation without acceleration
636+
return distanceMm / speedMmPerSec;
637+
}
638+
// v = a t, x = 1/2 a t² => t = v² / a², x = 1/2 v² / a
639+
// distance x for accelerating to full speed:
640+
double accelDistanceMm = 0.5 * Math.sqrt(speedMmPerSec * speedMmPerSec / tangentCurveMaxAcceleration);
641+
if (distanceMm > 2 * accelDistanceMm)
642+
{
643+
// Accelerating to full speed.
644+
// during acceleration, the effective speed is half the speed.
645+
return (distanceMm + 2 * accelDistanceMm) / speedMmPerSec;
646+
}
647+
else
648+
{
649+
// path is too short for full acceleration.
650+
// x = 1/2 v² / a => v_max = sqrt(2 a x), where x is half the length
651+
double peakSpeed = Math.sqrt(tangentCurveMaxAcceleration * distanceMm);
652+
return 2 * distanceMm / peakSpeed;
653+
}
631654
}
632655
/**
633656
* cutting time for cutting a line at the current speed
@@ -1844,8 +1867,10 @@ private double engraveBitmapLine(PrintStream out, ByteArrayList bytes, Point lin
18441867
out.write(b);
18451868
}
18461869
// TODO: this time estimate doesn't include the travel time to the start point
1847-
final double engraveSpeedFactor = 2; // FIXME: this is a rough estimate. Calibrate the engrave speed and take acceleration into account.
1848-
return cuttingTimeForPxDistance(bytes.size() * pixelsPerByte, resolution, currentSpeed * engraveSpeedFactor);
1870+
// TODO make the following parameters configurable
1871+
final double engraveSpeedVersusCutSpeed = 6.4; // Factor between full engrave speed and full cut speed.
1872+
final double engraveExtraSecondsPerLine = 0.1; // extra time per engrave line
1873+
return engraveExtraSecondsPerLine + cuttingTimeForPxDistance(bytes.size() * pixelsPerByte, resolution, currentSpeed * engraveSpeedVersusCutSpeed);
18491874
}
18501875

18511876

0 commit comments

Comments
 (0)