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
23e7c661
Commit
23e7c661
authored
Jun 03, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify nesting in gcode duration estimation code
parent
07cf32d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
63 deletions
+62
-63
gcoder.py
printrun/gcoder.py
+62
-63
No files found.
printrun/gcoder.py
View file @
23e7c661
...
@@ -492,73 +492,72 @@ class GCode(object):
...
@@ -492,73 +492,72 @@ class GCode(object):
ymax
=
max
(
ymax
,
line
.
current_y
)
ymax
=
max
(
ymax
,
line
.
current_y
)
# Compute duration
# Compute duration
if
line
.
command
in
[
"G1"
,
"G0"
,
"G4"
]:
if
line
.
command
==
"G0"
or
line
.
command
==
"G1"
:
if
line
.
command
==
"G4"
:
x
=
line
.
x
if
line
.
x
is
not
None
else
lastx
moveduration
=
P
(
line
)
y
=
line
.
y
if
line
.
y
is
not
None
else
lasty
if
moveduration
:
z
=
line
.
z
if
line
.
z
is
not
None
else
lastz
moveduration
/=
1000.0
e
=
line
.
e
if
line
.
e
is
not
None
else
laste
totalduration
+=
moveduration
# mm/s vs mm/m => divide by 60
f
=
line
.
f
/
60.0
if
line
.
f
is
not
None
else
lastf
# 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
# FIXME: this code has been proven to be super wrong when 2
# subsquent moves are in opposite directions, as requested
# speed is constant but printer has to fully decellerate
# and reaccelerate
# The following code tries to fix it by forcing a full
# reacceleration if this move is in the opposite direction
# of the previous one
dx
=
x
-
lastx
dy
=
y
-
lasty
if
dx
*
lastdx
+
dy
*
lastdy
<=
0
:
lastf
=
0
currenttravel
=
math
.
hypot
(
dx
,
dy
)
if
currenttravel
==
0
:
if
line
.
z
is
not
None
:
currenttravel
=
abs
(
line
.
z
)
if
line
.
relative
else
abs
(
line
.
z
-
lastz
)
elif
line
.
e
is
not
None
:
currenttravel
=
abs
(
line
.
e
)
if
line
.
relative_e
else
abs
(
line
.
e
-
laste
)
# Feedrate hasn't changed, no acceleration/decceleration planned
if
f
==
lastf
:
moveduration
=
currenttravel
/
f
if
f
!=
0
else
0.
else
:
else
:
x
=
line
.
x
if
line
.
x
is
not
None
else
lastx
# FIXME: review this better
y
=
line
.
y
if
line
.
y
is
not
None
else
lasty
# this looks wrong : there's little chance that the feedrate we'll decelerate to is the previous feedrate
z
=
line
.
z
if
line
.
z
is
not
None
else
lastz
# shouldn't we instead look at three consecutive moves ?
e
=
line
.
e
if
line
.
e
is
not
None
else
laste
distance
=
2
*
abs
(((
lastf
+
f
)
*
(
f
-
lastf
)
*
0.5
)
/
acceleration
)
# multiply by 2 because we have to accelerate and decelerate
# mm/s vs mm/m => divide by 60
if
distance
<=
currenttravel
and
lastf
+
f
!=
0
and
f
!=
0
:
f
=
line
.
f
/
60.0
if
line
.
f
is
not
None
else
lastf
moveduration
=
2
*
distance
/
(
lastf
+
f
)
# This is distance / mean(lastf, f)
moveduration
+=
(
currenttravel
-
distance
)
/
f
# 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
# FIXME: this code has been proven to be super wrong when 2
# subsquent moves are in opposite directions, as requested
# speed is constant but printer has to fully decellerate
# and reaccelerate
# The following code tries to fix it by forcing a full
# reacceleration if this move is in the opposite direction
# of the previous one
dx
=
x
-
lastx
dy
=
y
-
lasty
if
dx
*
lastdx
+
dy
*
lastdy
<=
0
:
lastf
=
0
currenttravel
=
math
.
hypot
(
dx
,
dy
)
if
currenttravel
==
0
:
if
line
.
z
is
not
None
:
currenttravel
=
abs
(
line
.
z
)
if
line
.
relative
else
abs
(
line
.
z
-
lastz
)
elif
line
.
e
is
not
None
:
currenttravel
=
abs
(
line
.
e
)
if
line
.
relative_e
else
abs
(
line
.
e
-
laste
)
# Feedrate hasn't changed, no acceleration/decceleration planned
if
f
==
lastf
:
moveduration
=
currenttravel
/
f
if
f
!=
0
else
0.
else
:
else
:
# FIXME: review this better
moveduration
=
2
*
currenttravel
/
(
lastf
+
f
)
# This is currenttravel / mean(lastf, f)
# this looks wrong : there's little chance that the feedrate we'll decelerate to is the previous feedrate
# FIXME: probably a little bit optimistic, but probably a much better estimate than the previous one:
# shouldn't we instead look at three consecutive moves ?
# moveduration = math.sqrt(2 * distance / acceleration) # probably buggy : not taking actual travel into account
distance
=
2
*
abs
(((
lastf
+
f
)
*
(
f
-
lastf
)
*
0.5
)
/
acceleration
)
# multiply by 2 because we have to accelerate and decelerate
if
distance
<=
currenttravel
and
lastf
+
f
!=
0
and
f
!=
0
:
lastdx
=
dx
moveduration
=
2
*
distance
/
(
lastf
+
f
)
# This is distance / mean(lastf, f)
lastdy
=
dy
moveduration
+=
(
currenttravel
-
distance
)
/
f
else
:
totalduration
+=
moveduration
moveduration
=
2
*
currenttravel
/
(
lastf
+
f
)
# This is currenttravel / mean(lastf, f)
# FIXME: probably a little bit optimistic, but probably a much better estimate than the previous one:
lastx
=
x
# moveduration = math.sqrt(2 * distance / acceleration) # probably buggy : not taking actual travel into account
lasty
=
y
lastz
=
z
lastdx
=
dx
laste
=
e
lastdy
=
dy
lastf
=
f
elif
line
.
command
==
"G4"
:
moveduration
=
P
(
line
)
if
moveduration
:
moveduration
/=
1000.0
totalduration
+=
moveduration
totalduration
+=
moveduration
lastx
=
x
lasty
=
y
lastz
=
z
laste
=
e
lastf
=
f
# FIXME : looks like this needs to be tested with "lift Z on move"
# FIXME : looks like this needs to be tested with "lift Z on move"
if
line
.
z
is
not
None
:
if
line
.
z
is
not
None
:
if
line
.
command
==
"G92"
:
if
line
.
command
==
"G92"
:
...
...
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