Skip to content

Commit

Permalink
Treat G4 dwells as delays
Browse files Browse the repository at this point in the history
Currently 'dwells' are both G4(time delay dwell) and "unbounded dwells"
like G28, temperature waits, etc. Really G4 should be considered part of
the known print time, and thus part of the sequences instead of as
sequence separators.

This is a breaking change compared to the 1.x series, where G4
operations would split `estimate` sequences.
  • Loading branch information
dalegaard committed Mar 30, 2022
1 parent 7a8b0cb commit e9cfd7e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ impl Planner {
/// open move sequence.
/// Returns the number of planning operations the command resulted in
pub fn process_cmd(&mut self, cmd: &GCodeCommand) -> usize {
if let Some(t) = Self::is_dwell(cmd) {
self.operations
.add_dwell(t, Some(self.kind_tracker.get_kind("Dwell")));
if let Some(m) = Self::is_dwell(cmd, &mut self.kind_tracker) {
self.operations.moves.push_back(m);
} else if let GCodeOperation::Move { x, y, z, e, f } = &cmd.op {
if let Some(v) = f {
self.toolhead_state.set_speed(v / 60.0);
Expand Down Expand Up @@ -174,29 +173,42 @@ impl Planner {
self.operations.flush();
}

fn is_dwell(cmd: &GCodeCommand) -> Option<f64> {
fn is_dwell(cmd: &GCodeCommand, kind_tracker: &mut KindTracker) -> Option<PlanningOperation> {
match &cmd.op {
GCodeOperation::Traditional {
letter: 'G',
code: 4,
params,
} => Some(params.get_number('P').map_or(0.25, |v: f64| v / 1000.0)),
} => Some(PlanningOperation::Delay(
params.get_number('P').map_or(0.25, |v: f64| v / 1000.0),
)),
GCodeOperation::Traditional {
letter: 'G',
code: 28,
..
} => Some(0.1),
} => Some(PlanningOperation::Dwell(
0.1,
Some(kind_tracker.get_kind("Indeterminate time")),
)),
GCodeOperation::Traditional {
letter: 'M',
code: 109 | 190,
..
} => Some(0.1),
GCodeOperation::Extended { command: cmd, .. } if cmd == "temperature_wait" => Some(0.1),
} => Some(PlanningOperation::Dwell(
0.1,
Some(kind_tracker.get_kind("Indeterminate time")),
)),
GCodeOperation::Extended { command: cmd, .. } if cmd == "temperature_wait" => Some(
PlanningOperation::Dwell(0.1, Some(kind_tracker.get_kind("Indeterminate time"))),
),
GCodeOperation::Traditional {
letter: 'M',
code: 600,
..
} => Some(0.0),
} => Some(PlanningOperation::Dwell(
0.1,
Some(kind_tracker.get_kind("Indeterminate time")),
)),
_ => None,
}
}
Expand Down Expand Up @@ -230,6 +242,7 @@ impl Planner {
#[derive(Debug)]
pub enum PlanningOperation {
Dwell(f64, Option<Kind>),
Delay(f64),
Move(PlanningMove),
Fill,
}
Expand Down
10 changes: 10 additions & 0 deletions tool/src/cmd/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ impl EstimationState {
fn add(&mut self, planner: &Planner, op: &PlanningOperation) {
match op {
PlanningOperation::Move(m) => self.add_move(planner, m),
PlanningOperation::Delay(t) => {
let seq = self.get_cur_seq();
seq.total_time += t;
let kind = "Dwell";
if let Some(kt) = seq.kind_times.get_mut(kind) {
*kt += t;
} else {
seq.kind_times.insert(kind.to_string(), *t);
}
}
PlanningOperation::Dwell(t, k) => {
// If current sequence has moves or there is no sequence, make a new one
if self
Expand Down
1 change: 1 addition & 0 deletions tool/src/cmd/post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl EstimateRunner {
let (n, cmd) = self.buffer.front_mut().unwrap();
match c {
PlanningOperation::Dwell(t, _) => self.state.result.total_time += t,
PlanningOperation::Delay(t) => self.state.result.total_time += t,
PlanningOperation::Move(m) => self.state.result.total_time += m.total_time(),
PlanningOperation::Fill => {}
}
Expand Down

0 comments on commit e9cfd7e

Please sign in to comment.