Commit f2434e75 authored by Christopher Keller's avatar Christopher Keller

Complete rewrite of time estimation with (default) acceleration!

  Accounts for G4 Pxxx
  Accounts for Z moves as well.
  Also prints out duration for each layer while calculating the total time.

  Does not use individual axis acceleration, only uses sprinter default acceleration 1500.0 mm/s/s
  Does not count E for timing... so if E is slowing down the move, we're not accounting for that.

** fixed: 2x distance to reach full speed, because accel and decel to 0.0 at each move.

TODO:
  Get Device Caps (per axis acceleration, per axis speed limits)
  anything else...?
parent bdb9eae0
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
import cmd, printcore, sys import cmd, printcore, sys
import glob, os, time import glob, os, time
import sys, subprocess import sys, subprocess
import math
from math import sqrt from math import sqrt
if os.name=="nt": if os.name=="nt":
try: try:
import _winreg import _winreg
...@@ -65,7 +67,6 @@ def measurements(g): ...@@ -65,7 +67,6 @@ def measurements(g):
Ytot = Ymax - Ymin Ytot = Ymax - Ymin
Ztot = Zmax - Zmin Ztot = Zmax - Zmin
return (Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax) return (Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
def totalelength(g): def totalelength(g):
...@@ -87,58 +88,76 @@ def get_coordinate_value(axis, parts): ...@@ -87,58 +88,76 @@ def get_coordinate_value(axis, parts):
return float(i[1:]) return float(i[1:])
return None return None
def hypot3d(X1, Y1, Z1, X2=0.0, Y2=0.0, Z2=0.0):
return math.hypot(X2-X1, math.hypot(Y2-Y1, Z2-Z1))
def estimate_duration(g): def estimate_duration(g):
extra_cost_per_movement = 0.02
total_duration = 0.0 lastx = lasty = lastz = laste = lastf = 0.0
feedrate = 0.0 x = y = z = e = f = 0.0
avg_feedrate = 0.0 currenttravel = 0.0
last_feedrate = 0.0 totaltravel = 0.0
X_last_position = 0.0 moveduration = 0.0
Y_last_position = 0.0 totalduration = 0.0
Z_last_position = 0.0 acceleration = 1500.0 #mm/s/s ASSUMING THE DEFAULT FROM SPRINTER !!!!
layerduration = 0.0
layerbeginduration = 0.0
#TODO:
# get device caps from firmware: max speed, acceleration/axis (including extruder)
# calculate the maximum move duration accounting for above ;)
print ".... estimating ...."
for i in g: for i in g:
i=i.split(";")[0] if "G4" in i or "G1" in i:
if "G1" in i and ("X" in i or "Y" in i or "F" in i or "E" in i): if "G4" in i:
#if "G1" in i and ("X" in i or "Y" in i or "Z" in i or "F" in i or "E" in i):
parts = i.split(" ") parts = i.split(" ")
X = get_coordinate_value("X", parts[1:]) moveduration = get_coordinate_value("P", parts[1:])
Y = get_coordinate_value("Y", parts[1:]) if moveduration is None:
#Z = get_coordinate_value("Z", parts[1:]) continue
F = get_coordinate_value("F", parts[1:]) else:
E = get_coordinate_value("E", parts[1:]) moveduration /= 1000.0
if "G1" in i:
if (F is not None): parts = i.split(" ")
feedrate = (last_feedrate + (F / 60.0))/2.0 x = get_coordinate_value("X", parts[1:])
distance = 0 if x is None: x=lastx
if (X is None and Y is None and E is not None): y = get_coordinate_value("Y", parts[1:])
distance = abs(E) if y is None: y=lasty
elif (X is not None and Y is None): z = get_coordinate_value("Z", parts[1:])
distance = X - X_last_position if z is None: z=lastz
X_last_position = X e = get_coordinate_value("E", parts[1:])
elif (X is None and Y is not None): if e is None: e=laste
distance = Y - Y_last_position f = get_coordinate_value("F", parts[1:])
Y_last_position = Y if f is None: f=lastf
elif (X is not None and Y is not None): else: f /= 60.0 # mm/s vs mm/m
X_distance = X - X_last_position
Y_distance = Y - Y_last_position # given last feedrate and current feedrate calculate the distance needed to achieve current feedrate.
distance = sqrt(X_distance * X_distance + Y_distance * Y_distance) # if travel is longer than req'd distance, then subtract distance to achieve full speed, and add the time it took to get there.
X_last_position = X # then calculate the time taken to complete the remaining distance
Y_last_position = Y
#if (Z is not None): currenttravel = hypot3d(x, y, z, lastx, lasty, lastz)
# Z_distance = Z - Z_last_position distance = 2* ((lastf+f) * (f-lastf) * 0.5 ) / acceleration #2x because we have to accelerate and decelerate
# if not(distance == 0.0): if distance <= currenttravel:
# distance = sqrt(Z_distance * Z_distance + distance * distance ) moveduration = 2 * distance / ( lastf + f )
# else: currenttravel -= distance
# distance = Z_distance moveduration += currenttravel/f
# Z_last_position = Z else:
moveduration = math.sqrt( 2 * distance / acceleration )
if (feedrate == 0.0 or distance == 0.0): continue
totalduration += moveduration
time_for_move = distance / feedrate
total_duration += time_for_move + extra_cost_per_movement if z > lastz:
if (F is not None): feedrate = F / 60.0 print "layer z: ", lastz, " will take: ", time.strftime('%H:%M:%S', time.gmtime(totalduration-layerbeginduration))
return time.strftime('%H:%M:%S', time.gmtime(total_duration/60.0)) layerbeginduration = totalduration
lastx = x
lasty = y
lastz = z
laste = e
lastf = f
print "Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration))
return time.strftime('%H:%M:%S', time.gmtime(totalduration))
class Settings: class Settings:
#def _temperature_alias(self): return {"pla":210,"abs":230,"off":0} #def _temperature_alias(self): return {"pla":210,"abs":230,"off":0}
#def _temperature_validate(self,v): #def _temperature_validate(self,v):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment