diff --git a/mbotmake b/mbotmake index 99cc924..9f5204b 100755 --- a/mbotmake +++ b/mbotmake @@ -5,6 +5,7 @@ import json import sys import tempfile import copy +import math def generateMetajson(temp, vardict): @@ -20,12 +21,14 @@ def generateMetajson(temp, vardict): ], "heat_platform": {3}, "extruder": "0" - }} + }}, + "duration_s": {4} }} """ meta = meta.format(vardict['tool0temp'], vardict['tool1temp'], vardict['bedtemp'], - 'true' if vardict['heatbed'] else 'false') + 'true' if vardict['heatbed'] else 'false', + int(math.ceil(vardict['time']))) with open('{}/meta.json'.format(temp), 'w') as metafile: metafile.write(meta) return @@ -77,7 +80,8 @@ def createToolpath(filename, temp): 'tool0temp': 0, 'tool1temp': 0, 'bedtemp': 0, - 'heatbed': False + 'heatbed': False, + 'time': 0.0 } print('lines processed:') print(printline.format(0, progresslen, 0/progresslen), end='') @@ -85,7 +89,7 @@ def createToolpath(filename, temp): Quick reference: G0/G1 is move M104 is set_toolhead_temperature - M140 sets bed temp + M140 sets bed temp M106 is fan_duty (sets fan) M107 is toggle_fan (off) G90 toggles absolute positioning @@ -108,6 +112,7 @@ def createToolpath(filename, temp): if len(line) == 2 and line[1][0] == 'F': axis['feedrate'] = float(line[1][1:]) / 60.0 else: # Normal move + prev = copy.copy(axis) # copy previous pos for timing for ax in line[1:]: if ax[0] == 'E': axis['a'] = float(ax[1:]) @@ -126,6 +131,11 @@ def createToolpath(filename, temp): 'z': False}, axis, []) + # get time traveled by the equasion + # time = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)/feedrate + distance = math.dist([axis['x'], axis['y'], axis['z']], + [prev['x'], prev['y'], prev['z']]) + printersettings['time'] += distance/axis['feedrate'] elif line[0] == 'M104': for ax in line[1:]: if ax[0] == 'T':