Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
79d04775
Commit
79d04775
authored
May 15, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move code around and remove useless helpers from pronsole.py
parent
d0a0ffbd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
95 deletions
+84
-95
gcoder.py
gcoder.py
+79
-1
pronsole.py
pronsole.py
+0
-88
pronterface.py
pronterface.py
+5
-6
No files found.
gcoder.py
View file @
79d04775
...
...
@@ -18,6 +18,15 @@ import sys
import
re
import
math
def
get_coordinate_value
(
axis
,
parts
):
for
i
in
parts
:
if
(
axis
in
i
):
return
float
(
i
[
1
:])
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
))
class
Line
(
object
):
def
__init__
(
self
,
l
):
self
.
_x
=
None
...
...
@@ -316,6 +325,73 @@ class GCode(object):
return
total_e
def
estimate_duration
(
self
,
g
):
lastx
=
lasty
=
lastz
=
laste
=
lastf
=
0.0
x
=
y
=
z
=
e
=
f
=
0.0
currenttravel
=
0.0
totaltravel
=
0.0
moveduration
=
0.0
totalduration
=
0.0
acceleration
=
1500.0
#mm/s/s ASSUMING THE DEFAULT FROM SPRINTER !!!!
layerduration
=
0.0
layerbeginduration
=
0.0
layercount
=
0
#TODO:
# get device caps from firmware: max speed, acceleration/axis (including extruder)
# calculate the maximum move duration accounting for above ;)
# self.log(".... estimating ....")
for
i
in
g
:
i
=
i
.
split
(
";"
)[
0
]
if
"G4"
in
i
or
"G1"
in
i
:
if
"G4"
in
i
:
parts
=
i
.
split
(
" "
)
moveduration
=
get_coordinate_value
(
"P"
,
parts
[
1
:])
if
moveduration
is
None
:
continue
else
:
moveduration
/=
1000.0
if
"G1"
in
i
:
parts
=
i
.
split
(
" "
)
x
=
get_coordinate_value
(
"X"
,
parts
[
1
:])
if
x
is
None
:
x
=
lastx
y
=
get_coordinate_value
(
"Y"
,
parts
[
1
:])
if
y
is
None
:
y
=
lasty
z
=
get_coordinate_value
(
"Z"
,
parts
[
1
:])
if
(
z
is
None
)
or
(
z
<
lastz
):
z
=
lastz
# Do not increment z if it's below the previous (Lift z on move fix)
e
=
get_coordinate_value
(
"E"
,
parts
[
1
:])
if
e
is
None
:
e
=
laste
f
=
get_coordinate_value
(
"F"
,
parts
[
1
:])
if
f
is
None
:
f
=
lastf
else
:
f
/=
60.0
# mm/s vs mm/m
# given last feedrate and current feedrate calculate the distance needed to achieve current feedrate.
# if travel is longer than req'd distance, then subtract distance to achieve full speed, and add the time it took to get there.
# then calculate the time taken to complete the remaining distance
currenttravel
=
hypot3d
(
x
,
y
,
z
,
lastx
,
lasty
,
lastz
)
distance
=
abs
(
2
*
((
lastf
+
f
)
*
(
f
-
lastf
)
*
0.5
)
/
acceleration
)
#2x because we have to accelerate and decelerate
if
distance
<=
currenttravel
and
(
lastf
+
f
)
!=
0
and
f
!=
0
:
moveduration
=
2
*
distance
/
(
lastf
+
f
)
currenttravel
-=
distance
moveduration
+=
currenttravel
/
f
else
:
moveduration
=
math
.
sqrt
(
2
*
distance
/
acceleration
)
totalduration
+=
moveduration
if
z
>
lastz
:
layercount
+=
1
#self.log("layer z: ", lastz, " will take: ", time.strftime('%H:%M:%S', time.gmtime(totalduration-layerbeginduration)))
layerbeginduration
=
totalduration
lastx
=
x
lasty
=
y
lastz
=
z
laste
=
e
lastf
=
f
#self.log("Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration)))
return
"{0:d} layers, "
.
format
(
int
(
layercount
))
+
str
(
datetime
.
timedelta
(
seconds
=
int
(
totalduration
)))
def
main
():
if
len
(
sys
.
argv
)
<
2
:
...
...
@@ -324,7 +400,8 @@ def main():
# d = [i.replace("\n","") for i in open(sys.argv[1])]
# gcode = GCode(d)
gcode
=
GCode
(
list
(
open
(
sys
.
argv
[
1
])))
d
=
list
(
open
(
sys
.
argv
[
1
]))
gcode
=
GCode
(
d
)
gcode
.
measure
()
...
...
@@ -334,6 +411,7 @@ def main():
print
"
\t
Z:
%0.02
f -
%0.02
f (
%0.02
f)"
%
(
gcode
.
zmin
,
gcode
.
zmax
,
gcode
.
height
)
print
"Filament used:
%0.02
fmm"
%
gcode
.
filament_length
()
print
"Number of layers:
%
d"
%
gcode
.
num_layers
()
print
"Estimated duration (pessimistic): "
,
gcode
.
estimate_duration
(
d
)
if
__name__
==
'__main__'
:
...
...
pronsole.py
View file @
79d04775
...
...
@@ -20,7 +20,6 @@ import glob, os, time, datetime
import
sys
,
subprocess
import
math
,
codecs
from
math
import
sqrt
from
gcoder
import
GCode
import
printcore
from
printrun.printrun_utils
import
install_locale
...
...
@@ -44,93 +43,6 @@ except:
def
dosify
(
name
):
return
os
.
path
.
split
(
name
)[
1
]
.
split
(
"."
)[
0
][:
8
]
+
".g"
def
measurements
(
g
):
gcode
=
GCode
(
g
)
gcode
.
measure
()
return
(
gcode
.
width
,
gcode
.
depth
,
gcode
.
height
,
gcode
.
xmin
,
gcode
.
xmax
,
gcode
.
ymin
,
gcode
.
ymax
,
gcode
.
zmin
,
gcode
.
zmax
)
def
totalelength
(
g
):
gcode
=
GCode
(
g
)
return
gcode
.
filament_length
()
def
get_coordinate_value
(
axis
,
parts
):
for
i
in
parts
:
if
(
axis
in
i
):
return
float
(
i
[
1
:])
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
):
lastx
=
lasty
=
lastz
=
laste
=
lastf
=
0.0
x
=
y
=
z
=
e
=
f
=
0.0
currenttravel
=
0.0
totaltravel
=
0.0
moveduration
=
0.0
totalduration
=
0.0
acceleration
=
1500.0
#mm/s/s ASSUMING THE DEFAULT FROM SPRINTER !!!!
layerduration
=
0.0
layerbeginduration
=
0.0
layercount
=
0
#TODO:
# get device caps from firmware: max speed, acceleration/axis (including extruder)
# calculate the maximum move duration accounting for above ;)
# self.log(".... estimating ....")
for
i
in
g
:
i
=
i
.
split
(
";"
)[
0
]
if
"G4"
in
i
or
"G1"
in
i
:
if
"G4"
in
i
:
parts
=
i
.
split
(
" "
)
moveduration
=
get_coordinate_value
(
"P"
,
parts
[
1
:])
if
moveduration
is
None
:
continue
else
:
moveduration
/=
1000.0
if
"G1"
in
i
:
parts
=
i
.
split
(
" "
)
x
=
get_coordinate_value
(
"X"
,
parts
[
1
:])
if
x
is
None
:
x
=
lastx
y
=
get_coordinate_value
(
"Y"
,
parts
[
1
:])
if
y
is
None
:
y
=
lasty
z
=
get_coordinate_value
(
"Z"
,
parts
[
1
:])
if
(
z
is
None
)
or
(
z
<
lastz
):
z
=
lastz
# Do not increment z if it's below the previous (Lift z on move fix)
e
=
get_coordinate_value
(
"E"
,
parts
[
1
:])
if
e
is
None
:
e
=
laste
f
=
get_coordinate_value
(
"F"
,
parts
[
1
:])
if
f
is
None
:
f
=
lastf
else
:
f
/=
60.0
# mm/s vs mm/m
# given last feedrate and current feedrate calculate the distance needed to achieve current feedrate.
# if travel is longer than req'd distance, then subtract distance to achieve full speed, and add the time it took to get there.
# then calculate the time taken to complete the remaining distance
currenttravel
=
hypot3d
(
x
,
y
,
z
,
lastx
,
lasty
,
lastz
)
distance
=
abs
(
2
*
((
lastf
+
f
)
*
(
f
-
lastf
)
*
0.5
)
/
acceleration
)
#2x because we have to accelerate and decelerate
if
distance
<=
currenttravel
and
(
lastf
+
f
)
!=
0
and
f
!=
0
:
moveduration
=
2
*
distance
/
(
lastf
+
f
)
currenttravel
-=
distance
moveduration
+=
currenttravel
/
f
else
:
moveduration
=
math
.
sqrt
(
2
*
distance
/
acceleration
)
totalduration
+=
moveduration
if
z
>
lastz
:
layercount
+=
1
#self.log("layer z: ", lastz, " will take: ", time.strftime('%H:%M:%S', time.gmtime(totalduration-layerbeginduration)))
layerbeginduration
=
totalduration
lastx
=
x
lasty
=
y
lastz
=
z
laste
=
e
lastf
=
f
#self.log("Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration)))
return
"{0:d} layers, "
.
format
(
int
(
layercount
))
+
str
(
datetime
.
timedelta
(
seconds
=
int
(
totalduration
)))
def
confirm
():
y_or_n
=
raw_input
(
"y/n: "
)
if
y_or_n
==
"y"
:
...
...
pronterface.py
View file @
79d04775
...
...
@@ -1283,15 +1283,14 @@ class PronterWindow(MainWindow, pronsole.pronsole):
threading
.
Thread
(
target
=
self
.
loadviz
)
.
start
()
def
loadviz
(
self
):
Xtot
,
Ytot
,
Ztot
,
Xmin
,
Xmax
,
Ymin
,
Ymax
,
Zmin
,
Zmax
=
pronsole
.
measurements
(
self
.
f
)
print
pronsole
.
totalelength
(
self
.
f
),
_
(
"mm of filament used in this print
\n
"
)
gcode
=
pronsole
.
GCode
(
self
.
f
)
gcode
.
measure
()
Xtot
,
Ytot
,
Ztot
,
Xmin
,
Xmax
,
Ymin
,
Ymax
,
Zmin
,
Zmax
=
(
gcode
.
width
,
gcode
.
depth
,
gcode
.
height
,
gcode
.
xmin
,
gcode
.
xmax
,
gcode
.
ymin
,
gcode
.
ymax
,
gcode
.
zmin
,
gcode
.
zmax
)
print
gcode
.
filament_length
(),
_
(
"mm of filament used in this print
\n
"
)
print
_
(
"the print goes from
%
f mm to
%
f mm in X
\n
and is
%
f mm wide
\n
"
)
%
(
Xmin
,
Xmax
,
Xtot
)
print
_
(
"the print goes from
%
f mm to
%
f mm in Y
\n
and is
%
f mm wide
\n
"
)
%
(
Ymin
,
Ymax
,
Ytot
)
print
_
(
"the print goes from
%
f mm to
%
f mm in Z
\n
and is
%
f mm high
\n
"
)
%
(
Zmin
,
Zmax
,
Ztot
)
try
:
print
_
(
"Estimated duration (pessimistic): "
),
pronsole
.
estimate_duration
(
self
.
f
)
except
:
pass
print
_
(
"Estimated duration (pessimistic): "
),
gcode
.
estimate_duration
(
self
.
f
)
#import time
#t0 = time.time()
self
.
gviz
.
clear
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment